|
@@ -109,6 +109,8 @@
|
|
# define AGAIN EAGAIN
|
|
# define AGAIN EAGAIN
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+#include "ua_log_socket_error.h"
|
|
|
|
+
|
|
/****************************/
|
|
/****************************/
|
|
/* Generic Socket Functions */
|
|
/* Generic Socket Functions */
|
|
/****************************/
|
|
/****************************/
|
|
@@ -290,9 +292,10 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
|
|
int dummy = 1;
|
|
int dummy = 1;
|
|
if(setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY,
|
|
if(setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY,
|
|
(const char *)&dummy, sizeof(dummy)) < 0) {
|
|
(const char *)&dummy, sizeof(dummy)) < 0) {
|
|
- UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Cannot set socket option TCP_NODELAY. Error: %s",
|
|
|
|
- strerror(errno));
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Cannot set socket option TCP_NODELAY. Error: %s",
|
|
|
|
+ errno_str));
|
|
return UA_STATUSCODE_BADUNEXPECTEDERROR;
|
|
return UA_STATUSCODE_BADUNEXPECTEDERROR;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -307,10 +310,10 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
|
|
"Connection %i | New connection over TCP from %s",
|
|
"Connection %i | New connection over TCP from %s",
|
|
(int)newsockfd, remote_name);
|
|
(int)newsockfd, remote_name);
|
|
} else {
|
|
} else {
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Connection %i | New connection over TCP, "
|
|
|
|
- "getnameinfo failed with errno %i",
|
|
|
|
- (int)newsockfd, errno__);
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Connection %i | New connection over TCP, "
|
|
|
|
+ "getnameinfo failed with error: %s",
|
|
|
|
+ (int)newsockfd, errno_str));
|
|
}
|
|
}
|
|
|
|
|
|
/* Allocate and initialize the connection */
|
|
/* Allocate and initialize the connection */
|
|
@@ -382,16 +385,18 @@ addServerSocket(ServerNetworkLayerTCP *layer, struct addrinfo *ai) {
|
|
|
|
|
|
/* Bind socket to address */
|
|
/* Bind socket to address */
|
|
if(bind(newsock, ai->ai_addr, WIN32_INT ai->ai_addrlen) < 0) {
|
|
if(bind(newsock, ai->ai_addr, WIN32_INT ai->ai_addrlen) < 0) {
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Error binding a server socket: %i", errno__);
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Error binding a server socket: %s", errno_str));
|
|
CLOSESOCKET(newsock);
|
|
CLOSESOCKET(newsock);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
/* Start listening */
|
|
/* Start listening */
|
|
if(listen(newsock, MAXBACKLOG) < 0) {
|
|
if(listen(newsock, MAXBACKLOG) < 0) {
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Error listening on server socket");
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Error listening on server socket: %s", errno_str));
|
|
CLOSESOCKET(newsock);
|
|
CLOSESOCKET(newsock);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -501,14 +506,20 @@ ServerNetworkLayerTCP_listen(UA_ServerNetworkLayer *nl, UA_Server *server,
|
|
/* Every open socket can generate two jobs */
|
|
/* Every open socket can generate two jobs */
|
|
ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
|
|
ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
|
|
|
|
|
|
|
|
+ if (layer->serverSocketsSize == 0)
|
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
|
+
|
|
/* Listen on open sockets (including the server) */
|
|
/* Listen on open sockets (including the server) */
|
|
fd_set fdset, errset;
|
|
fd_set fdset, errset;
|
|
UA_Int32 highestfd = setFDSet(layer, &fdset);
|
|
UA_Int32 highestfd = setFDSet(layer, &fdset);
|
|
setFDSet(layer, &errset);
|
|
setFDSet(layer, &errset);
|
|
struct timeval tmptv = {0, timeout * 1000};
|
|
struct timeval tmptv = {0, timeout * 1000};
|
|
if (select(highestfd+1, &fdset, NULL, &errset, &tmptv) < 0) {
|
|
if (select(highestfd+1, &fdset, NULL, &errset, &tmptv) < 0) {
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Socket select failed with %s", strerror(errno));
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Socket select failed with %s", errno_str));
|
|
|
|
+ // we will retry, so do not return bad
|
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
}
|
|
}
|
|
|
|
|
|
/* Accept new connections via the server sockets */
|
|
/* Accept new connections via the server sockets */
|
|
@@ -732,8 +743,9 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
|
|
#else
|
|
#else
|
|
if(clientsockfd < 0) {
|
|
if(clientsockfd < 0) {
|
|
#endif
|
|
#endif
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Could not create client socket: %s", strerror(errno__));
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Could not create client socket: %s", errno_str));
|
|
freeaddrinfo(server);
|
|
freeaddrinfo(server);
|
|
return connection;
|
|
return connection;
|
|
}
|
|
}
|
|
@@ -756,9 +768,10 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
|
|
|
|
|
|
if ((error == -1) && (errno__ != ERR_CONNECTION_PROGRESS)) {
|
|
if ((error == -1) && (errno__ != ERR_CONNECTION_PROGRESS)) {
|
|
ClientNetworkLayerTCP_close(&connection);
|
|
ClientNetworkLayerTCP_close(&connection);
|
|
- UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
- "Connection to %s failed with error: %s",
|
|
|
|
- endpointUrl, strerror(errno__));
|
|
|
|
|
|
+ UA_LOG_SOCKET_ERRNO_WRAP(
|
|
|
|
+ UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_NETWORK,
|
|
|
|
+ "Connection to %s failed with error: %s",
|
|
|
|
+ endpointUrl, errno_str));
|
|
freeaddrinfo(server);
|
|
freeaddrinfo(server);
|
|
return connection;
|
|
return connection;
|
|
}
|
|
}
|