Commit e796417d authored by Patrick Bellot's avatar Patrick Bellot
Browse files

linux64_ingocs2 is ready

parent 7a5863ab
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
<option id="gnu.cpp.compiler.option.include.files.1016416781" name="Include files (-include)" superClass="gnu.cpp.compiler.option.include.files" useByScannerDiscovery="false"/> <option id="gnu.cpp.compiler.option.include.files.1016416781" name="Include files (-include)" superClass="gnu.cpp.compiler.option.include.files" useByScannerDiscovery="false"/>
<option id="gnu.cpp.compiler.option.include.paths.780294207" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option id="gnu.cpp.compiler.option.include.paths.780294207" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/s2opc_stack}/include_linux&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/s2opc_stack}/include_linux&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/opcua-client}&quot;"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1464493100" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1464493100" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
......
...@@ -98,6 +98,7 @@ public: ...@@ -98,6 +98,7 @@ public:
} }
length = _length ; length = _length ;
array = _array ; array = _array ;
NOT_USED(takeItForYou) ;
} }
ByteString(uint32_t value) ByteString(uint32_t value)
......
...@@ -95,6 +95,7 @@ public: ...@@ -95,6 +95,7 @@ public:
: BaseDataType() : BaseDataType()
{ {
str = _str ; str = _str ;
NOT_USED(takeItForYou) ;
} }
String(const char * const _str) String(const char * const _str)
......
...@@ -157,6 +157,8 @@ MYDLL void ClientService_ServiceFault( ...@@ -157,6 +157,8 @@ MYDLL void ClientService_ServiceFault(
OpcUa_ServiceFault_Clear(response) ; OpcUa_ServiceFault_Clear(response) ;
free(responseHeader) ; free(responseHeader) ;
free(response) ; free(response) ;
NOT_USED(scConnectionId) ;
} }
...@@ -199,6 +201,8 @@ MYDLL void ClientService_CreateSession( ...@@ -199,6 +201,8 @@ MYDLL void ClientService_CreateSession(
OpcUa_CreateSessionResponse_Clear(response) ; OpcUa_CreateSessionResponse_Clear(response) ;
free(responseHeader) ; free(responseHeader) ;
free(response) ; free(response) ;
NOT_USED(scConnectionId) ;
} }
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.config.gnu.so.debug.564995990" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1968678984014786712" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.so.release.573252170" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1968678984014786712" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
...@@ -17,30 +17,22 @@ ...@@ -17,30 +17,22 @@
#include "sopc_raw_sockets.h" #include "sopc_raw_sockets.h"
#include "sopc_threads.h" #include <errno.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <string.h>
#include <unistd.h>
static WSADATA wsaData; #include "sopc_threads.h"
bool Socket_Network_Initialize() bool Socket_Network_Initialize()
{ {
bool status = true; return true;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (result != 0)
{
status = false;
}
return status;
} }
bool Socket_Network_Clear() bool Socket_Network_Clear()
{ {
bool status = true; return true;
int result = WSACleanup();
if (result != 0)
{
status = false;
}
return status;
} }
SOPC_ReturnStatus Socket_AddrInfo_Get(char* hostname, char* port, Socket_AddressInfo** addrs) SOPC_ReturnStatus Socket_AddrInfo_Get(char* hostname, char* port, Socket_AddressInfo** addrs)
...@@ -78,7 +70,7 @@ Socket_AddressInfo* Socket_AddrInfo_IterNext(Socket_AddressInfo* addr) ...@@ -78,7 +70,7 @@ Socket_AddressInfo* Socket_AddrInfo_IterNext(Socket_AddressInfo* addr)
uint8_t Socket_AddrInfo_IsIPV6(Socket_AddressInfo* addr) uint8_t Socket_AddrInfo_IsIPV6(Socket_AddressInfo* addr)
{ {
return addr->ai_family == AF_INET6; return addr->ai_family == PF_INET6;
} }
void Socket_AddrInfoDelete(Socket_AddressInfo** addrs) void Socket_AddrInfoDelete(Socket_AddressInfo** addrs)
...@@ -99,32 +91,33 @@ SOPC_ReturnStatus Socket_Configure(Socket sock, bool setNonBlocking) ...@@ -99,32 +91,33 @@ SOPC_ReturnStatus Socket_Configure(Socket sock, bool setNonBlocking)
{ {
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
const int trueInt = true; const int trueInt = true;
u_long ltrue = 1;
int setOptStatus = -1; int setOptStatus = -1;
if (sock != SOPC_INVALID_SOCKET) if (sock != SOPC_INVALID_SOCKET)
{ {
status = SOPC_STATUS_OK; status = SOPC_STATUS_OK;
// Deactivate Nagle's algorithm since we always write a TCP UA binary message (and not just few bytes) // Deactivate Nagle's algorithm since we always write a TCP UA binary message (and not just few bytes)
setOptStatus = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const void*) &trueInt, sizeof(int)); setOptStatus = setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const void*) &trueInt, sizeof(int));
/* /*
if(setOptStatus != SOCKET_ERROR){ if(setOptStatus != -1){
int rcvbufsize = UINT16_MAX; int rcvbufsize = UINT16_MAX;
setOptStatus = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char*) &rcvbufsize, sizeof(int)); setOptStatus = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, sizeof(int));
} }
if(setOptStatus != SOCKET_ERROR){ if(setOptStatus != -1){
int sndbufsize = UINT16_MAX; int sndbufsize = UINT16_MAX;
setOptStatus = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char*) &sndbufsize, sizeof(int)); setOptStatus = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &sndbufsize, sizeof(int));
} }
*/ */
if (setOptStatus != SOCKET_ERROR && setNonBlocking != false) if (setOptStatus != -1 && setNonBlocking != false)
{ {
setOptStatus = ioctlsocket(sock, FIONBIO, &ltrue); // True => Non blocking setOptStatus = fcntl(sock, F_SETFL, O_NONBLOCK);
} }
if (setOptStatus == SOCKET_ERROR) if (setOptStatus < 0)
{ {
status = SOPC_STATUS_NOK; status = SOPC_STATUS_NOK;
} }
...@@ -137,33 +130,38 @@ SOPC_ReturnStatus Socket_CreateNew(Socket_AddressInfo* addr, bool setReuseAddr, ...@@ -137,33 +130,38 @@ SOPC_ReturnStatus Socket_CreateNew(Socket_AddressInfo* addr, bool setReuseAddr,
{ {
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
const int trueInt = true; const int trueInt = true;
int setOptStatus = SOCKET_ERROR; int setOptStatus = -1;
if (addr != NULL && sock != NULL) if (addr != NULL && sock != NULL)
{ {
status = SOPC_STATUS_OK;
*sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); *sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (*sock != SOPC_INVALID_SOCKET) if (*sock != SOPC_INVALID_SOCKET)
{ {
status = Socket_Configure(*sock, setNonBlocking); status = Socket_Configure(*sock, setNonBlocking);
}
else
{
status = SOPC_STATUS_NOK;
}
if (status == SOPC_STATUS_OK) if (SOPC_STATUS_OK == status)
{ {
setOptStatus = 0; setOptStatus = 0;
} // else SOCKET_ERROR due to init } // else -1 due to init
if (setOptStatus != SOCKET_ERROR && setReuseAddr != false) if (setOptStatus != -1 && setReuseAddr != false)
{ {
setOptStatus = setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, (const void*) &trueInt, sizeof(int)); setOptStatus = setsockopt(*sock, SOL_SOCKET, SO_REUSEADDR, (const void*) &trueInt, sizeof(int));
} }
// Enforce IPV6 sockets can be used for IPV4 connections (if socket is IPV6) // Enforce IPV6 sockets can be used for IPV4 connections (if socket is IPV6)
if (setOptStatus != SOCKET_ERROR && addr->ai_family == AF_INET6) if (setOptStatus != -1 && addr->ai_family == AF_INET6)
{ {
const int falseInt = false; const int falseInt = false;
setOptStatus = setsockopt(*sock, IPPROTO_IPV6, IPV6_V6ONLY, (const void*) &falseInt, sizeof(int)); setOptStatus = setsockopt(*sock, IPPROTO_IPV6, IPV6_V6ONLY, (const void*) &falseInt, sizeof(int));
}
} }
if (setOptStatus == SOCKET_ERROR)
if (setOptStatus < 0)
{ {
status = SOPC_STATUS_NOK; status = SOPC_STATUS_NOK;
} }
...@@ -177,13 +175,13 @@ SOPC_ReturnStatus Socket_Listen(Socket sock, Socket_AddressInfo* addr) ...@@ -177,13 +175,13 @@ SOPC_ReturnStatus Socket_Listen(Socket sock, Socket_AddressInfo* addr)
int bindListenStatus = -1; int bindListenStatus = -1;
if (addr != NULL) if (addr != NULL)
{ {
bindListenStatus = bind(sock, addr->ai_addr, (int) addr->ai_addrlen); bindListenStatus = bind(sock, addr->ai_addr, addr->ai_addrlen);
if (bindListenStatus != SOCKET_ERROR) if (bindListenStatus != -1)
{ {
bindListenStatus = listen(sock, SOMAXCONN); bindListenStatus = listen(sock, SOMAXCONN);
} }
} }
if (bindListenStatus != SOCKET_ERROR) if (bindListenStatus != -1)
{ {
status = SOPC_STATUS_OK; status = SOPC_STATUS_OK;
} }
...@@ -193,9 +191,16 @@ SOPC_ReturnStatus Socket_Listen(Socket sock, Socket_AddressInfo* addr) ...@@ -193,9 +191,16 @@ SOPC_ReturnStatus Socket_Listen(Socket sock, Socket_AddressInfo* addr)
SOPC_ReturnStatus Socket_Accept(Socket listeningSock, bool setNonBlocking, Socket* acceptedSock) SOPC_ReturnStatus Socket_Accept(Socket listeningSock, bool setNonBlocking, Socket* acceptedSock)
{ {
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
if (listeningSock != SOPC_INVALID_SOCKET && acceptedSock != NULL) struct sockaddr remoteAddr;
socklen_t addrLen = 0;
if (listeningSock != -1 && acceptedSock != NULL)
{ {
*acceptedSock = accept(listeningSock, NULL, NULL); *acceptedSock = accept(listeningSock, &remoteAddr, &addrLen);
// printf("selectserver: new connection from %s on socket %d\n",
// inet_ntop(remoteaddr.sa_family,
// get_in_addr((struct sockaddr*)&remoteaddr),
// remoteIP, INET6_ADDRSTRLEN),
// acceptSock);
if (*acceptedSock != SOPC_INVALID_SOCKET) if (*acceptedSock != SOPC_INVALID_SOCKET)
{ {
status = Socket_Configure(*acceptedSock, setNonBlocking); status = Socket_Configure(*acceptedSock, setNonBlocking);
...@@ -208,14 +213,12 @@ SOPC_ReturnStatus Socket_Connect(Socket sock, Socket_AddressInfo* addr) ...@@ -208,14 +213,12 @@ SOPC_ReturnStatus Socket_Connect(Socket sock, Socket_AddressInfo* addr)
{ {
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
int connectStatus = -1; int connectStatus = -1;
int wsaError = 0; if (addr != NULL && sock != -1)
if (addr != NULL && sock != SOPC_INVALID_SOCKET)
{ {
connectStatus = connect(sock, addr->ai_addr, (int) addr->ai_addrlen); connectStatus = connect(sock, addr->ai_addr, addr->ai_addrlen);
if (connectStatus == SOCKET_ERROR) if (connectStatus < 0)
{ {
wsaError = WSAGetLastError(); if (errno == EINPROGRESS)
if (wsaError == WSAEWOULDBLOCK)
{ {
// Non blocking connection started // Non blocking connection started
connectStatus = 0; connectStatus = 0;
...@@ -234,9 +237,9 @@ SOPC_ReturnStatus Socket_CheckAckConnect(Socket sock) ...@@ -234,9 +237,9 @@ SOPC_ReturnStatus Socket_CheckAckConnect(Socket sock)
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
int error = 0; int error = 0;
socklen_t len = sizeof(int); socklen_t len = sizeof(int);
if (sock != SOPC_INVALID_SOCKET) if (sock != -1)
{ {
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (char*) &error, &len) < 0 || error != 0) if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error != 0)
{ {
status = SOPC_STATUS_NOK; status = SOPC_STATUS_NOK;
} }
...@@ -250,17 +253,21 @@ SOPC_ReturnStatus Socket_CheckAckConnect(Socket sock) ...@@ -250,17 +253,21 @@ SOPC_ReturnStatus Socket_CheckAckConnect(Socket sock)
void SocketSet_Add(Socket sock, SocketSet* sockSet) void SocketSet_Add(Socket sock, SocketSet* sockSet)
{ {
if (sock != SOPC_INVALID_SOCKET && sockSet != NULL) if (sock != -1 && sockSet != NULL)
{ {
FD_SET(sock, sockSet); FD_SET(sock, &sockSet->set);
if (sock > sockSet->fdmax)
{
sockSet->fdmax = sock;
}
} }
} }
bool SocketSet_IsPresent(Socket sock, SocketSet* sockSet) bool SocketSet_IsPresent(Socket sock, SocketSet* sockSet)
{ {
if (sock != SOPC_INVALID_SOCKET && sockSet != NULL) if (sock != -1 && sockSet != NULL)
{ {
if (false == FD_ISSET(sock, sockSet)) if (false == FD_ISSET(sock, &sockSet->set))
{ {
return false; return false;
} }
...@@ -276,16 +283,29 @@ void SocketSet_Clear(SocketSet* sockSet) ...@@ -276,16 +283,29 @@ void SocketSet_Clear(SocketSet* sockSet)
{ {
if (sockSet != NULL) if (sockSet != NULL)
{ {
FD_ZERO(sockSet); FD_ZERO(&sockSet->set);
sockSet->fdmax = 0;
} }
} }
int32_t Socket_WaitSocketEvents(SocketSet* readSet, SocketSet* writeSet, SocketSet* exceptSet, uint32_t waitMs) int32_t Socket_WaitSocketEvents(SocketSet* readSet, SocketSet* writeSet, SocketSet* exceptSet, uint32_t waitMs)
{ {
int32_t nbReady = 0; int32_t nbReady = 0;
const int ignored = 0; // ignored in winsocks
struct timeval timeout; struct timeval timeout;
struct timeval* val; struct timeval* val;
int fdmax = 0;
if (readSet->fdmax > writeSet->fdmax)
{
fdmax = readSet->fdmax;
}
else
{
fdmax = writeSet->fdmax;
}
if (exceptSet->fdmax > fdmax)
{
fdmax = exceptSet->fdmax;
}
if (waitMs == 0) if (waitMs == 0)
{ {
...@@ -297,8 +317,8 @@ int32_t Socket_WaitSocketEvents(SocketSet* readSet, SocketSet* writeSet, SocketS ...@@ -297,8 +317,8 @@ int32_t Socket_WaitSocketEvents(SocketSet* readSet, SocketSet* writeSet, SocketS
timeout.tv_usec = 1000 * (waitMs % 1000); timeout.tv_usec = 1000 * (waitMs % 1000);
val = &timeout; val = &timeout;
} }
nbReady = select(ignored, readSet, writeSet, exceptSet, val); nbReady = select(fdmax + 1, &readSet->set, &writeSet->set, &exceptSet->set, val);
if (nbReady == SOCKET_ERROR || nbReady > INT32_MAX || nbReady < INT32_MIN) if (nbReady > INT32_MAX || nbReady < INT32_MIN)
return -1; return -1;
return (int32_t) nbReady; return (int32_t) nbReady;
} }
...@@ -307,26 +327,24 @@ SOPC_ReturnStatus Socket_Write(Socket sock, uint8_t* data, uint32_t count, uint3 ...@@ -307,26 +327,24 @@ SOPC_ReturnStatus Socket_Write(Socket sock, uint8_t* data, uint32_t count, uint3
{ {
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
int res = 0; int res = 0;
int wsaError = 0;
if (sock != SOPC_INVALID_SOCKET && data != NULL && count <= INT32_MAX && sentBytes != NULL) if (sock != SOPC_INVALID_SOCKET && data != NULL && count <= INT32_MAX && sentBytes != NULL)
{ {
status = SOPC_STATUS_NOK; status = SOPC_STATUS_NOK;
res = send(sock, (char*) data, count, 0); res = send(sock, data, count, 0);
*sentBytes = (uint32_t) res; *sentBytes = (uint32_t) res;
if (res == SOCKET_ERROR) if (res >= 0 && (uint32_t) res == count)
{
status = SOPC_STATUS_OK;
}
else
{ {
wsaError = WSAGetLastError();
// ERROR CASE // ERROR CASE
if (wsaError == WSAEWOULDBLOCK) if (errno == EAGAIN || errno == EWOULDBLOCK)
{ {
// Try again in those cases // Try again in those cases
status = SOPC_STATUS_WOULD_BLOCK; status = SOPC_STATUS_WOULD_BLOCK;
} // keep SOPC_STATUS_NOK } // else: error, keep SOPC_STATUS_NOK
} }
else if (res >= 0 && (uint32_t) res == count)
{
status = SOPC_STATUS_OK;
} // else SOPC_STATUS_NOK
} }
return status; return status;
} }
...@@ -336,7 +354,14 @@ SOPC_ReturnStatus Socket_Read(Socket sock, uint8_t* data, uint32_t dataSize, int ...@@ -336,7 +354,14 @@ SOPC_ReturnStatus Socket_Read(Socket sock, uint8_t* data, uint32_t dataSize, int
SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS; SOPC_ReturnStatus status = SOPC_STATUS_INVALID_PARAMETERS;
if (sock != SOPC_INVALID_SOCKET && data != NULL && dataSize > 0) if (sock != SOPC_INVALID_SOCKET && data != NULL && dataSize > 0)
{ {
*readCount = recv(sock, (char*) data, dataSize, 0); *readCount = recv(sock, data, dataSize, 0);
/* Extract of man recv (release 3.54 of the Linux man-pages project):
* RETURN VALUE
* These calls return the number of bytes received, or -1 if an error occurred. In the event of an error,
* errno is set to indicate the error. The return value will be 0 when the peer has performed an orderly
* shutdown. */
if (*readCount > 0) if (*readCount > 0)
{ {
status = SOPC_STATUS_OK; status = SOPC_STATUS_OK;
...@@ -347,7 +372,13 @@ SOPC_ReturnStatus Socket_Read(Socket sock, uint8_t* data, uint32_t dataSize, int ...@@ -347,7 +372,13 @@ SOPC_ReturnStatus Socket_Read(Socket sock, uint8_t* data, uint32_t dataSize, int
} }
else if (*readCount == -1) else if (*readCount == -1)
{ {
if (WSAGetLastError() == WSAEWOULDBLOCK) /* Extract of man recv (release 3.54 of the Linux man-pages project):
* If no messages are available at the socket, the receive calls wait for a message to arrive, unless the
* socket is onblocking (see fcntl(2)), in which case the value -1 is returned and the external variable
* errno is set to EAGAIN or WOULDBLOCK. The receive calls normally return any data available, up to the
* requested amount, rather than waiting for receipt of the full amount requested.*/
if (errno == EAGAIN || errno == EWOULDBLOCK)
{ {
status = SOPC_STATUS_WOULD_BLOCK; status = SOPC_STATUS_WOULD_BLOCK;
} }
...@@ -364,9 +395,9 @@ void Socket_Close(Socket* sock) ...@@ -364,9 +395,9 @@ void Socket_Close(Socket* sock)
{ {
if (sock != NULL && *sock != SOPC_INVALID_SOCKET) if (sock != NULL && *sock != SOPC_INVALID_SOCKET)
{ {
if (closesocket(*sock) != SOCKET_ERROR) if (close(*sock) != -1)
{ {
*sock = -1; *sock = SOPC_INVALID_SOCKET;
} }
} }
} }
...@@ -18,18 +18,15 @@ ...@@ -18,18 +18,15 @@
#ifndef SOPC_P_SOCKETS_H_ #ifndef SOPC_P_SOCKETS_H_
#define SOPC_P_SOCKETS_H_ #define SOPC_P_SOCKETS_H_
#include <winsock2.h> #include <netdb.h>
#include <ws2tcpip.h> #include <sys/select.h>
#define MAX_SEND_ATTEMPTS 20 #define SOPC_INVALID_SOCKET -1
#define SLEEP_NEXT_SEND_ATTEMP 50 // milliseconds
#define SOPC_INVALID_SOCKET INVALID_SOCKET
/** /**
* \brief Socket base type * \brief Socket base type
*/ */
typedef SOCKET Socket; typedef int Socket;