src/sock_tcp.h
changeset 10 9fe218576d13
parent 3 cc94ae754e2a
child 11 14e79683c48c
equal deleted inserted replaced
9:4c4c906cc649 10:9fe218576d13
    13     /* The base struct for sock_stream_* functions */
    13     /* The base struct for sock_stream_* functions */
    14     struct sock_stream base;
    14     struct sock_stream base;
    15     
    15     
    16     /* The OS file descriptor */
    16     /* The OS file descriptor */
    17     int fd;
    17     int fd;
       
    18 
       
    19     /* The libevent struct */
       
    20     struct event *ev;
    18 };
    21 };
    19 
    22 
    20 #define SOCK_TCP_BASE(sock_ptr) (&(sock_ptr)->base)
    23 #define SOCK_TCP_BASE(sock_ptr) (&(sock_ptr)->base)
    21 #define SOCK_TCP_ERR(sock_ptr) SOCK_ERR(SOCK_TCP_BASE(sock_ptr))
    24 #define SOCK_TCP_ERR(sock_ptr) SOCK_ERR(SOCK_TCP_BASE(sock_ptr))
    22 
    25 
    29  * Initialize a blank sock_tcp with a given already-existing fd
    32  * Initialize a blank sock_tcp with a given already-existing fd
    30  */
    33  */
    31 err_t sock_tcp_init_fd (struct sock_tcp *sock, int fd);
    34 err_t sock_tcp_init_fd (struct sock_tcp *sock, int fd);
    32 
    35 
    33 /*
    36 /*
       
    37  * Initialize sock_tcp.ev to use the socket's fd with the given callback. By default, this is created with EV_READ
       
    38  * flags, but is not added.
       
    39  */
       
    40 err_t sock_tcp_init_ev (struct sock_tcp *sock, void (*ev_cb) (evutil_socket_t, short, void *), void *arg);
       
    41 
       
    42 /*
    34  * Initialize a blank sock_tcp by connecting
    43  * Initialize a blank sock_tcp by connecting
    35  */
    44  */
    36 err_t sock_tcp_init_connect (struct sock_tcp *sock, const char *hostname, const char *service);
    45 err_t sock_tcp_init_connect (struct sock_tcp *sock, const char *hostname, const char *service);
       
    46 
       
    47 /*
       
    48  * Set the socket's nonblock mode
       
    49  */
       
    50 err_t sock_tcp_set_nonblock (struct sock_tcp *sock, int nonblock);
    37 
    51 
    38 /*
    52 /*
    39  * Release a non-connected sock_tcp
    53  * Release a non-connected sock_tcp
    40  */
    54  */
    41 void sock_tcp_release (struct sock_tcp *sock);
    55 void sock_tcp_release (struct sock_tcp *sock);