|
sock_t | ds_accept_socket (sock_t fd) |
| Accepts a connection from a listen socket. More...
|
|
sock_t | ds_client_socket (const char *serv, unsigned short port) |
| Creates a client socket with which to connect to a host. More...
|
|
sock_t | ds_client_socket_nonblocking (const char *serv, unsigned short port) |
| Creates a client socket with which to connect to a host. More...
|
|
int | ds_getaddr (const char *name, struct in_addr *addr) |
| Gets a network address. More...
|
|
struct sockaddr * | ds_gethostsockaddr (const char *name, struct sockaddr *serv_addr) |
| Return the socket address for a given hostname. More...
|
|
int | ds_inet_aton (const char *cp, struct in_addr *inp) |
| Converts an IP address in string format into binary data. More...
|
|
char * | ds_interface_address (const char *ifname) |
| Get the local IP address for the specified interface name. More...
|
|
sock_t | ds_listen_socket (struct in_addr *addr, int port, int backlog) |
| Creates a listen socket on the specified local address and TCP port. More...
|
|
sock_t | ds_listen_socket_log (struct in_addr *addr, int port, int backlog, ds_log_t *log, const char *context) |
| Wrapper for ds_listen_socket that creates a listen socket and logs that creation. More...
|
|
sock_t | ds_multicast_listen_socket (const char *iface, const char *addr, int port) |
| Creates a multicast listen socket. More...
|
|
int | ds_pipe (sock_t fds[2]) |
| Creates a UNIX-style pipe. More...
|
|
void | ds_setnonblocking (sock_t fd) |
| Set a socket to be non-blocking. More...
|
|
int | ds_udp_bind_client_socket (sock_t sock, const char *addr, int port) |
| Binds a UDP socket to a local address. More...
|
|
sock_t | ds_udp_client_socket (const char *addr, int port, struct sockaddr_in *serv_addr) |
| Creates a UDP client socket. More...
|
|
sock_t | ds_udp_listen_socket (const char *iface, int port) |
| Creates a UDP listen socket. More...
|
|
int | ds_udp_send (const char *data, int len, const char *addr, int port) |
| Sends data to a UDP address. More...
|
|
int | ds_udp_sendto (const char *data, int len, struct sockaddr_in *serv_addr) |
| Sends data to a UDP address. More...
|
|
DataSource SDK provides a simplified network programming API, including wrappers to standard system calls and library functions.
Using these wrappers will ensure that the network code in your DataSource application will work across all supported platforms.
sock_t ds_client_socket_nonblocking |
( |
const char * |
serv, |
|
|
unsigned short |
port |
|
) |
| |
Creates a client socket with which to connect to a host.
- Parameters
-
serv | The IP address or hostname of the server |
port | The port to connect to |
- Returns
- The created socket; or INVALID_SOCKET.
Example: connecting to port 25 of localhost.
3 if ( (sock = ds_client_socket_nonblocking("localhost",25) ) != INVALID_SOCKET ) {
Following this read andwrite events should be registered as necessary to catch the result of the non-blocking connect.
Hint:
- If the descriptor comes back as writable ONLY then the connection has successful.
- If the descriptor comes back both writeable and readable then:
- The connection has been established and data has been rcvd from the remote end before select was called / returned.
- An error occurred and the connection could not be properly established.
When #2 occurs, I typically just call connect(...) again and if I get a -1 and errno == EISCONN I know I can continue on while any other errno should mean a failure.
Another often heard suggestion is to do a read against the socket with a requested length of 0 - you should get a 0 on return and a -1 if there is a problem. While certainly valid, some people find this a bit counter intuitive to use since a return of 0 on a read normally means EOF / shutdown of the connection by the remote side.
sock_t ds_listen_socket |
( |
struct in_addr * |
addr, |
|
|
int |
port, |
|
|
int |
backlog |
|
) |
| |
Creates a listen socket on the specified local address and TCP port.
- Parameters
-
addr | The local address to bind to |
port | The port to bind to. |
backlog | Queue size of pending connections. |
- Returns
- The created sock_t on success, or INVALID_SOCKET on failure
If the address is NULL then all local interfaces will be bound to.
Example: Listening on TCP port 1025 with a backlog of 5 pending connections.
3 if ( (sock = ds_listen_socket(NULL,1025,5)) != INVALID_SOCKET ) {
or, using a network interface returned from ds_getaddr()
1 if ( (sock = ds_listen_socket(&addr,1025,5)) != INVALID_SOCKET ) {