1 #ifndef RH_SOCKET_H
 2 #define RH_SOCKET_H
 3 
 4 #include <netinet/in.h>
 5 #include <sys/types.h>
 6 #include "rh_event.h"
 7 
 8 struct rh_socket {
 9         int                     fd;
10         struct sockaddr_in      addr;
11         rh_event_t              event_write;
12         rh_event_t              event_read;
13 };
14 
15 typedef struct rh_socket rh_socket_t;
16 
17 
18 #define RH_SOCKET_NONBLOCK      1
19 #define RH_SOCKET_REUSEADDR     2
20 #define RH_SOCKET_CORK_ON       3
21 #define RH_SOCKET_CORK_OFF      4
22 
23 void rh_socket_init (rh_socket_t *s);
24 
25 int rh_socket_create (rh_socket_t *s, int domain, int type, int protocol);
26 
27 int rh_socket_close  (rh_socket_t *s);
28 
29 int rh_socket_listen (rh_socket_t *s, int backlog);
30 
31 int rh_socket_bind   (rh_socket_t *s);
32 
33 int rh_socket_accept (rh_socket_t *server, rh_socket_t *client);
34 
35 int rh_socket_set    (rh_socket_t *s, int what);
36 
37 int rh_socket_set_addr (rh_socket_t *s, unsigned short port);
38 
39 
40 ssize_t rh_socket_write (rh_socket_t *s, const void *src, size_t nsrc);
41 ssize_t rh_socket_read  (rh_socket_t *s, void *dst, size_t ndst);
42 
43 
44 #endif /* RH_SOCKET_H */


syntax highlighted by Code2HTML, v. 0.9.1