Commit 2035294d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

rpcrt4: Use standard Wine list to store connections in RpcServerProtseq.

parent e6215938
...@@ -90,7 +90,7 @@ typedef struct _RpcConnection ...@@ -90,7 +90,7 @@ typedef struct _RpcConnection
/* The active interface bound to server. */ /* The active interface bound to server. */
RPC_SYNTAX_IDENTIFIER ActiveInterface; RPC_SYNTAX_IDENTIFIER ActiveInterface;
USHORT NextCallId; USHORT NextCallId;
struct _RpcConnection* Next; struct list protseq_entry;
struct _RpcBinding *server_binding; struct _RpcBinding *server_binding;
} RpcConnection; } RpcConnection;
......
...@@ -670,7 +670,7 @@ static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg) ...@@ -670,7 +670,7 @@ static DWORD CALLBACK RPCRT4_server_thread(LPVOID the_arg)
/* cleanup */ /* cleanup */
cps->ops->free_wait_array(cps, objs); cps->ops->free_wait_array(cps, objs);
EnterCriticalSection(&cps->cs); EnterCriticalSection(&cps->cs);
for (conn = cps->conn; conn; conn = conn->Next) LIST_FOR_EACH_ENTRY(conn, &cps->connections, RpcConnection, protseq_entry)
RPCRT4_CloseConnection(conn); RPCRT4_CloseConnection(conn);
LeaveCriticalSection(&cps->cs); LeaveCriticalSection(&cps->cs);
...@@ -802,14 +802,16 @@ static RPC_STATUS RPCRT4_stop_listen(BOOL auto_listen) ...@@ -802,14 +802,16 @@ static RPC_STATUS RPCRT4_stop_listen(BOOL auto_listen)
static BOOL RPCRT4_protseq_is_endpoint_registered(RpcServerProtseq *protseq, const char *endpoint) static BOOL RPCRT4_protseq_is_endpoint_registered(RpcServerProtseq *protseq, const char *endpoint)
{ {
RpcConnection *conn; RpcConnection *conn;
BOOL registered = FALSE;
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
for (conn = protseq->conn; conn; conn = conn->Next) LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection, protseq_entry) {
{ if (!endpoint || !strcmp(endpoint, conn->Endpoint)) {
if (!endpoint || !strcmp(endpoint, conn->Endpoint)) registered = TRUE;
break; break;
} }
}
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
return (conn != NULL); return registered;
} }
static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps, const char *endpoint) static RPC_STATUS RPCRT4_use_protseq(RpcServerProtseq* ps, const char *endpoint)
...@@ -858,7 +860,7 @@ RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector ) ...@@ -858,7 +860,7 @@ RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
count = 0; count = 0;
LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) { LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
EnterCriticalSection(&ps->cs); EnterCriticalSection(&ps->cs);
for (conn = ps->conn; conn; conn = conn->Next) LIST_FOR_EACH_ENTRY(conn, &ps->connections, RpcConnection, protseq_entry)
count++; count++;
LeaveCriticalSection(&ps->cs); LeaveCriticalSection(&ps->cs);
} }
...@@ -871,7 +873,7 @@ RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector ) ...@@ -871,7 +873,7 @@ RPC_STATUS WINAPI RpcServerInqBindings( RPC_BINDING_VECTOR** BindingVector )
count = 0; count = 0;
LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) { LIST_FOR_EACH_ENTRY(ps, &protseqs, RpcServerProtseq, entry) {
EnterCriticalSection(&ps->cs); EnterCriticalSection(&ps->cs);
for (conn = ps->conn; conn; conn = conn->Next) { LIST_FOR_EACH_ENTRY(conn, &ps->connections, RpcConnection, protseq_entry) {
RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count], RPCRT4_MakeBinding((RpcBinding**)&(*BindingVector)->BindingH[count],
conn); conn);
count++; count++;
...@@ -943,7 +945,7 @@ static RPC_STATUS alloc_serverprotoseq(UINT MaxCalls, const char *Protseq, RpcSe ...@@ -943,7 +945,7 @@ static RPC_STATUS alloc_serverprotoseq(UINT MaxCalls, const char *Protseq, RpcSe
(*ps)->Protseq = RPCRT4_strdupA(Protseq); (*ps)->Protseq = RPCRT4_strdupA(Protseq);
(*ps)->ops = ops; (*ps)->ops = ops;
(*ps)->MaxCalls = 0; (*ps)->MaxCalls = 0;
(*ps)->conn = NULL; list_init(&(*ps)->connections);
InitializeCriticalSection(&(*ps)->cs); InitializeCriticalSection(&(*ps)->cs);
(*ps)->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": RpcServerProtseq.cs"); (*ps)->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": RpcServerProtseq.cs");
(*ps)->is_listening = FALSE; (*ps)->is_listening = FALSE;
......
...@@ -33,7 +33,7 @@ typedef struct _RpcServerProtseq ...@@ -33,7 +33,7 @@ typedef struct _RpcServerProtseq
LPSTR Protseq; /* RO */ LPSTR Protseq; /* RO */
UINT MaxCalls; /* RO */ UINT MaxCalls; /* RO */
/* list of listening connections */ /* list of listening connections */
RpcConnection* conn; /* CS cs */ struct list connections; /* CS cs */
CRITICAL_SECTION cs; CRITICAL_SECTION cs;
/* is the server currently listening? */ /* is the server currently listening? */
......
...@@ -254,8 +254,7 @@ static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq ...@@ -254,8 +254,7 @@ static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq
I_RpcFree(pname); I_RpcFree(pname);
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
Connection->Next = protseq->conn; list_add_head(&protseq->connections, &Connection->protseq_entry);
protseq->conn = Connection;
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
return r; return r;
...@@ -316,8 +315,7 @@ static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protse ...@@ -316,8 +315,7 @@ static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protse
I_RpcFree(pname); I_RpcFree(pname);
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
Connection->Next = protseq->conn; list_add_head(&protseq->connections, &Connection->protseq_entry);
protseq->conn = Connection;
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
return r; return r;
...@@ -662,12 +660,10 @@ static void *rpcrt4_protseq_np_get_wait_array(RpcServerProtseq *protseq, void *p ...@@ -662,12 +660,10 @@ static void *rpcrt4_protseq_np_get_wait_array(RpcServerProtseq *protseq, void *p
/* open and count connections */ /* open and count connections */
*count = 1; *count = 1;
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_np, common.protseq_entry) {
while (conn) {
rpcrt4_conn_listen_pipe(conn); rpcrt4_conn_listen_pipe(conn);
if (conn->listen_thread) if (conn->listen_thread)
(*count)++; (*count)++;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
} }
/* make array of connections */ /* make array of connections */
...@@ -684,11 +680,9 @@ static void *rpcrt4_protseq_np_get_wait_array(RpcServerProtseq *protseq, void *p ...@@ -684,11 +680,9 @@ static void *rpcrt4_protseq_np_get_wait_array(RpcServerProtseq *protseq, void *p
objs[0] = npps->mgr_event; objs[0] = npps->mgr_event;
*count = 1; *count = 1;
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_np, common.protseq_entry) {
while (conn) {
if ((objs[*count] = conn->listen_thread)) if ((objs[*count] = conn->listen_thread))
(*count)++; (*count)++;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
} }
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
return objs; return objs;
...@@ -704,7 +698,7 @@ static int rpcrt4_protseq_np_wait_for_new_connection(RpcServerProtseq *protseq, ...@@ -704,7 +698,7 @@ static int rpcrt4_protseq_np_wait_for_new_connection(RpcServerProtseq *protseq,
HANDLE b_handle; HANDLE b_handle;
HANDLE *objs = wait_array; HANDLE *objs = wait_array;
DWORD res; DWORD res;
RpcConnection *cconn; RpcConnection *cconn = NULL;
RpcConnection_np *conn; RpcConnection_np *conn;
if (!objs) if (!objs)
...@@ -731,30 +725,25 @@ static int rpcrt4_protseq_np_wait_for_new_connection(RpcServerProtseq *protseq, ...@@ -731,30 +725,25 @@ static int rpcrt4_protseq_np_wait_for_new_connection(RpcServerProtseq *protseq,
b_handle = objs[res - WAIT_OBJECT_0]; b_handle = objs[res - WAIT_OBJECT_0];
/* find which connection got a RPC */ /* find which connection got a RPC */
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_np, common.protseq_entry) {
while (conn) { if (b_handle == conn->listen_thread) {
if (b_handle == conn->listen_thread) break;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
}
cconn = NULL;
if (conn)
{
DWORD exit_code; DWORD exit_code;
if (GetExitCodeThread(conn->listen_thread, &exit_code) && exit_code == RPC_S_OK) if (GetExitCodeThread(conn->listen_thread, &exit_code) && exit_code == RPC_S_OK)
RPCRT4_SpawnConnection(&cconn, &conn->common); RPCRT4_SpawnConnection(&cconn, &conn->common);
CloseHandle(conn->listen_thread); CloseHandle(conn->listen_thread);
conn->listen_thread = 0; conn->listen_thread = 0;
break;
}
} }
else
ERR("failed to locate connection for handle %p\n", b_handle);
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
if (cconn) if (!cconn)
{ {
ERR("failed to locate connection for handle %p\n", b_handle);
return -1;
}
RPCRT4_new_client(cconn); RPCRT4_new_client(cconn);
return 1; return 1;
} }
else return -1;
}
} }
static size_t rpcrt4_ncalrpc_get_top_of_tower(unsigned char *tower_data, static size_t rpcrt4_ncalrpc_get_top_of_tower(unsigned char *tower_data,
...@@ -1211,7 +1200,6 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr ...@@ -1211,7 +1200,6 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr
struct addrinfo *ai; struct addrinfo *ai;
struct addrinfo *ai_cur; struct addrinfo *ai_cur;
struct addrinfo hints; struct addrinfo hints;
RpcConnection *first_connection = NULL;
TRACE("(%p, %s)\n", protseq, endpoint); TRACE("(%p, %s)\n", protseq, endpoint);
...@@ -1331,35 +1319,19 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr ...@@ -1331,35 +1319,19 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr
continue; continue;
} }
tcpc->common.Next = first_connection;
first_connection = &tcpc->common;
/* since IPv4 and IPv6 share the same port space, we only need one
* successful bind to listen for both */
break;
}
freeaddrinfo(ai);
/* if at least one connection was created for an endpoint then
* return success */
if (first_connection)
{
RpcConnection *conn;
/* find last element in list */
for (conn = first_connection; conn->Next; conn = conn->Next)
;
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
conn->Next = protseq->conn; list_add_tail(&protseq->connections, &tcpc->common.protseq_entry);
protseq->conn = first_connection;
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
freeaddrinfo(ai);
/* since IPv4 and IPv6 share the same port space, we only need one
* successful bind to listen for both */
TRACE("listening on %s\n", endpoint); TRACE("listening on %s\n", endpoint);
return RPC_S_OK; return RPC_S_OK;
} }
freeaddrinfo(ai);
ERR("couldn't listen on port %s\n", endpoint); ERR("couldn't listen on port %s\n", endpoint);
return status; return status;
} }
...@@ -1536,12 +1508,10 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void ...@@ -1536,12 +1508,10 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void
/* open and count connections */ /* open and count connections */
*count = 1; *count = 1;
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_tcp, common.protseq_entry)
while (conn)
{ {
if (conn->sock != -1) if (conn->sock != -1)
(*count)++; (*count)++;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
} }
/* make array of connections */ /* make array of connections */
...@@ -1558,8 +1528,7 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void ...@@ -1558,8 +1528,7 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void
objs[0] = sockps->mgr_event; objs[0] = sockps->mgr_event;
*count = 1; *count = 1;
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_tcp, common.protseq_entry)
while (conn)
{ {
if (conn->sock != -1) if (conn->sock != -1)
{ {
...@@ -1572,7 +1541,6 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void ...@@ -1572,7 +1541,6 @@ static void *rpcrt4_protseq_sock_get_wait_array(RpcServerProtseq *protseq, void
(*count)++; (*count)++;
} }
} }
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
} }
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
return objs; return objs;
...@@ -1588,7 +1556,7 @@ static int rpcrt4_protseq_sock_wait_for_new_connection(RpcServerProtseq *protseq ...@@ -1588,7 +1556,7 @@ static int rpcrt4_protseq_sock_wait_for_new_connection(RpcServerProtseq *protseq
HANDLE b_handle; HANDLE b_handle;
HANDLE *objs = wait_array; HANDLE *objs = wait_array;
DWORD res; DWORD res;
RpcConnection *cconn; RpcConnection *cconn = NULL;
RpcConnection_tcp *conn; RpcConnection_tcp *conn;
if (!objs) if (!objs)
...@@ -1605,35 +1573,33 @@ static int rpcrt4_protseq_sock_wait_for_new_connection(RpcServerProtseq *protseq ...@@ -1605,35 +1573,33 @@ static int rpcrt4_protseq_sock_wait_for_new_connection(RpcServerProtseq *protseq
if (res == WAIT_OBJECT_0) if (res == WAIT_OBJECT_0)
return 0; return 0;
else if (res == WAIT_FAILED) if (res == WAIT_FAILED)
{ {
ERR("wait failed with error %d\n", GetLastError()); ERR("wait failed with error %d\n", GetLastError());
return -1; return -1;
} }
else
{
b_handle = objs[res - WAIT_OBJECT_0]; b_handle = objs[res - WAIT_OBJECT_0];
/* find which connection got a RPC */ /* find which connection got a RPC */
EnterCriticalSection(&protseq->cs); EnterCriticalSection(&protseq->cs);
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_tcp, common); LIST_FOR_EACH_ENTRY(conn, &protseq->connections, RpcConnection_tcp, common.protseq_entry)
while (conn) {
if (b_handle == conn->sock_event)
{ {
if (b_handle == conn->sock_event) break;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_tcp, common);
}
cconn = NULL;
if (conn)
RPCRT4_SpawnConnection(&cconn, &conn->common); RPCRT4_SpawnConnection(&cconn, &conn->common);
else break;
ERR("failed to locate connection for handle %p\n", b_handle); }
}
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
if (cconn) if (!cconn)
{ {
ERR("failed to locate connection for handle %p\n", b_handle);
return -1;
}
RPCRT4_new_client(cconn); RPCRT4_new_client(cconn);
return 1; return 1;
}
else return -1;
}
} }
static RPC_STATUS rpcrt4_ncacn_ip_tcp_parse_top_of_tower(const unsigned char *tower_data, static RPC_STATUS rpcrt4_ncacn_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
...@@ -3313,7 +3279,6 @@ RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, ...@@ -3313,7 +3279,6 @@ RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server,
NewConnection = ops->alloc(); NewConnection = ops->alloc();
NewConnection->ref = 1; NewConnection->ref = 1;
NewConnection->Next = NULL;
NewConnection->server_binding = NULL; NewConnection->server_binding = NULL;
NewConnection->server = server; NewConnection->server = server;
NewConnection->ops = ops; NewConnection->ops = ops;
...@@ -3337,6 +3302,7 @@ RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server, ...@@ -3337,6 +3302,7 @@ RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server,
NewConnection->QOS = QOS; NewConnection->QOS = QOS;
list_init(&NewConnection->conn_pool_entry); list_init(&NewConnection->conn_pool_entry);
list_init(&NewConnection->protseq_entry);
NewConnection->async_state = NULL; NewConnection->async_state = NULL;
TRACE("connection: %p\n", NewConnection); TRACE("connection: %p\n", NewConnection);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment