libevent patch required for SMTP test
[ioevent.git] / libevent-1.4.2-rc.patch
blob739d22fb3294a0a62c51d18a97c127e4cc29abdf
1 --- libevent-1.4.2-rc/evbuffer.c 2007-11-18 07:08:36.000000000 +0000
2 +++ libevent-1.4.2-rc.new/evbuffer.c 2008-04-05 20:13:51.000000000 +0000
3 @@ -27,6 +27,10 @@
5 #include <sys/types.h>
7 +#include <sys/socket.h>
9 +#include <netinet/in.h>
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 @@ -50,11 +54,48 @@
15 #include "evutil.h"
16 #include "event.h"
18 +#ifndef WIN32
19 +#include <unistd.h>
20 +#endif
22 /* prototypes */
24 void bufferevent_setwatermark(struct bufferevent *, short, size_t, size_t);
25 void bufferevent_read_pressure_cb(struct evbuffer *, size_t, size_t, void *);
27 +//socket
28 +int bufev_socket_new(void) {
29 + return socket(AF_INET, SOCK_STREAM, 0);
31 +// connect
32 +int bufev_socket_connect(int sock, struct sockaddr_in *addr) {
33 + return connect(sock, (struct sockaddr*)addr, sizeof(struct sockaddr_in));
35 +// accept
36 +struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg) {
37 + int returned;
38 + returned = accept(listen_sock, NULL, NULL);
40 + if(returned < 0) {
41 + perror("Accept failed : ");
42 + return NULL;
43 + }
45 + return bufferevent_new(returned, readcb, writecb, errorcb, cbarg);
47 +// listen
48 +int bufev_socket_listen(int sock, int backlog) {
49 + return listen(sock, backlog);
51 +// bind
52 +int bufev_socket_bind(int sock, struct sockaddr_in *bind_to) {
53 + return bind(sock, (struct sockaddr*) bind_to, sizeof(struct sockaddr_in));
56 +int bufev_socket_close(int sock) {
57 + return close(sock);
60 static int
61 bufferevent_add(struct event *ev, int timeout)
63 @@ -287,6 +328,12 @@
64 free(bufev);
67 +//TODO:
68 +//void bufferevent_close_and_free(struct bufferevent *bufev) {
69 +// bufev_socket_close(bufev->fd);
70 +// bufferevent_free(bufev);
71 +//}
74 * Returns 0 on success;
75 * -1 on failure.
76 --- libevent-1.4.2-rc/event.h 2008-02-23 01:36:12.000000000 +0000
77 +++ libevent-1.4.2-rc.new/event.h 2008-04-05 20:13:18.000000000 +0000
78 @@ -163,6 +163,9 @@
79 #ifdef _EVENT_HAVE_SYS_TYPES_H
80 #include <sys/types.h>
81 #endif
82 +#ifdef _EVENT_HAVE_SYS_SOCKET_H
83 +#include <sys/socket.h>
84 +#endif
85 #ifdef _EVENT_HAVE_SYS_TIME_H
86 #include <sys/time.h>
87 #endif
88 @@ -174,6 +177,8 @@
89 /* For int types. */
90 #include <evutil.h>
92 +struct sockaddr_in;
94 #ifdef WIN32
95 #define WIN32_LEAN_AND_MEAN
96 #include <windows.h>
97 @@ -766,6 +771,54 @@
102 + * From: https://tor-svn.freehaven.net/svn/libevent-urz
104 + * Documentation for the below is rough, but should be complete
106 + * int bufev_socket_new(void);
107 + * Creates a new socket which is compatible with the local implementation
108 + * of bufferevents. The return value is only required to fit in the same
109 + * space as an int, it is not required to actually *be* an int.
110 + * Regardless the true return type, (int) -1 is a reserved value which
111 + * means creating a new socket failed.
113 + * int bufev_socket_connect(int sock, struct sockaddr_in *addr);
114 + * Connects a socket to an internet address. Returns -1 on failure,
115 + * 0 on success.
117 + * struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
118 + * listen_sock is a listening socket (see bufev_socket_listen).
119 + * all other arguments are as bufferevent_new().
120 + * Takes one connection off the pending connection queue for a listening socket and
121 + * creates a new bufferevent based on the connection.
123 + * int bufev_socket_listen(int sock, int backlog);
124 + * Sets a socket (created with bufev_socket_new()) to listen. The socket must first be bound
125 + * (with bufev_socket_bind()). Returns 0 on success, -1 on failure.
127 + * int bufev_socket_bind(int sock, struct sockaddr_in *bind_to);
128 + * Binds a socket (created with bufev_socket_new()) to a particular internet address.
129 + * returns 0 on success, -1 on failure.
131 + * int bufev_socket_close(int sock);
132 + * Closes a socket (created with bufev_socket_new()). Returns 0 on success, -1 on error.
133 + */
135 +//socket
136 +int bufev_socket_new(void);
137 +// connect
138 +int bufev_socket_connect(int sock, struct sockaddr_in *addr);
139 +// accept
140 +struct bufferevent *bufev_socket_accept(int listen_sock, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg);
141 +// listen
142 +int bufev_socket_listen(int sock, int backlog);
143 +// bind
144 +int bufev_socket_bind(int sock, struct sockaddr_in *bind_to);
145 +// close
146 +int bufev_socket_close(int sock);
150 Create a new bufferevent.
152 --- libevent-1.4.2-rc/evhttp.h 2008-02-17 01:16:12.000000000 +0000
153 +++ libevent-1.4.2-rc.new/evhttp.h 2008-04-05 20:13:34.000000000 +0000
154 @@ -333,6 +333,10 @@
156 char *evhttp_htmlescape(const char *html);
158 +int socket_connect(int fd, const char *address, unsigned short port);
159 +int bind_socket_ai(struct addrinfo *);
160 +int bind_socket(const char *, u_short);
162 #ifdef __cplusplus
164 #endif
165 --- libevent-1.4.2-rc/http.c 2008-02-17 01:16:12.000000000 +0000
166 +++ libevent-1.4.2-rc.new/http.c 2008-04-05 20:13:51.000000000 +0000
167 @@ -151,9 +151,6 @@
169 extern int debug;
171 -static int socket_connect(int fd, const char *address, unsigned short port);
172 -static int bind_socket_ai(struct addrinfo *);
173 -static int bind_socket(const char *, u_short);
174 static void name_from_addr(struct sockaddr *, socklen_t, char **, char **);
175 static int evhttp_associate_new_request_with_connection(
176 struct evhttp_connection *evcon);
177 @@ -2371,7 +2368,7 @@
179 /* Either connect or bind */
181 -static int
182 +int
183 bind_socket_ai(struct addrinfo *ai)
185 int fd, on = 1, r;
186 @@ -2448,7 +2445,7 @@
187 return (aitop);
190 -static int
191 +int
192 bind_socket(const char *address, u_short port)
194 int fd;
195 @@ -2468,7 +2465,7 @@
196 return (fd);
199 -static int
200 +int
201 socket_connect(int fd, const char *address, unsigned short port)
203 struct addrinfo *ai = make_addrinfo(address, port);