Comestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_invoke_user_cb() and iocp_listener_enable().

This commit is contained in:
Jardel Weyrich 2009-12-30 19:24:39 -02:00 committed by Nick Mathewson
parent fec66f9685
commit 510ab6bce0

View File

@ -115,6 +115,7 @@ evconnlistener_new(struct event_base *base,
evutil_socket_t fd) evutil_socket_t fd)
{ {
struct evconnlistener_event *lev; struct evconnlistener_event *lev;
#ifdef WIN32 #ifdef WIN32
if (event_base_get_iocp(base)) { if (event_base_get_iocp(base)) {
const struct win32_extension_fns *ext = const struct win32_extension_fns *ext =
@ -124,6 +125,7 @@ evconnlistener_new(struct event_base *base,
backlog, fd); backlog, fd);
} }
#endif #endif
if (backlog > 0) { if (backlog > 0) {
if (listen(fd, backlog) < 0) if (listen(fd, backlog) < 0)
return NULL; return NULL;
@ -131,16 +133,20 @@ evconnlistener_new(struct event_base *base,
if (listen(fd, 128) < 0) if (listen(fd, 128) < 0)
return NULL; return NULL;
} }
lev = mm_calloc(1, sizeof(struct evconnlistener_event)); lev = mm_calloc(1, sizeof(struct evconnlistener_event));
if (!lev) if (!lev)
return NULL; return NULL;
lev->base.ops = &evconnlistener_event_ops; lev->base.ops = &evconnlistener_event_ops;
lev->base.cb = cb; lev->base.cb = cb;
lev->base.user_data = ptr; lev->base.user_data = ptr;
lev->base.flags = flags; lev->base.flags = flags;
event_assign(&lev->listener, base, fd, EV_READ|EV_PERSIST, event_assign(&lev->listener, base, fd, EV_READ|EV_PERSIST,
listener_read_cb, lev); listener_read_cb, lev);
evconnlistener_enable(&lev->base); evconnlistener_enable(&lev->base);
return &lev->base; return &lev->base;
} }
@ -316,6 +322,7 @@ new_accepting_socket(struct evconnlistener_iocp *lev, int family)
struct accepting_socket *res; struct accepting_socket *res;
int addrlen; int addrlen;
int buflen; int buflen;
if (family == AF_INET) if (family == AF_INET)
addrlen = sizeof(struct sockaddr_in); addrlen = sizeof(struct sockaddr_in);
else if (family == AF_INET6) else if (family == AF_INET6)
@ -325,7 +332,6 @@ new_accepting_socket(struct evconnlistener_iocp *lev, int family)
buflen = (addrlen+16)*2; buflen = (addrlen+16)*2;
res = mm_calloc(1,sizeof(struct accepting_socket)-1+buflen); res = mm_calloc(1,sizeof(struct accepting_socket)-1+buflen);
if (!res) if (!res)
return NULL; return NULL;
@ -410,8 +416,7 @@ accepted_socket_invoke_user_cb(struct deferred_cb *cb, void *arg)
struct sockaddr *sa_local=NULL, *sa_remote=NULL; struct sockaddr *sa_local=NULL, *sa_remote=NULL;
int socklen_local=0, socklen_remote=0; int socklen_local=0, socklen_remote=0;
const struct win32_extension_fns *ext = const struct win32_extension_fns *ext = event_get_win32_extension_fns();
event_get_win32_extension_fns();
EVUTIL_ASSERT(ext->GetAcceptExSockaddrs); EVUTIL_ASSERT(ext->GetAcceptExSockaddrs);
@ -421,17 +426,16 @@ accepted_socket_invoke_user_cb(struct deferred_cb *cb, void *arg)
return; return;
} }
ext->GetAcceptExSockaddrs(as->addrbuf, 0, ext->GetAcceptExSockaddrs(
as->buflen/2, as->buflen/2, as->addrbuf, 0, as->buflen/2, as->buflen/2,
&sa_local, &socklen_local, &sa_local, &socklen_local, &sa_remote, &socklen_remote);
&sa_remote, &socklen_remote);
as->lev->base.cb(&as->lev->base, as->s, sa_remote, as->lev->base.cb(&as->lev->base, as->s, sa_remote,
socklen_remote, as->lev->base.user_data); socklen_remote, as->lev->base.user_data);
as->s = INVALID_SOCKET; as->s = INVALID_SOCKET;
start_accepting(as);/*XXX handle error */ start_accepting(as); /* XXXX handle error */
LeaveCriticalSection(&as->lock); LeaveCriticalSection(&as->lock);
} }
@ -475,7 +479,7 @@ iocp_listener_enable(struct evconnlistener *lev)
continue; continue;
EnterCriticalSection(&as->lock); EnterCriticalSection(&as->lock);
if (!as->free_on_cb && as->s == INVALID_SOCKET) if (!as->free_on_cb && as->s == INVALID_SOCKET)
start_accepting(as); /* detect failure. */ start_accepting(as); /* XXXX handle error */
LeaveCriticalSection(&as->lock); LeaveCriticalSection(&as->lock);
} }
LeaveCriticalSection(&lev_iocp->lock); LeaveCriticalSection(&lev_iocp->lock);