1 /*
2  * Copyright 2001-2004 Brandon Long
3  * All Rights Reserved.
4  *
5  * ClearSilver Templating System
6  *
7  * This code is made available under the terms of the ClearSilver License.
8  * http://www.clearsilver.net/license.hdf
9  *
10  */
11 
12 #ifndef __NEO_NET_H_
13 #define __NEO_NET_H_ 1
14 
15 __BEGIN_DECLS
16 
17 #define NET_BUFSIZE 4096
18 
19 typedef struct _neo_sock {
20   int fd;
21   int data_timeout;
22   int conn_timeout;
23 
24   UINT32 remote_ip;
25   int remote_port;
26 
27   /* incoming buffer */
28   UINT8 ibuf[NET_BUFSIZE];
29   int ib;
30   int il;
31 
32   /* outbound buffer */
33   UINT8 obuf[NET_BUFSIZE];
34   int ol;
35 } NSOCK;
36 
37 NEOERR *ne_net_listen(int port, int *fd);
38 NEOERR *ne_net_accept(NSOCK **sock, int fd, int data_timeout);
39 NEOERR *ne_net_connect(NSOCK **sock, const char *host, int port,
40                        int conn_timeout, int data_timeout);
41 NEOERR *ne_net_close(NSOCK **sock);
42 NEOERR *ne_net_read(NSOCK *sock, UINT8 *buf, int buflen);
43 NEOERR *ne_net_read_line(NSOCK *sock, char **buf);
44 NEOERR *ne_net_read_binary(NSOCK *sock, UINT8 **b, int *blen);
45 NEOERR *ne_net_read_str_alloc(NSOCK *sock, char **s, int *len);
46 NEOERR *ne_net_read_int(NSOCK *sock, int *i);
47 NEOERR *ne_net_write(NSOCK *sock, const char *b, int blen);
48 NEOERR *ne_net_write_line(NSOCK *sock, const char *s);
49 NEOERR *ne_net_write_binary(NSOCK *sock, const char *b, int blen);
50 NEOERR *ne_net_write_str(NSOCK *sock, const char *s);
51 NEOERR *ne_net_write_int(NSOCK *sock, int i);
52 NEOERR *ne_net_flush(NSOCK *sock);
53 void ne_net_shutdown(void);
54 
55 __END_DECLS
56 
57 #endif /* __NEO_NET_H_ */
58