|
@@ -356,9 +356,11 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
|
|
|
c->releaseRecvBuffer = ServerNetworkLayerReleaseRecvBuffer;
|
|
|
c->state = UA_CONNECTION_OPENING;
|
|
|
struct ConnectionMapping *nm;
|
|
|
- nm = realloc(layer->mappings, sizeof(struct ConnectionMapping)*(layer->mappingsSize+1));
|
|
|
+ nm = realloc(layer->mappings,
|
|
|
+ sizeof(struct ConnectionMapping)*(layer->mappingsSize+1));
|
|
|
if(!nm) {
|
|
|
- UA_LOG_ERROR(layer->logger, UA_LOGCATEGORY_NETWORK, "No memory for a new Connection");
|
|
|
+ UA_LOG_ERROR(layer->logger, UA_LOGCATEGORY_NETWORK,
|
|
|
+ "No memory for a new Connection");
|
|
|
free(c);
|
|
|
return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
}
|
|
@@ -463,7 +465,8 @@ removeClosedConnections(ServerNetworkLayerTCP *layer, UA_Job *js) {
|
|
|
}
|
|
|
|
|
|
static size_t
|
|
|
-ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt16 timeout) {
|
|
|
+ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs,
|
|
|
+ UA_UInt16 timeout) {
|
|
|
/* Every open socket can generate two jobs */
|
|
|
ServerNetworkLayerTCP *layer = nl->handle;
|
|
|
UA_Job *js = malloc(sizeof(UA_Job) * (size_t)((layer->mappingsSize * 2)));
|
|
@@ -608,7 +611,8 @@ UA_ServerNetworkLayerTCP(UA_ConnectionConfig conf, UA_UInt16 port) {
|
|
|
/***************************/
|
|
|
|
|
|
static UA_StatusCode
|
|
|
-ClientNetworkLayerGetBuffer(UA_Connection *connection, size_t length, UA_ByteString *buf) {
|
|
|
+ClientNetworkLayerGetBuffer(UA_Connection *connection, size_t length,
|
|
|
+ UA_ByteString *buf) {
|
|
|
if(length > connection->remoteConf.recvBufferSize)
|
|
|
return UA_STATUSCODE_BADCOMMUNICATIONERROR;
|
|
|
if(connection->state == UA_CONNECTION_CLOSED)
|
|
@@ -668,7 +672,8 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf, const char *endpointUrl,
|
|
|
"Server url is invalid: %s", endpointUrl);
|
|
|
else if(parse_retval == UA_STATUSCODE_BADATTRIBUTEIDINVALID)
|
|
|
UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
|
|
- "Server url does not begin with 'opc.tcp://' '%s'", endpointUrl);
|
|
|
+ "Server url does not begin with 'opc.tcp://' '%s'",
|
|
|
+ endpointUrl);
|
|
|
return connection;
|
|
|
}
|
|
|
|
|
@@ -697,13 +702,15 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf, const char *endpointUrl,
|
|
|
}
|
|
|
|
|
|
/* Get a socket */
|
|
|
- SOCKET clientsockfd = socket(server->ai_family, server->ai_socktype, server->ai_protocol);
|
|
|
+ SOCKET clientsockfd = socket(server->ai_family, server->ai_socktype,
|
|
|
+ server->ai_protocol);
|
|
|
#ifdef _WIN32
|
|
|
if(clientsockfd == INVALID_SOCKET) {
|
|
|
#else
|
|
|
if(clientsockfd < 0) {
|
|
|
#endif
|
|
|
- UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK, "Could not create client socket");
|
|
|
+ UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
|
|
+ "Could not create client socket");
|
|
|
freeaddrinfo(server);
|
|
|
return connection;
|
|
|
}
|
|
@@ -716,24 +723,32 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf, const char *endpointUrl,
|
|
|
ClientNetworkLayerClose(&connection);
|
|
|
#ifdef _WIN32
|
|
|
wchar_t *s = NULL;
|
|
|
- FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
+ FORMAT_MESSAGE_FROM_SYSTEM |
|
|
|
+ FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
NULL, WSAGetLastError(),
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
(LPWSTR)&s, 0, NULL);
|
|
|
- UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK, "Connection to %s failed. Error: %d: %S", endpointUrl, WSAGetLastError(), s);
|
|
|
+ UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
|
|
+ "Connection to %s failed. Error: %d: %S",
|
|
|
+ endpointUrl, WSAGetLastError(), s);
|
|
|
LocalFree(s);
|
|
|
#else
|
|
|
- UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK, "Connection to %s failed. Error: %d: %s", endpointUrl, errno, strerror(errno));
|
|
|
+ UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
|
|
+ "Connection to %s failed. Error: %d: %s",
|
|
|
+ endpointUrl, errno, strerror(errno));
|
|
|
#endif
|
|
|
return connection;
|
|
|
}
|
|
|
|
|
|
#ifdef SO_NOSIGPIPE
|
|
|
int val = 1;
|
|
|
- if(setsockopt(connection.sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&val, sizeof(val)) < 0) {
|
|
|
- UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK, "Couldn't set SO_NOSIGPIPE");
|
|
|
- return connection;
|
|
|
- }
|
|
|
+ int sso_result = setsockopt(connection.sockfd,
|
|
|
+ SOL_SOCKET, SO_NOSIGPIPE,
|
|
|
+ (void*)&val, sizeof(val));
|
|
|
+ if(sso_result < 0)
|
|
|
+ UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
|
|
|
+ "Couldn't set SO_NOSIGPIPE");
|
|
|
#endif
|
|
|
|
|
|
return connection;
|