Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 327 lines (278 sloc) 8.633 kb
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
1 /*
e49e289 Update copyright notices to 2012
Nick Mathewson authored
2 * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /**
28 @file buffer_iocp.c
29
30 This module implements overlapped read and write functions for evbuffer
31 objects on Windows.
32 */
0915ca0 @kev009 Include evconfig-private.h in internal files for great good.
kev009 authored
33 #include "event2/event-config.h"
34 #include "evconfig-private.h"
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
35
36 #include "event2/buffer.h"
af8b822 Add missing include to buffer_iocp.c
Nick Mathewson authored
37 #include "event2/buffer_compat.h"
93d4f88 Make buffer iocp stuff compile happily
Nick Mathewson authored
38 #include "event2/util.h"
39 #include "event2/thread.h"
40 #include "util-internal.h"
41 #include "evthread-internal.h"
42 #include "evbuffer-internal.h"
43 #include "iocp-internal.h"
44 #include "mm-internal.h"
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
45
5b5b880 Various MSVC cleanups from Brodie Thiesfield.
Nick Mathewson authored
46 #include <winsock2.h>
e865eb9 More msvc build tweaks.
Nick Mathewson authored
47 #include <windows.h>
48 #include <stdio.h>
49
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
50 #define MAX_WSABUFS 16
51
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
52 /** An evbuffer that can handle overlapped IO. */
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
53 struct evbuffer_overlapped {
54 struct evbuffer buffer;
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
55 /** The socket that we're doing overlapped IO on. */
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
56 evutil_socket_t fd;
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
57
58 /** pending I/O type */
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
59 unsigned read_in_progress : 1;
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
60 unsigned write_in_progress : 1;
61
62 /** The first pinned chain in the buffer. */
63 struct evbuffer_chain *first_pinned;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
64
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
65 /** How many chains are pinned; how many of the fields in buffers
66 * are we using. */
67 int n_buffers;
68 WSABUF buffers[MAX_WSABUFS];
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
69 };
70
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
71 /** Given an evbuffer, return the correponding evbuffer structure, or NULL if
72 * the evbuffer isn't overlapped. */
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
73 static inline struct evbuffer_overlapped *
74 upcast_evbuffer(struct evbuffer *buf)
75 {
23121bf Fix a reversed check in upcast_evbuffer
Nick Mathewson authored
76 if (!buf || !buf->is_overlapped)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
77 return NULL;
78 return EVUTIL_UPCAST(buf, struct evbuffer_overlapped, buffer);
79 }
80
838d0a8 Document many internal functions and pieces of code.
Nick Mathewson authored
81 /** Unpin all the chains noted as pinned in 'eo'. */
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
82 static void
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
83 pin_release(struct evbuffer_overlapped *eo, unsigned flag)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
84 {
85 int i;
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
86 struct evbuffer_chain *next, *chain = eo->first_pinned;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
87
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
88 for (i = 0; i < eo->n_buffers; ++i) {
2e36dbe Use EVUTIL_ASSERT() consistently instead of assert.
Nick Mathewson authored
89 EVUTIL_ASSERT(chain);
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
90 next = chain->next;
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
91 evbuffer_chain_unpin_(chain, flag);
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
92 chain = next;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
93 }
94 }
95
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
96 void
97 evbuffer_commit_read(struct evbuffer *evbuf, ev_ssize_t nBytes)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
98 {
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
99 struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf);
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
100 struct evbuffer_chain **chainp;
101 size_t remaining, len;
102 unsigned i;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
103
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
104 EVBUFFER_LOCK(evbuf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
105 EVUTIL_ASSERT(buf->read_in_progress && !buf->write_in_progress);
e2ca403 Make it compile under gcc --std=c89.
Nick Mathewson authored
106 EVUTIL_ASSERT(nBytes >= 0); /* XXXX Can this be false? */
a84c87d Refactor IOCP callback interface
Nick Mathewson authored
107
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
108 evbuffer_unfreeze(evbuf, 0);
109
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
110 chainp = evbuf->last_with_datap;
111 if (!((*chainp)->flags & EVBUFFER_MEM_PINNED_R))
112 chainp = &(*chainp)->next;
113 remaining = nBytes;
e06f514 Fix signed/unsigned warnings on win32
Nick Mathewson authored
114 for (i = 0; remaining > 0 && i < (unsigned)buf->n_buffers; ++i) {
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
115 EVUTIL_ASSERT(*chainp);
116 len = buf->buffers[i].len;
117 if (remaining < len)
118 len = remaining;
119 (*chainp)->off += len;
120 evbuf->last_with_datap = chainp;
121 remaining -= len;
122 chainp = &(*chainp)->next;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
123 }
124
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
125 pin_release(buf, EVBUFFER_MEM_PINNED_R);
126
127 buf->read_in_progress = 0;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
128
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
129 evbuf->total_len += nBytes;
6acfbdd Make overlapped reads result in evbuffer callbacks getting invoked
Nick Mathewson authored
130 evbuf->n_add_for_cb += nBytes;
131
132 evbuffer_invoke_callbacks(evbuf);
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
133
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
134 evbuffer_decref_and_unlock_(evbuf);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
135 }
136
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
137 void
138 evbuffer_commit_write(struct evbuffer *evbuf, ev_ssize_t nBytes)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
139 {
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
140 struct evbuffer_overlapped *buf = upcast_evbuffer(evbuf);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
141
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
142 EVBUFFER_LOCK(evbuf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
143 EVUTIL_ASSERT(buf->write_in_progress && !buf->read_in_progress);
93d4f88 Make buffer iocp stuff compile happily
Nick Mathewson authored
144 evbuffer_unfreeze(evbuf, 1);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
145 evbuffer_drain(evbuf, nBytes);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
146 pin_release(buf,EVBUFFER_MEM_PINNED_W);
147 buf->write_in_progress = 0;
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
148 evbuffer_decref_and_unlock_(evbuf);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
149 }
150
151 struct evbuffer *
152 evbuffer_overlapped_new(evutil_socket_t fd)
153 {
154 struct evbuffer_overlapped *evo;
155
156 evo = mm_calloc(1, sizeof(struct evbuffer_overlapped));
89d5e09 Add some missing checks for mm_calloc failures
Nick Mathewson authored
157 if (!evo)
158 return NULL;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
159
d313c29 Use LIST rather than TAILQ for evbuffer callbacks
Nick Mathewson authored
160 LIST_INIT(&evo->buffer.callbacks);
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
161 evo->buffer.refcnt = 1;
a0983b6 Initialize last_with_datap correctly in evbuffer_overlapped
Nick Mathewson authored
162 evo->buffer.last_with_datap = &evo->buffer.first;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
163
164 evo->buffer.is_overlapped = 1;
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
165 evo->fd = fd;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
166
167 return &evo->buffer;
168 }
169
170 int
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
171 evbuffer_launch_write(struct evbuffer *buf, ev_ssize_t at_most,
172 struct event_overlapped *ol)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
173 {
174 struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
175 int r = -1;
93d4f88 Make buffer iocp stuff compile happily
Nick Mathewson authored
176 int i;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
177 struct evbuffer_chain *chain;
93d4f88 Make buffer iocp stuff compile happily
Nick Mathewson authored
178 DWORD bytesSent;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
179
180 if (!buf) {
181 /* No buffer, or it isn't overlapped */
182 return -1;
183 }
184
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
185 EVBUFFER_LOCK(buf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
186 EVUTIL_ASSERT(!buf_o->read_in_progress);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
187 if (buf->freeze_start || buf_o->write_in_progress)
188 goto done;
189 if (!buf->total_len) {
190 /* Nothing to write */
191 r = 0;
192 goto done;
e865eb9 More msvc build tweaks.
Nick Mathewson authored
193 } else if (at_most < 0 || (size_t)at_most > buf->total_len) {
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
194 at_most = buf->total_len;
195 }
196 evbuffer_freeze(buf, 1);
197
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
198 buf_o->first_pinned = NULL;
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
199 buf_o->n_buffers = 0;
200 memset(buf_o->buffers, 0, sizeof(buf_o->buffers));
201
202 chain = buf_o->first_pinned = buf->first;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
203
204 for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) {
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
205 WSABUF *b = &buf_o->buffers[i];
5b7a370 Fix warnings on mingw with gcc 4.5
Nick Mathewson authored
206 b->buf = (char*)( chain->buffer + chain->misalign );
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
207 evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_W);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
208
e865eb9 More msvc build tweaks.
Nick Mathewson authored
209 if ((size_t)at_most > chain->off) {
7484df6 Fix even more win64 warnings
Nick Mathewson authored
210 /* XXXX Cast is safe for now, since win32 has no
211 mmaped chains. But later, we need to have this
212 add more WSAbufs if chain->off is greater than
213 ULONG_MAX */
214 b->len = (unsigned long)chain->off;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
215 at_most -= chain->off;
216 } else {
7484df6 Fix even more win64 warnings
Nick Mathewson authored
217 b->len = (unsigned long)at_most;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
218 ++i;
219 break;
220 }
221 }
222
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
223 buf_o->n_buffers = i;
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
224 evbuffer_incref_(buf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
225 if (WSASend(buf_o->fd, buf_o->buffers, i, &bytesSent, 0,
226 &ol->overlapped, NULL)) {
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
227 int error = WSAGetLastError();
228 if (error != WSA_IO_PENDING) {
229 /* An actual error. */
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
230 pin_release(buf_o, EVBUFFER_MEM_PINNED_W);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
231 evbuffer_unfreeze(buf, 1);
232 evbuffer_free(buf); /* decref */
233 goto done;
234 }
235 }
236
237 buf_o->write_in_progress = 1;
238 r = 0;
239 done:
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
240 EVBUFFER_UNLOCK(buf);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
241 return r;
242 }
243
244 int
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
245 evbuffer_launch_read(struct evbuffer *buf, size_t at_most,
246 struct event_overlapped *ol)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
247 {
248 struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
23243b8 Replace reserve/commit with new iovec-based interface. Add a new evb…
Nick Mathewson authored
249 int r = -1, i;
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
250 int nvecs;
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
251 int npin=0;
b7442f8 Replace last_with_data with a slightly smarter version
Nick Mathewson authored
252 struct evbuffer_chain *chain=NULL, **chainp;
93d4f88 Make buffer iocp stuff compile happily
Nick Mathewson authored
253 DWORD bytesRead;
254 DWORD flags = 0;
7a84473 Fix some small win32 build issues on trunk.
Nick Mathewson authored
255 struct evbuffer_iovec vecs[MAX_WSABUFS];
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
256
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
257 if (!buf_o)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
258 return -1;
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
259 EVBUFFER_LOCK(buf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
260 EVUTIL_ASSERT(!buf_o->write_in_progress);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
261 if (buf->freeze_end || buf_o->read_in_progress)
262 goto done;
263
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
264 buf_o->first_pinned = NULL;
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
265 buf_o->n_buffers = 0;
266 memset(buf_o->buffers, 0, sizeof(buf_o->buffers));
267
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
268 if (evbuffer_expand_fast_(buf, at_most, MAX_WSABUFS) == -1)
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
269 goto done;
270 evbuffer_freeze(buf, 0);
271
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
272 nvecs = evbuffer_read_setup_vecs_(buf, at_most,
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
273 vecs, MAX_WSABUFS, &chainp, 1);
23243b8 Replace reserve/commit with new iovec-based interface. Add a new evb…
Nick Mathewson authored
274 for (i=0;i<nvecs;++i) {
8997f23 Use the native "struct iovec" as our "struct evbuffer_iovec" when ava…
Nick Mathewson authored
275 WSABUF_FROM_EVBUFFER_IOV(
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
276 &buf_o->buffers[i],
23243b8 Replace reserve/commit with new iovec-based interface. Add a new evb…
Nick Mathewson authored
277 &vecs[i]);
278 }
279
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
280 buf_o->n_buffers = nvecs;
03afa20 @chris-davis IOCP-related evbuffer fixes.
chris-davis authored
281 buf_o->first_pinned = chain = *chainp;
282
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
283 npin=0;
284 for ( ; chain; chain = chain->next) {
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
285 evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_R);
efc24f7 Get launch_read and launch_write to (apparently) work.
Nick Mathewson authored
286 ++npin;
287 }
2e36dbe Use EVUTIL_ASSERT() consistently instead of assert.
Nick Mathewson authored
288 EVUTIL_ASSERT(npin == nvecs);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
289
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
290 evbuffer_incref_(buf);
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
291 if (WSARecv(buf_o->fd, buf_o->buffers, nvecs, &bytesRead, &flags,
e5bbd40 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson authored
292 &ol->overlapped, NULL)) {
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
293 int error = WSAGetLastError();
294 if (error != WSA_IO_PENDING) {
295 /* An actual error. */
d7d1f1d Move responsibility for IOCP callback into bufferevent_async.
Nick Mathewson authored
296 pin_release(buf_o, EVBUFFER_MEM_PINNED_R);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
297 evbuffer_unfreeze(buf, 0);
298 evbuffer_free(buf); /* decref */
299 goto done;
300 }
301 }
302
303 buf_o->read_in_progress = 1;
304 r = 0;
305 done:
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
306 EVBUFFER_UNLOCK(buf);
ca737ff Add draft (nonworking) versions of iocp code to hack on more.
Nick Mathewson authored
307 return r;
308 }
309
31d89f2 Add a "ctrl" mechanism to bufferevents for property access.
Nick Mathewson authored
310 evutil_socket_t
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
311 evbuffer_overlapped_get_fd_(struct evbuffer *buf)
31d89f2 Add a "ctrl" mechanism to bufferevents for property access.
Nick Mathewson authored
312 {
313 struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
314 return buf_o ? buf_o->fd : -1;
315 }
86db1c8 Commit ConnectEx code to get connect working with async bufferevents.
Nick Mathewson authored
316
317 void
cb9da0b Fix all identifiers with names beginning with underscore.
Nick Mathewson authored
318 evbuffer_overlapped_set_fd_(struct evbuffer *buf, evutil_socket_t fd)
86db1c8 Commit ConnectEx code to get connect working with async bufferevents.
Nick Mathewson authored
319 {
320 struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf);
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
321 EVBUFFER_LOCK(buf);
86db1c8 Commit ConnectEx code to get connect working with async bufferevents.
Nick Mathewson authored
322 /* XXX is this right?, should it cancel current I/O operations? */
323 if (buf_o)
324 buf_o->fd = fd;
76cd2b7 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Nick Mathewson authored
325 EVBUFFER_UNLOCK(buf);
86db1c8 Commit ConnectEx code to get connect working with async bufferevents.
Nick Mathewson authored
326 }
Something went wrong with that request. Please try again.