Commit 35435a96 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Place socket error description at the end of the logged messages.

Socket error descriptions on Windows can be quite long (e.g. > 128 chars) and
include punctuation, so include at the end of logged socket error messages.

If FormatMessage() fails on Windows (in socket_strerror()) return the
GetLastError() value in the error description.
parent 2ec90d7a
......@@ -153,9 +153,9 @@ BOOL DLLCALL xpms_add(struct xpms_set *xpms_set, int domain, int type,
if(type != SOCK_DGRAM) {
if(listen(xpms_set->socks[xpms_set->sock_count].sock, SOMAXCONN)==-1) {
if(xpms_set->lprintf)
xpms_set->lprintf(LOG_WARNING, "%04d !%s ERROR %d (%s) listening on port %d"
xpms_set->lprintf(LOG_WARNING, "%04d !%s ERROR %d listening on port %d: %s"
,xpms_set->socks[xpms_set->sock_count].sock, prot, ERROR_VALUE
,socket_strerror(socket_errno,err,sizeof(err)), port);
,port, socket_strerror(socket_errno,err,sizeof(err)));
closesocket(xpms_set->socks[xpms_set->sock_count].sock);
FREE_AND_NULL(xpms_set->socks[xpms_set->sock_count].address);
FREE_AND_NULL(xpms_set->socks[xpms_set->sock_count].prot);
......
......@@ -352,7 +352,7 @@ int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
,int (*lprintf)(int level, const char *fmt, ...))
{
char port_str[128];
char err[128];
char err[256];
int result=-1;
uint i;
......@@ -365,7 +365,7 @@ int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
break;
if(lprintf!=NULL)
lprintf(i<retries ? LOG_WARNING:LOG_CRIT
,"%04d !ERROR %d (%s) binding %s socket%s", s, ERROR_VALUE, socket_strerror(socket_errno, err, sizeof(err)), prot, port_str);
,"%04d !ERROR %d binding %s socket%s: %s", s, ERROR_VALUE, prot, port_str, socket_strerror(socket_errno, err, sizeof(err)));
if(i<retries) {
if(lprintf!=NULL)
lprintf(LOG_WARNING,"%04d Will retry in %u seconds (%u of %u)"
......@@ -509,13 +509,14 @@ DLLEXPORT char* socket_strerror(int error_number, char* buf, size_t buflen)
buf[buflen - 1] = 0;
if(error_number > 0 && error_number < WSABASEERR)
error_number += WSABASEERR;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, // dwFlags
if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, // dwFlags
NULL, // lpSource
error_number, // dwMessageId
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // dwLanguageId
buf,
buflen,
NULL);
NULL))
safe_snprintf(buf, buflen, "Error %d getting error description", GetLastError());
truncsp(buf);
return buf;
#else
......
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