-
Notifications
You must be signed in to change notification settings - Fork 9
/
event_tcp.h
114 lines (97 loc) · 2.6 KB
/
event_tcp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/***********************************************************************
*
* event-tcp.h
*
* Event-driven TCP functions to allow for single-threaded "concurrent"
* server.
*
* Copyright (C) 2001-2003 Roaring Penguin Software Inc.
*
* This program may be distributed according to the terms of the GNU
* General Public License, version 2 or (at your option) any later version.
*
***********************************************************************/
#ifndef INCLUDE_EVENT_TCP_H
#define INCLUDE_EVENT_TCP_H 1
#include "event.h"
#include <sys/socket.h>
#ifndef HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
typedef void (*EventTcpAcceptFunc)(EventSelector *es,
int fd);
typedef void (*EventTcpConnectFunc)(EventSelector *es,
int fd,
int flag,
void *data);
typedef void (*EventTcpIOFinishedFunc)(EventSelector *es,
int fd,
char *buf,
int len,
int flag,
void *data);
#define EVENT_TCP_FLAG_INIT -1
#define EVENT_TCP_FLAG_COMPLETE 0
#define EVENT_TCP_FLAG_IOERROR 1
#define EVENT_TCP_FLAG_EOF 2
#define EVENT_TCP_FLAG_TIMEOUT 3
typedef struct EventTcpState_t {
int socket;
char *buf;
char *cur;
int len;
int chunked;
int delim;
int got_delim;
EventTcpIOFinishedFunc f;
EventSelector *es;
EventHandler *eh;
void *data;
} EventTcpState;
typedef struct EventTcpConnectState_t {
int fd;
EventHandler *conn;
EventTcpConnectFunc f;
void *data;
} EventTcpConnectState;
extern EventHandler *EventTcp_CreateAcceptor(EventSelector *es,
int socket,
EventTcpAcceptFunc f);
extern void EventTcp_Connect(EventSelector *es,
int fd,
struct sockaddr const *addr,
socklen_t addrlen,
EventTcpConnectFunc f,
int timeout,
void *data);
extern EventTcpState *EventTcp_ReadBuf(EventSelector *es,
int socket,
int len,
int delim,
EventTcpIOFinishedFunc f,
int timeout,
int chunked,
void *data);
extern EventTcpState *EventTcp_WriteBuf(EventSelector *es,
int socket,
char const *buf,
int len,
EventTcpIOFinishedFunc f,
int timeout,
void *data);
extern EventTcpState *
EventTcp_ReadNetstring(EventSelector *es,
int socket,
EventTcpIOFinishedFunc f,
int timeout,
void *data);
extern EventTcpState *
EventTcp_WriteNetstring(EventSelector *es,
int socket,
char const *buf,
int len,
EventTcpIOFinishedFunc f,
int timeout,
void *data);
extern void EventTcp_CancelPending(EventTcpState *s);
#endif