From 014265ec0a44cfbbc2117c4af605caa4d207524c Mon Sep 17 00:00:00 2001 From: Scott Lindeneau Date: Mon, 1 Sep 2008 02:28:04 +0900 Subject: [PATCH] Modifies accept_socket to take an accepting socket as an argument. To: wine-patches Modfies sock.c accept_socket to take a second socket handle as an arguement that will be used to accept the connection onto instead of creating a new socket. AcceptEx requires this. --- include/wine/server_protocol.h | 3 ++- server/protocol.def | 1 + server/sock.c | 39 ++++++++++++++++++++++++++++----------- server/trace.c | 1 + 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 327c174..e01a193 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -1154,6 +1154,7 @@ struct accept_socket_request { struct request_header __header; obj_handle_t lhandle; + obj_handle_t ahandle; unsigned int access; unsigned int attributes; }; @@ -4998,6 +4999,6 @@ union generic_reply struct add_fd_completion_reply add_fd_completion_reply; }; -#define SERVER_PROTOCOL_VERSION 342 +#define SERVER_PROTOCOL_VERSION 343 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */ diff --git a/server/protocol.def b/server/protocol.def index b78592f..185ec64 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -950,6 +950,7 @@ enum server_fd_type /* Accept a socket */ @REQ(accept_socket) obj_handle_t lhandle; /* handle to the listening socket */ + obj_handle_t ahandle; /* handle to the accepting socket */ unsigned int access; /* wanted access rights */ unsigned int attributes; /* object attributes */ @REPLY diff --git a/server/sock.c b/server/sock.c index f4fe25e..1c0034e 100644 --- a/server/sock.c +++ b/server/sock.c @@ -621,16 +621,16 @@ static struct object *create_socket( int family, int type, int protocol, unsigne } /* accept a socket (creates a new fd) */ -static struct sock *accept_socket( obj_handle_t handle ) +static struct sock *accept_socket( obj_handle_t handle, obj_handle_t ahandle ) { - struct sock *acceptsock; + struct sock *acceptsock = NULL; struct sock *sock; - int acceptfd; - struct sockaddr saddr; + int acceptfd; + struct sockaddr saddr; sock = (struct sock *)get_handle_obj( current->process, handle, FILE_READ_DATA, &sock_ops ); if (!sock) - return NULL; + return NULL; if ( sock->deferred ) { @@ -652,7 +652,18 @@ static struct sock *accept_socket( obj_handle_t handle ) release_object( sock ); return NULL; } - if (!(acceptsock = alloc_object( &sock_ops ))) + + if(ahandle){ + acceptsock = (struct sock *)get_handle_obj(current->process, ahandle, FILE_READ_DATA | FILE_WRITE_DATA, &sock_ops ); + if(acceptsock){ + if(acceptsock->event) + release_object( acceptsock->event ); + release_object( acceptsock->fd ); + } + }else{ + acceptsock = alloc_object( &sock_ops ); + } + if (!acceptsock) { close( acceptfd ); release_object( sock ); @@ -673,7 +684,7 @@ static struct sock *accept_socket( obj_handle_t handle ) acceptsock->event = NULL; acceptsock->window = sock->window; acceptsock->message = sock->message; - acceptsock->wparam = 0; + acceptsock->wparam = ahandle; if (sock->event) acceptsock->event = (struct event *)grab_object( sock->event ); acceptsock->flags = sock->flags; acceptsock->deferred = NULL; @@ -777,6 +788,7 @@ DECL_HANDLER(create_socket) if ((obj = create_socket( req->family, req->type, req->protocol, req->flags )) != NULL) { reply->handle = alloc_handle( current->process, obj, req->access, req->attributes ); + ((struct sock*)obj)->wparam = reply->handle; /* wparam for message is the socket handle */ release_object( obj ); } } @@ -787,11 +799,16 @@ DECL_HANDLER(accept_socket) struct sock *sock; reply->handle = 0; - if ((sock = accept_socket( req->lhandle )) != NULL) + if ((sock = accept_socket( req->lhandle, req->ahandle )) != NULL) { - reply->handle = alloc_handle( current->process, &sock->obj, req->access, req->attributes ); - sock->wparam = reply->handle; /* wparam for message is the socket handle */ - sock_reselect( sock ); + if (req->ahandle) + reply->handle = req->ahandle; + else + { + reply->handle = alloc_handle( current->process, &sock->obj, req->access, req->attributes ); + sock->wparam = reply->handle; /* wparam for message is the socket handle */ + sock_reselect( sock ); + } release_object( &sock->obj ); } } diff --git a/server/trace.c b/server/trace.c index d2b0411..3775fb1 100644 --- a/server/trace.c +++ b/server/trace.c @@ -1398,6 +1398,7 @@ static void dump_create_socket_reply( const struct create_socket_reply *req ) static void dump_accept_socket_request( const struct accept_socket_request *req ) { fprintf( stderr, " lhandle=%p,", req->lhandle ); + fprintf( stderr, " ahandle=%p,", req->ahandle ); fprintf( stderr, " access=%08x,", req->access ); fprintf( stderr, " attributes=%08x", req->attributes ); } -- 1.5.4.3