|
@@ -47,7 +47,7 @@ static UA_StatusCode socket_write(UA_Connection *connection, const UA_ByteString
|
|
|
do {
|
|
|
#ifdef _WIN32
|
|
|
n = send((SOCKET)connection->sockfd, (const char*)buf->data, buf->length, 0);
|
|
|
- if(n != 0 &&WSAGetLastError() != WSAEINTR)
|
|
|
+ if(n < 0 && WSAGetLastError() != WSAEINTR)
|
|
|
return UA_STATUSCODE_BADCONNECTIONCLOSED;
|
|
|
#else
|
|
|
n = send(connection->sockfd, (const char*)buf->data, buf->length, MSG_NOSIGNAL);
|
|
@@ -62,19 +62,28 @@ static UA_StatusCode socket_write(UA_Connection *connection, const UA_ByteString
|
|
|
|
|
|
static UA_StatusCode socket_recv(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout) {
|
|
|
UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
- if(response->data == UA_NULL)
|
|
|
+ if(response->data == UA_NULL)
|
|
|
retval = connection->getBuffer(connection, response, connection->localConf.recvBufferSize);
|
|
|
if(retval != UA_STATUSCODE_GOOD)
|
|
|
return retval;
|
|
|
struct timeval tmptv = {0, timeout * 1000};
|
|
|
setsockopt(connection->sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tmptv, sizeof(struct timeval));
|
|
|
int ret = recv(connection->sockfd, (char*)response->data, response->length, 0);
|
|
|
- if(ret <= -1) {
|
|
|
- if(errno == EAGAIN) {
|
|
|
+ if(ret == 0) {
|
|
|
+ connection->releaseBuffer(connection, response);
|
|
|
+ connection->close(connection);
|
|
|
+ return UA_STATUSCODE_BADCONNECTIONCLOSED;
|
|
|
+ } else if(ret < 0) {
|
|
|
+#ifdef _WIN32
|
|
|
+ if(WSAGetLastError() == WSAEINTR || WSAGetLastError() == WSAEWOULDBLOCK) {
|
|
|
+#else
|
|
|
+ if (errno == EAGAIN) {
|
|
|
+#endif
|
|
|
return UA_STATUSCODE_BADCOMMUNICATIONERROR;
|
|
|
}
|
|
|
connection->releaseBuffer(connection, response);
|
|
|
- return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
+ connection->close(connection);
|
|
|
+ return UA_STATUSCODE_BADCONNECTIONCLOSED;
|
|
|
}
|
|
|
response->length = ret;
|
|
|
*response = UA_Connection_completeMessages(connection, *response);
|
|
@@ -518,7 +527,7 @@ UA_Connection ClientNetworkLayerTCP_connect(char *endpointUrl, UA_Logger *logger
|
|
|
return connection;
|
|
|
}
|
|
|
connection.state = UA_CONNECTION_OPENING;
|
|
|
- socket_set_nonblocking(connection.sockfd);
|
|
|
+ //socket_set_nonblocking(connection.sockfd);
|
|
|
connection.write = socket_write;
|
|
|
connection.recv = socket_recv;
|
|
|
connection.close = socket_close;
|