rpcrt4: For TCP endpoints, bind to all the address and ports that getaddrinfo for the machine.

This commit is contained in:
Rob Shearman 2006-11-08 20:47:08 +00:00 committed by Alexandre Julliard
parent 034eaa1cad
commit 0345a578b5
1 changed files with 29 additions and 12 deletions

View File

@ -736,6 +736,7 @@ 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);
@ -761,6 +762,8 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr
for (ai_cur = ai; ai_cur; ai_cur = ai_cur->ai_next) for (ai_cur = ai; ai_cur; ai_cur = ai_cur->ai_next)
{ {
RpcConnection_tcp *tcpc; RpcConnection_tcp *tcpc;
RPC_STATUS create_status;
if (TRACE_ON(rpc)) if (TRACE_ON(rpc))
{ {
char host[256]; char host[256];
@ -790,20 +793,22 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr
status = RPC_S_CANT_CREATE_ENDPOINT; status = RPC_S_CANT_CREATE_ENDPOINT;
continue; continue;
} }
status = RPCRT4_CreateConnection((RpcConnection **)&tcpc, TRUE, create_status = RPCRT4_CreateConnection((RpcConnection **)&tcpc, TRUE,
protseq->Protseq, NULL, endpoint, NULL, protseq->Protseq, NULL,
NULL, NULL); endpoint, NULL, NULL, NULL);
if (status != RPC_S_OK) if (create_status != RPC_S_OK)
{ {
close(sock); close(sock);
status = create_status;
continue; continue;
} }
tcpc->sock = sock;
ret = listen(sock, protseq->MaxCalls); ret = listen(sock, protseq->MaxCalls);
if (ret < 0) if (ret < 0)
{ {
WARN("listen failed: %s\n", strerror(errno)); WARN("listen failed: %s\n", strerror(errno));
close(sock); RPCRT4_DestroyConnection(&tcpc->common);
status = RPC_S_OUT_OF_RESOURCES; status = RPC_S_OUT_OF_RESOURCES;
continue; continue;
} }
@ -815,24 +820,36 @@ static RPC_STATUS rpcrt4_protseq_ncacn_ip_tcp_open_endpoint(RpcServerProtseq *pr
if (ret < 0) if (ret < 0)
{ {
WARN("couldn't make socket non-blocking, error %d\n", ret); WARN("couldn't make socket non-blocking, error %d\n", ret);
close(sock); RPCRT4_DestroyConnection(&tcpc->common);
status = RPC_S_OUT_OF_RESOURCES; status = RPC_S_OUT_OF_RESOURCES;
continue; continue;
} }
tcpc->sock = sock;
tcpc->common.Next = first_connection;
first_connection = &tcpc->common;
}
freeaddrinfo(ai); 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);
tcpc->common.Next = protseq->conn; conn->Next = protseq->conn;
protseq->conn = &tcpc->common; protseq->conn = first_connection;
LeaveCriticalSection(&protseq->cs); LeaveCriticalSection(&protseq->cs);
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;
} }