blob: 7e281d02ffe803fc31a8243f147bcf6a10f0ef4d
1 | /*********************************************************************** |
2 | * |
3 | * event-tcp.h |
4 | * |
5 | * Event-driven TCP functions to allow for single-threaded "concurrent" |
6 | * server. |
7 | * |
8 | * Copyright (C) 2001 Roaring Penguin Software Inc. |
9 | * |
10 | * $Id$ |
11 | * |
12 | * This program may be distributed according to the terms of the GNU |
13 | * General Public License, version 2 or (at your option) any later version. |
14 | * |
15 | * LIC: GPL |
16 | * |
17 | ***********************************************************************/ |
18 | |
19 | #ifndef INCLUDE_EVENT_TCP_H |
20 | #define INCLUDE_EVENT_TCP_H 1 |
21 | |
22 | #include "event.h" |
23 | #include <sys/socket.h> |
24 | |
25 | typedef void (*EventTcpAcceptFunc)(EventSelector *es, |
26 | int fd); |
27 | |
28 | typedef void (*EventTcpConnectFunc)(EventSelector *es, |
29 | int fd, |
30 | int flag, |
31 | void *data); |
32 | |
33 | typedef void (*EventTcpIOFinishedFunc)(EventSelector *es, |
34 | int fd, |
35 | char *buf, |
36 | int len, |
37 | int flag, |
38 | void *data); |
39 | |
40 | #define EVENT_TCP_FLAG_COMPLETE 0 |
41 | #define EVENT_TCP_FLAG_IOERROR 1 |
42 | #define EVENT_TCP_FLAG_EOF 2 |
43 | #define EVENT_TCP_FLAG_TIMEOUT 3 |
44 | |
45 | typedef struct EventTcpState_t { |
46 | int socket; |
47 | char *buf; |
48 | char *cur; |
49 | int len; |
50 | int delim; |
51 | EventTcpIOFinishedFunc f; |
52 | EventSelector *es; |
53 | EventHandler *eh; |
54 | void *data; |
55 | } EventTcpState; |
56 | |
57 | extern EventHandler *EventTcp_CreateAcceptor(EventSelector *es, |
58 | int socket, |
59 | EventTcpAcceptFunc f); |
60 | |
61 | extern void EventTcp_Connect(EventSelector *es, |
62 | int fd, |
63 | struct sockaddr const *addr, |
64 | socklen_t addrlen, |
65 | EventTcpConnectFunc f, |
66 | int timeout, |
67 | void *data); |
68 | |
69 | extern EventTcpState *EventTcp_ReadBuf(EventSelector *es, |
70 | int socket, |
71 | int len, |
72 | int delim, |
73 | EventTcpIOFinishedFunc f, |
74 | int timeout, |
75 | void *data); |
76 | |
77 | extern EventTcpState *EventTcp_WriteBuf(EventSelector *es, |
78 | int socket, |
79 | char *buf, |
80 | int len, |
81 | EventTcpIOFinishedFunc f, |
82 | int timeout, |
83 | void *data); |
84 | |
85 | extern void EventTcp_CancelPending(EventTcpState *s); |
86 | |
87 | #endif |
88 |