P_tcp4_listen 3porty 2011-04-14 libporty manual

NAME

P_tcp4_listen, P_tcp4_accept

SYNPOSIS

#include <libporty/net/tcp4.h>

int P_tcp4_listen (P_net_socket * sock , const char * loc_hostname , int loc_port , P_net_nonblock_t non_blocking , int backlog );
int P_tcp4_accept (P_net_socket * new_socket , P_net_socket listen_sock , unsigned long int * rem_ip , char ** rem_host , int * rem_port , P_net_nonblock_t non_blocking )

Link with -lporty_net

DESCRIPTION

P_tcp4_listen creates a TCP/IPv4 listening socket (socket is returned in sock ). The socket is bound to loc_hostname : loc_port locally. For listening on any interface loc_hostname should be "0.0.0.0". If loc_hostname is not an ip address, a blocking DNS lookup will be issued.

If non_blocking has bit P_net_nonblock_socket set for the listen call, the listening socket will be non-blocking for read. backlog specifies how many pending connections are remembered by the system, as documented in listen(2). For the accept call, non_blocking with bit P_net_nonblock_socket set will set the newly accepted socket non-blocking.

Caller should poll for reading (P_POLLIN) on listening sockets and call P_tcp4_accept when the socket becomes readable with the same listen_sock . The newly accepted socket is returned in new_socket . Optionally, if caller may be interested in where the connection is coming from, any of the non-NULL rem_ip , rem_host , rem_port are filled in. Note: rem_host triggers blocking DNS lookups.

RETURN VALUE

Returns 0 on success or an error code from P_net_err n failure.

P_tcp4_listen 3porty 2011-04-14 libporty manual