terom@1: #ifndef SOCK_TCP_H terom@1: #define SOCK_TCP_H terom@1: terom@1: /* terom@1: * TCP implementation of sock_stream interface. terom@1: */ terom@1: #include "sock_internal.h" terom@1: terom@1: /* terom@1: * Contains the base sock_stream struct, and the file descriptor terom@1: */ terom@1: struct sock_tcp { terom@1: /* The base struct for sock_stream_* functions */ terom@1: struct sock_stream base; terom@1: terom@1: /* The OS file descriptor */ terom@1: int fd; terom@10: terom@11: /* The IO events */ terom@11: struct event *ev_read, *ev_write; terom@1: }; terom@1: terom@1: #define SOCK_TCP_BASE(sock_ptr) (&(sock_ptr)->base) terom@3: #define SOCK_TCP_ERR(sock_ptr) SOCK_ERR(SOCK_TCP_BASE(sock_ptr)) terom@1: terom@1: /* terom@2: * Allocate a new blank sock_tcp with a correctly initialized base terom@1: */ terom@3: err_t sock_tcp_alloc (struct sock_tcp **sock_ptr); terom@2: terom@2: /* terom@2: * Initialize a blank sock_tcp with a given already-existing fd terom@2: */ terom@3: err_t sock_tcp_init_fd (struct sock_tcp *sock, int fd); terom@2: terom@2: /* terom@11: * Initialize sock_tcp.ev_* to use the socket's fd with the given callback. The ev's are not activated yet. terom@10: */ terom@10: err_t sock_tcp_init_ev (struct sock_tcp *sock, void (*ev_cb) (evutil_socket_t, short, void *), void *arg); terom@10: terom@10: /* terom@2: * Initialize a blank sock_tcp by connecting terom@2: */ terom@3: err_t sock_tcp_init_connect (struct sock_tcp *sock, const char *hostname, const char *service); terom@3: terom@3: /* terom@10: * Set the socket's nonblock mode terom@10: */ terom@10: err_t sock_tcp_set_nonblock (struct sock_tcp *sock, int nonblock); terom@10: terom@10: /* terom@12: * event_add the specified ev_* events. terom@12: */ terom@12: err_t sock_tcp_add_event (struct sock_tcp *sock, short mask); terom@12: terom@12: /* terom@3: * Release a non-connected sock_tcp terom@3: */ terom@3: void sock_tcp_release (struct sock_tcp *sock); terom@1: terom@1: #endif /* SOCK_TCP_H */