Commit 5c4caa5a authored by rswindell's avatar rswindell
Browse files

Provide detailed socket error descriptions using new socket_strerror() function.

parent 55ee3a25
......@@ -264,7 +264,7 @@ static int close_socket(SOCKET sock)
if(startup!=NULL && startup->socket_open!=NULL)
startup->socket_open(startup->cbdata,FALSE);
if(result!=0)
lprintf(LOG_WARNING,"%04d !ERROR %d closing socket",sock, ERROR_VALUE);
lprintf(LOG_WARNING,"%04d !ERROR %d (%s) closing socket",sock, ERROR_VALUE, socket_strerror(socket_errno));
return(result);
}
......@@ -1650,7 +1650,7 @@ static void cleanup(int code)
#ifdef _WINSOCKAPI_
if(WSAInitialized) {
if(WSACleanup()!=0)
lprintf(LOG_ERR,"0000 !WSACleanup ERROR %d",ERROR_VALUE);
lprintf(LOG_ERR,"0000 !WSACleanup ERROR %d (%s)",ERROR_VALUE, socket_strerror(socket_errno));
WSAInitialized = FALSE;
}
#endif
......@@ -1696,14 +1696,15 @@ void service_udp_sock_cb(SOCKET sock, void *cbdata)
/* We need to set the REUSE ADDRESS socket option */
optval=TRUE;
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&optval,sizeof(optval))!=0) {
lprintf(LOG_ERR,"%04d !ERROR %d setting %s socket option"
,sock, ERROR_VALUE, serv->protocol);
lprintf(LOG_ERR,"%04d !ERROR %d (%s) setting %s socket option"
,sock, ERROR_VALUE, socket_strerror(socket_errno), serv->protocol);
close_socket(sock);
return;
}
#ifdef BSD
if(setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&optval,sizeof(optval))!=0) {
lprintf(LOG_ERR,"%04d !ERROR %d setting %s socket option",sock, ERROR_VALUE, serv->protocol);
lprintf(LOG_ERR,"%04d !ERROR %d (%s) setting %s socket option"
,sock, ERROR_VALUE, socket_strerror(socket_errno), serv->protocol);
close_socket(sock);
return;
}
......@@ -2005,7 +2006,7 @@ void DLLCALL services_thread(void* arg)
else if(ERROR_VALUE == ENOTSOCK)
lprintf(LOG_NOTICE,"0000 Services sockets closed");
else
lprintf(LOG_WARNING,"0000 !ERROR %d selecting sockets",ERROR_VALUE);
lprintf(LOG_WARNING,"0000 !ERROR %d (%s) selecting sockets",ERROR_VALUE, socket_strerror(socket_errno));
continue;
}
......@@ -2036,16 +2037,16 @@ void DLLCALL services_thread(void* arg)
,&client_addr.addr, &client_addr_len);
if(udp_len<1) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d recvfrom failed"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) recvfrom failed"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
continue;
}
if((client_socket = open_socket(service[i].set->socks[j].domain, SOCK_DGRAM, &service[i]))
==INVALID_SOCKET) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d opening socket"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) opening socket"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
continue;
}
......@@ -2057,8 +2058,8 @@ void DLLCALL services_thread(void* arg)
if(setsockopt(client_socket,SOL_SOCKET,SO_REUSEADDR
,(char*)&optval,sizeof(optval))!=0) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d setting socket option"
,client_socket, service[i].protocol, ERROR_VALUE);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) setting socket option"
,client_socket, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
close_socket(client_socket);
continue;
}
......@@ -2066,8 +2067,8 @@ void DLLCALL services_thread(void* arg)
if(setsockopt(client_socket,SOL_SOCKET,SO_REUSEPORT
,(char*)&optval,sizeof(optval))!=0) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d setting socket option"
,client_socket, service[i].protocol, ERROR_VALUE);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) setting socket option"
,client_socket, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
close_socket(client_socket);
continue;
}
......@@ -2078,16 +2079,16 @@ void DLLCALL services_thread(void* arg)
result=bind(client_socket, &addr.addr, addr_len);
if(result==SOCKET_ERROR) {
/* Failed to re-bind to same port number, use user port */
lprintf(LOG_NOTICE,"%04d %s ERROR %d re-binding socket to port %u failed, "
lprintf(LOG_NOTICE,"%04d %s ERROR %d (%s) re-binding socket to port %u failed, "
"using user port"
,client_socket, service[i].protocol, ERROR_VALUE, service[i].port);
,client_socket, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno), service[i].port);
inet_setaddrport(&addr, 0);
result=bind(client_socket, (struct sockaddr *) &addr, addr_len);
}
if(result!=0) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d re-binding socket to port %u"
,client_socket, service[i].protocol, ERROR_VALUE, service[i].port);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) re-binding socket to port %u"
,client_socket, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno), service[i].port);
close_socket(client_socket);
continue;
}
......@@ -2096,8 +2097,8 @@ void DLLCALL services_thread(void* arg)
if(connect(client_socket
,(struct sockaddr *)&client_addr, client_addr_len)!=0) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_ERR,"%04d %s !ERROR %d connect failed"
,client_socket, service[i].protocol, ERROR_VALUE);
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) connect failed"
,client_socket, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
close_socket(client_socket);
continue;
}
......@@ -2110,8 +2111,8 @@ void DLLCALL services_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s socket closed while listening"
,service[i].set->socks[j].sock, service[i].protocol);
else
lprintf(LOG_WARNING,"%04d %s !ERROR %d accepting connection"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE);
lprintf(LOG_WARNING,"%04d %s !ERROR %d (%s) accepting connection"
,service[i].set->socks[j].sock, service[i].protocol, ERROR_VALUE, socket_strerror(socket_errno));
#ifdef _WIN32
if(WSAGetLastError()==WSAENOBUFS) /* recycle (re-init WinSock) on this error */
break;
......
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