diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-04-14 20:11:10 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-04-14 20:11:10 +0000 |
commit | 93d4f884aa2f42d832b4fefa0fe4d39bb0098750 (patch) | |
tree | 2cc14b3c05688266ebde83ae409292e42d21b857 | |
parent | fe95df15d3c5ad424c76f75596452f0229e191b2 (diff) | |
download | libevent-93d4f884aa2f42d832b4fefa0fe4d39bb0098750.tar.gz |
Make buffer iocp stuff compile happily
svn:r1174
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | buffer.c | 2 | ||||
-rw-r--r-- | buffer_iocp.c | 62 | ||||
-rw-r--r-- | evbuffer-internal.h | 10 | ||||
-rw-r--r-- | event_iocp.c | 8 | ||||
-rw-r--r-- | include/event2/buffer.h | 4 | ||||
-rw-r--r-- | iocp-internal.h | 6 |
7 files changed, 66 insertions, 29 deletions
diff --git a/Makefile.am b/Makefile.am index 1c7cb87e..2f0357b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,6 +35,7 @@ EXTRA_DIST = \ Doxyfile \ kqueue.c epoll_sub.c epoll.c select.c poll.c signal.c \ evport.c devpoll.c event_rpcgen.py \ + event_iocp.c buffer_iocp.c iocp-internal.h \ sample/Makefile.am sample/Makefile.in sample/event-test.c \ sample/signal-test.c sample/time-test.c \ test/Makefile.am test/Makefile.in test/bench.c test/regress.c \ @@ -61,7 +62,7 @@ SUBDIRS = . include sample test if BUILD_WIN32 SYS_LIBS = -lws2_32 -SYS_SRC = WIN32-Code/win32.c evthread_win32.c +SYS_SRC = WIN32-Code/win32.c evthread_win32.c buffer_iocp.c event_iocp.c SYS_INCLUDES = -IWIN32-Code else @@ -1341,7 +1341,7 @@ err: /* Make sure that datlen bytes are available for writing in the last two * chains. Never copies or moves data. */ -static int +int _evbuffer_expand_fast(struct evbuffer *buf, size_t datlen) { struct evbuffer_chain *chain = buf->last, *tmp; diff --git a/buffer_iocp.c b/buffer_iocp.c index b604be58..b8be1489 100644 --- a/buffer_iocp.c +++ b/buffer_iocp.c @@ -1,6 +1,17 @@ +#include <windows.h> +#include <assert.h> + #include "event2/buffer.h" -#incldue "buffer-internal.h" +#include "event2/buffer_compat.h" +#include "event2/util.h" +#include "event2/thread.h" +#include "event-config.h" +#include "util-internal.h" +#include "evthread-internal.h" +#include "evbuffer-internal.h" +#include "iocp-internal.h" +#include "mm-internal.h" #define MAX_WSABUFS 16 @@ -26,7 +37,7 @@ struct evbuffer_overlapped { static inline struct evbuffer_overlapped * upcast_evbuffer(struct evbuffer *buf) { - if (!buf || !buf->is_overlapped) + if (!buf || buf->is_overlapped) return NULL; return EVUTIL_UPCAST(buf, struct evbuffer_overlapped, buffer); } @@ -38,12 +49,13 @@ upcast_overlapped(struct event_overlapped *o) } static void -pin_release(struct evbuffer_overlapped *eo, unsigned flag) +pin_release(struct event_overlapped *eo, unsigned flag) { int i; - struct evbuffer_chain *chain = eo->first_pinned; + struct buffer_overlapped *bo = upcast_overlapped(eo); + struct evbuffer_chain *chain = bo->first_pinned; - for (i = 0; i < eo->n_buffers; ++i) { + for (i = 0; i < bo->n_buffers; ++i) { _evbuffer_chain_unpin(chain, flag); chain = chain->next; assert(chain); @@ -51,13 +63,13 @@ pin_release(struct evbuffer_overlapped *eo, unsigned flag) } static void -read_completed(struct event_overlapped *eo, uintptr_t, ssize_t nBytes) +read_completed(struct event_overlapped *eo, uintptr_t _, ssize_t nBytes) { struct buffer_overlapped *buf_o = upcast_overlapped(eo); struct evbuffer_overlapped *buf = buf_o->buf; struct evbuffer *evbuf = &buf->buffer; - struct evbuffer_chain chain = buf_o->first_pinned; + struct evbuffer_chain *chain = buf_o->first_pinned; EVBUFFER_LOCK(evbuf, EVTHREAD_WRITE); evbuffer_unfreeze(evbuf, 0); @@ -77,14 +89,14 @@ read_completed(struct event_overlapped *eo, uintptr_t, ssize_t nBytes) assert(0); } - pin_release(buf,EVBUFFER_MEM_PINNED_R); + pin_release(eo, EVBUFFER_MEM_PINNED_R); - evbuf->read_in_progress = 0; + buf->read_in_progress = 0; _evbuffer_decref_and_unlock(evbuf); } static void -write_completed(struct event_overlapped *eo, uintptr_t, ssize_t nBytes) +write_completed(struct event_overlapped *eo, uintptr_t _, ssize_t nBytes) { struct buffer_overlapped *buf_o = upcast_overlapped(eo); struct evbuffer_overlapped *buf = buf_o->buf; @@ -92,9 +104,9 @@ write_completed(struct event_overlapped *eo, uintptr_t, ssize_t nBytes) struct evbuffer *evbuf = &buf->buffer; EVBUFFER_LOCK(evbuf, EVTHREAD_WRITE); - evbuffer_unfreeze(buf, 1); + evbuffer_unfreeze(evbuf, 1); evbuffer_drain(evbuf, nBytes); - pin_release(buf,EVBUFFER_MEM_PINNED_W); + pin_release(eo,EVBUFFER_MEM_PINNED_W); buf->write_in_progress = 0; _evbuffer_decref_and_unlock(evbuf); } @@ -106,7 +118,7 @@ evbuffer_overlapped_new(evutil_socket_t fd) evo = mm_calloc(1, sizeof(struct evbuffer_overlapped)); - TAILQ_INIT(&evo->buf.callbacks); + TAILQ_INIT(&evo->buffer.callbacks); evo->buffer.is_overlapped = 1; @@ -118,8 +130,9 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); int r = -1; - int idx; + int i; struct evbuffer_chain *chain; + DWORD bytesSent; if (!buf) { /* No buffer, or it isn't overlapped */ @@ -142,7 +155,7 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most) memset(&buf_o->write_info, 0, sizeof(buf_o->write_info)); buf_o->write_info.buf = buf_o; buf_o->write_info.event_overlapped.cb = write_completed; - chain = buf_o->first_pinned = buf->first; + chain = buf_o->write_info.first_pinned = buf->first; for (i=0; i < MAX_WSABUFS && chain; ++i, chain=chain->next) { WSABUF *b = &buf_o->write_info.buffers[i]; @@ -159,14 +172,14 @@ evbuffer_launch_write(struct evbuffer *buf, ssize_t at_most) } } - buf_o->write_info.n_vectors = i; + buf_o->write_info.n_buffers = i; _evbuffer_incref(buf); - if (WSASend(buf->fd, b->buffers, i, &bytesSent, 0, + if (WSASend(buf_o->fd, buf_o->write_info.buffers, i, &bytesSent, 0, &buf_o->write_info.event_overlapped.overlapped, NULL)) { int error = WSAGetLastError(); if (error != WSA_IO_PENDING) { /* An actual error. */ - pin_release(buf_o, EVBUFFER_MEM_PINNED_W); + pin_release(&buf_o->write_info.event_overlapped, EVBUFFER_MEM_PINNED_W); evbuffer_unfreeze(buf, 1); evbuffer_free(buf); /* decref */ goto done; @@ -185,9 +198,10 @@ evbuffer_launch_read(struct evbuffer *buf, size_t at_most) { struct evbuffer_overlapped *buf_o = upcast_evbuffer(buf); int r = -1; - WSABUF *buffers; int nvecs; struct evbuffer_chain *chain=NULL; + DWORD bytesRead; + DWORD flags = 0; if (!buf) return -1; @@ -195,7 +209,7 @@ evbuffer_launch_read(struct evbuffer *buf, size_t at_most) if (buf->freeze_end || buf_o->read_in_progress) goto done; - if (_evbuffer_expand_fast(buf, howmuch) == -1) + if (_evbuffer_expand_fast(buf, at_most) == -1) goto done; evbuffer_freeze(buf, 0); @@ -204,19 +218,19 @@ evbuffer_launch_read(struct evbuffer *buf, size_t at_most) buf_o->read_info.buf = buf_o; buf_o->read_info.event_overlapped.cb = read_completed; - nvecs = _evbuffer_read_setup_vecs(buf, howmuch, + nvecs = _evbuffer_read_setup_vecs(buf, at_most, buf_o->read_info.buffers, &chain); buf_o->read_info.n_buffers = nvecs; - buf_o->first_pinned = chain; + buf_o->read_info.first_pinned = chain; for ( ; chain; chain = chain->next) _evbuffer_chain_pin(chain, EVBUFFER_MEM_PINNED_R); _evbuffer_incref(buf); - if (WSARecv(buf->fd, buf_o->read_info.buffers, nvecs, &bytesRead, &flags, &buf_o->read_info.event_overlapped.overlapped, NULL)) { + if (WSARecv(buf_o->fd, buf_o->read_info.buffers, nvecs, &bytesRead, &flags, &buf_o->read_info.event_overlapped.overlapped, NULL)) { int error = WSAGetLastError(); if (error != WSA_IO_PENDING) { /* An actual error. */ - pin_release(buf_o, EVBUFFER_MEM_PINNED_R); + pin_release(&buf_o->read_info.event_overlapped, EVBUFFER_MEM_PINNED_R); evbuffer_unfreeze(buf, 0); evbuffer_free(buf); /* decref */ goto done; diff --git a/evbuffer-internal.h b/evbuffer-internal.h index d6d9b1c0..bee2e4d9 100644 --- a/evbuffer-internal.h +++ b/evbuffer-internal.h @@ -80,6 +80,9 @@ struct evbuffer { unsigned freeze_start : 1; unsigned freeze_end : 1; unsigned deferred_cbs : 1; +#ifdef WIN32 + unsigned is_overlapped : 1; +#endif struct event_base *ev_base; @@ -128,7 +131,7 @@ struct evbuffer_chain { * EVBUFFER_IMMUTABLE will be set in flags. For sendfile, it * may point to NULL. */ - u_char *buffer; + unsigned char *buffer; }; /* this is currently used by both mmap and sendfile */ @@ -197,6 +200,7 @@ void _evbuffer_incref(struct evbuffer *buf); void _evbuffer_chain_pin(struct evbuffer_chain *chain, unsigned flag); void _evbuffer_chain_unpin(struct evbuffer_chain *chain, unsigned flag); void _evbuffer_decref_and_unlock(struct evbuffer *buffer); +int _evbuffer_expand_fast(struct evbuffer *, size_t); #ifdef _EVENT_HAVE_SYS_UIO_H int _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch, @@ -206,6 +210,10 @@ int _evbuffer_read_setup_vecs(struct evbuffer *buf, ssize_t howmuch, WSABUF *vecs, struct evbuffer_chain **chainp); #endif +#ifdef WIN32 +struct evbuffer *evbuffer_overlapped_new(evutil_socket_t fd); +#endif + #ifdef __cplusplus } #endif diff --git a/event_iocp.c b/event_iocp.c index de4c35e2..8df1dd5d 100644 --- a/event_iocp.c +++ b/event_iocp.c @@ -1,4 +1,10 @@ +#include "event-config.h" +#include <sys/types.h> +#include <windows.h> +#include <WinBase.h> +#include "event2/util.h" +#include "util-internal.h" #include "iocp-internal.h" #define N_OVERLAPPED_ENTRIES 32 @@ -6,7 +12,7 @@ void event_overlapped_init(struct event_overlapped *o, iocp_callback cb) { - memeset(o, 0, sizeof(struct event_overlapped)); + memset(o, 0, sizeof(struct event_overlapped)); o->cb = cb; } diff --git a/include/event2/buffer.h b/include/event2/buffer.h index a4b9a4cf..4c5a3b75 100644 --- a/include/event2/buffer.h +++ b/include/event2/buffer.h @@ -67,6 +67,10 @@ extern "C" { #include <event-config.h> #include <stdarg.h> +#ifdef _EVENT_HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif +#include <event2/util.h> struct evbuffer; diff --git a/iocp-internal.h b/iocp-internal.h index 4fd507c9..9d49a7c0 100644 --- a/iocp-internal.h +++ b/iocp-internal.h @@ -31,6 +31,7 @@ extern "C" { #endif +struct event_overlapped; typedef void (*iocp_callback)(struct event_overlapped *, uintptr_t, ssize_t); struct event_overlapped { @@ -40,11 +41,14 @@ struct event_overlapped { struct event_iocp_port { HANDLE port; - int shutdown = 0; }; void event_overlapped_init(struct event_overlapped *, iocp_callback cb); +struct evbuffer; +int evbuffer_launch_write(struct evbuffer *buf, ssize_t atmost); +int evbuffer_launch_read(struct evbuffer *buf, size_t atmost); + #ifdef __cplusplus } #endif |