|
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...
|
|
struct sockaddr_storage * | ds_gethostsockaddr (const char *name, struct sockaddr_storage *serv_addr) |
| Return the socket address for a given hostname. More...
|
|
char * | ds_getnameinfo (const struct sockaddr_storage *addr, char *buf, size_t buflen) |
| return the string representation of the address passed in More...
|
|
sock_t | ds_listen_socket (const char *addr, int port, int backlog) |
| Creates a listen socket on the specified local address and TCP port. More...
|
|
sock_t | ds_listen_socket_log (const char *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_storage *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_storage *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 and write 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 |
( |
const char * |
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 ) {