X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fttt-socket.h;h=c3ca0bdd604263e65e49af91f1a106ad36b79b03;hp=59e89a514b6fd1d2d92af21cfe1e9f4dba2e2eb6;hb=f2187ebd49f78b84bd2dca6172abc81e54dda199;hpb=152ea9285ef3804783540d46263a7fc9802bc7db diff --git a/src/ttt-socket.h b/src/ttt-socket.h index 59e89a5..c3ca0bd 100644 --- a/src/ttt-socket.h +++ b/src/ttt-socket.h @@ -24,7 +24,8 @@ #include "ttt.h" -typedef void (*ttt_socket_dispatch_func_t) (int connected_socket); +typedef void (*ttt_socket_accept_func_t) (void *closure, + int connected_socket); /* Create a socket, bind it to the given host and port, and listen in * preparation for incoming connections. See ttt_socket_accept for a @@ -45,10 +46,51 @@ ttt_socket_create_server (const char *host, const char *port); /* Wait for an incoming connection on listen_socket, (which should be * a valid socket on which bind and listen have already been - * called---see ttt_socket_create_server), then call the dispatch - * function with the new socket from the connection. + * called---see ttt_socket_create_server), then call the accept + * function with the closure argument and the new socket from the + * connection. */ void -ttt_socket_accept (int listen_socket, ttt_socket_dispatch_func_t dispatch); +ttt_socket_accept (int listen_socket, + ttt_socket_accept_func_t accept, + void *closure); + +/* Create a socket, and connect it to the given host and port, + * returing it in socket_ret. + * + * Lookup for host (e.g. /etc/hosts and DNS) and port (e.g /etc/services) + * will be performed if necessary. + * + * Return value: TTT_STATUS_SUCCESS if successful. + * TTT_STATUS_CONNECTION_REFUSED: no server listening. + * TTT_STATUS_NETWORK_UNREACHABLE: + * + * Errors: If any error other than those listed above occurs, this + * function will not return. + */ +ttt_status_t +ttt_socket_create_client (const char *host, + const char *port, + int *socket_ret); + +/* Perform a blocking read, until all count bytes are read from the + * socket to buf, which must be of size count or larger. + * + * Errors: If any errors occur, this function does not return. + */ +void +ttt_socket_read (int socket, + void *buf, + size_t count); + +/* Perform a blocking write, until all count bytes are written from + * buf to the socket. + * + * Errors: If any errors occur, this function does not return. + */ +void +ttt_socket_write (int socket, + const void *buf, + size_t count); #endif