You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
599 lines
19 KiB
599 lines
19 KiB
#include "serialSOL.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "SOL", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "SOL", this, _LOG_ERROR, X )
|
|
|
|
serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){
|
|
m_pLog = m_pLog = basicLogCollection::getInstance();
|
|
//memset( &m_sPortSettings, 0, sizeof( SOL_PORT_SETTINGS ));
|
|
//m_sPortSettings.eConnectionType = t;
|
|
m_eType = t;
|
|
memset( m_cDeviceAddress, 0, 64 );
|
|
m_nPort = 0;
|
|
m_nSpeed = 0;
|
|
#ifdef __linux__
|
|
m_nSocketFD = -1;
|
|
memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) );
|
|
memset( &m_sClientAddr, 0, sizeof( m_sClientAddr ) );
|
|
#endif
|
|
};
|
|
|
|
serialSOL::serialSOL( SOL_PORT_SETTINGS *PortSettings ): transportSocket(){
|
|
m_pLog = m_pLog = basicLogCollection::getInstance();
|
|
//memset( &m_sPortSettings, 0, sizeof( SOL_PORT_SETTINGS ));
|
|
//m_sPortSettings.eConnectionType = t;
|
|
m_eType = PortSettings->eConnectionType;
|
|
#ifdef __linux__
|
|
m_nSocketFD = -1;
|
|
memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) );
|
|
memset( &m_sClientAddr, 0, sizeof( m_sClientAddr ) );
|
|
#endif
|
|
};
|
|
|
|
|
|
bool serialSOL::closePort(){
|
|
char tBuff[128];
|
|
|
|
setConnectionStatus( CS_DISCONNECTED );
|
|
|
|
if( m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT ){
|
|
uninit();
|
|
};
|
|
#ifdef __linux__
|
|
if( m_nSocketFD != -1 ){
|
|
#else
|
|
if( m_sSocket != INVALID_SOCKET ){
|
|
#endif
|
|
switch( m_eType ) {
|
|
case SOL_UDP_CLIENT:
|
|
case SOL_TCP_CLIENT:
|
|
case SOL_UDP_SERVER: {
|
|
#ifdef __linux__
|
|
close( m_nSocketFD );
|
|
#else
|
|
// When your application is finished receiving datagrams close the socket.
|
|
LOG("Server: Finished receiving.Closing the listening socket...");
|
|
if( closesocket(m_sSocket) != 0 ){
|
|
sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError());
|
|
LOG_ERROR(tBuff);
|
|
} else {
|
|
LOG("closesocket() is OK...");
|
|
};
|
|
// When your application is finished call WSACleanup.
|
|
LOG("Server: Cleaning up...");
|
|
if (WSACleanup() != 0) {
|
|
sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError());
|
|
LOG_ERROR(tBuff);
|
|
} else {
|
|
LOG("WSACleanup() is OK");
|
|
};
|
|
#endif
|
|
break;
|
|
};
|
|
case SOL_TCP_SERVER:{
|
|
#ifdef __linux__
|
|
close(m_nSocketFD);
|
|
#else
|
|
// When your application is finished receiving datagrams close the socket.
|
|
LOG("Server: Finished receiving.Closing the listening socket...");
|
|
if (closesocket(m_sSocket) != 0) {
|
|
sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError());
|
|
LOG_ERROR(tBuff);
|
|
} else {
|
|
LOG("closesocket() is OK...");
|
|
};
|
|
// When your application is finished call WSACleanup.
|
|
LOG("Server: Cleaning up...");
|
|
if (WSACleanup() != 0) {
|
|
sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError());
|
|
LOG_ERROR(tBuff);
|
|
} else {
|
|
LOG("WSACleanup() is OK");
|
|
};
|
|
#endif
|
|
break;
|
|
};
|
|
};
|
|
#ifdef __linux__
|
|
m_nSocketFD = -1;
|
|
#else
|
|
m_sSocket = INVALID_SOCKET;
|
|
#endif
|
|
};
|
|
return true;
|
|
};
|
|
|
|
serialSOL::~serialSOL(){
|
|
closePort();
|
|
};
|
|
|
|
#ifdef __linux__
|
|
|
|
#else
|
|
// Windows
|
|
int recvfromTimeOutUDP(SOCKET socket, long sec, long usec) {
|
|
// Setup timeval variable
|
|
struct timeval timeout;
|
|
struct fd_set fds;
|
|
timeout.tv_sec = sec;
|
|
timeout.tv_usec = usec;
|
|
// Setup fd_set structure
|
|
FD_ZERO(&fds);
|
|
FD_SET(socket, &fds);
|
|
// Return value:
|
|
// -1: error occurred
|
|
// 0: timed out
|
|
// > 0: data ready to be read
|
|
return select(0, &fds, 0, 0, &timeout);
|
|
};
|
|
#endif
|
|
|
|
bool serialSOL::create( CSTR address, uint16_t port, int Speed, SOL_TYPE t ){
|
|
if( m_eType == SOL_NOT_DEFINED ){
|
|
if ( t == SOL_NOT_DEFINED ) {
|
|
LOG_ERROR("No Connection Type Defined!");
|
|
return false;
|
|
};
|
|
m_eType = t;
|
|
} else {
|
|
if ( t != SOL_NOT_DEFINED ) {
|
|
m_eType = t;
|
|
};
|
|
};
|
|
if( m_nPort == 0 ){
|
|
if( port == 0 ) {
|
|
LOG_ERROR("No Port Defined!");
|
|
return false;
|
|
};
|
|
m_nPort = port;
|
|
} else {
|
|
if( port != 0 ) {
|
|
m_nPort = port;
|
|
};
|
|
};
|
|
if( m_nSpeed == 0 ){
|
|
if( Speed == 0 ){
|
|
LOG_ERROR("No Speed Defined!");
|
|
return false;
|
|
};
|
|
m_nSpeed = Speed;
|
|
} else {
|
|
if( Speed != 0 ) {
|
|
m_nSpeed = Speed;
|
|
};
|
|
};
|
|
if( m_cDeviceAddress[0]==(char)0 ) {
|
|
if( address== NULL) return false;
|
|
strncpy(m_cDeviceAddress, address, 64 );
|
|
} else {
|
|
if( address != NULL ) {
|
|
if( address[0]!= (char)0 ) {
|
|
strncpy(m_cDeviceAddress, address, 64 );
|
|
};
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
LOG( m_cDeviceAddress );
|
|
#endif
|
|
switch( m_eType ) {
|
|
case SOL_UDP_CLIENT:{
|
|
#ifdef DEBUG
|
|
LOG("PORT IS CLIENT - Create UDP Server");
|
|
#endif
|
|
#ifdef __linux__
|
|
// Creating socket file descriptor
|
|
if ( (m_nSocketFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) {
|
|
LOG_ERROR("UDP Socket Creation Failed!");
|
|
return false;
|
|
};
|
|
fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK);
|
|
// Filling server information
|
|
m_sServerAddr.sin_family = AF_INET; // IPv4
|
|
m_sServerAddr.sin_addr.s_addr = INADDR_ANY;
|
|
m_sServerAddr.sin_port = htons( m_nPort );
|
|
|
|
// Bind the socket with the server address
|
|
if ( bind( m_nSocketFD, (const struct sockaddr *)&m_sServerAddr, sizeof(m_sServerAddr)) < 0 ){
|
|
LOG_ERROR("UDP Bind Failed");
|
|
return false;
|
|
};
|
|
#else
|
|
WSADATA wsaData;
|
|
// Initialize Winsock version 2.2
|
|
char tBuff[128];
|
|
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
|
sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError());
|
|
LOG_ERROR(tBuff);
|
|
return false;
|
|
} else {
|
|
sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus);
|
|
LOG(tBuff);
|
|
};
|
|
// Set up a SOCKADDR_IN structure that will tell bind that we
|
|
// want to receive datagrams from all interfaces using port 5150.
|
|
// The IPv4 family
|
|
m_sServerAddr.sin_family = AF_INET;
|
|
// Port no. 5150
|
|
m_sServerAddr.sin_port = htons( m_nPort );
|
|
// From all interface (0.0.0.0)
|
|
m_sServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
// Associate the address information with the socket using bind.
|
|
// At this point you can receive datagrams on your bound socket.
|
|
if( bind(m_sSocket, (SOCKADDR*)&m_sServerAddr, sizeof(m_sServerAddr)) == SOCKET_ERROR ){
|
|
sprintf( tBuff, "Server: bind() failed!Error : %ld.", WSAGetLastError());
|
|
// Close the socket
|
|
closesocket(m_sSocket);
|
|
// Do the clean up
|
|
WSACleanup();
|
|
// and exit with error
|
|
LOG_ERROR(tBuff);
|
|
return false;
|
|
} else {
|
|
LOG("UDP Server: bind() is OK!");
|
|
};
|
|
// Some info on the receiver side...
|
|
SOCKADDR_IN tAddr;
|
|
int tLen = sizeof(SOCKADDR_IN);
|
|
getsockname(m_sSocket, (SOCKADDR*)&tAddr, &tLen);
|
|
sprintf( tBuff, "Receiving IP(s) used : %s", inet_ntoa(tAddr.sin_addr));
|
|
LOG(tBuff);
|
|
sprintf(tBuff,"Receiving port used : %d", htons(tAddr.sin_port));
|
|
LOG(tBuff);
|
|
SelectTiming = recvfromTimeOutUDP(m_sSocket, 10, 0);
|
|
#endif
|
|
break;
|
|
};
|
|
case SOL_TCP_CLIENT:{
|
|
#ifdef DEBUG
|
|
LOG("PORT IS CLIENT - Create TCP Server");
|
|
#endif
|
|
break;
|
|
};
|
|
case SOL_UDP_SERVER:{
|
|
#ifdef DEBUG
|
|
LOG("PORT IS SERVER - Create UDP Client");
|
|
#endif
|
|
#ifdef __linux__
|
|
// Creating socket file descriptor
|
|
if ( (m_nSocketFD = socket( AF_INET, SOCK_DGRAM, 0)) < 0 ) {
|
|
LOG_ERROR("Socket Creation Failed!");
|
|
return false;
|
|
};
|
|
fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK );
|
|
|
|
// Filling server information
|
|
m_sServerAddr.sin_family = AF_INET;
|
|
m_sServerAddr.sin_addr.s_addr = INADDR_ANY;
|
|
m_sServerAddr.sin_port = htons( m_nPort );
|
|
#else
|
|
|
|
#endif
|
|
break;
|
|
};
|
|
case SOL_TCP_SERVER:{
|
|
#ifdef DEBUG
|
|
LOG("PORT IS SERVER - Create TCP Client");
|
|
#endif
|
|
// socket create and varification
|
|
#ifdef __linux__
|
|
m_nSocketFD = socket( AF_INET, SOCK_STREAM, 0 );
|
|
if( m_nSocketFD == -1) {
|
|
LOG_ERROR("Socket creation failed!");
|
|
return false;
|
|
}
|
|
#else
|
|
m_sSocket = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (m_sSocket == INVALID_SOCKET ) {
|
|
LOG_ERROR("Socket creation failed!");
|
|
return false;
|
|
}
|
|
#endif
|
|
#ifdef DEBUG
|
|
else LOG("Socket successfully created");
|
|
#endif
|
|
memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) );
|
|
|
|
// assign IP, PORT
|
|
m_sServerAddr.sin_family = AF_INET;
|
|
m_sServerAddr.sin_addr.s_addr = inet_addr( m_cDeviceAddress );
|
|
m_sServerAddr.sin_port = htons( m_nPort );
|
|
|
|
|
|
#ifdef __linux__
|
|
// Set non-blocking
|
|
int arg;
|
|
if( (arg = fcntl( m_nSocketFD, F_GETFL, NULL)) < 0) {
|
|
char tBuf[128];
|
|
sprintf( tBuf, "Error fcntl(..., F_GETFL) (%s)", strerror(errno));
|
|
LOG_ERROR( tBuf );
|
|
return false;
|
|
};
|
|
arg |= O_NONBLOCK;
|
|
if( fcntl( m_nSocketFD, F_SETFL, arg) < 0) {
|
|
char tBuf[128];
|
|
sprintf( tBuf, "Error fcntl(..., F_SETFL) (%s)", strerror(errno));
|
|
LOG_ERROR( tBuf );
|
|
return false;
|
|
};
|
|
// connect the client socket to server socket
|
|
if( connect( m_nSocketFD, (struct sockaddr *)&m_sServerAddr, sizeof( struct sockaddr ) ) < 0 ){
|
|
if( errno == EINPROGRESS ){
|
|
#ifdef DEBUG
|
|
LOG( "EINPROGRESS in connect() - selecting" );
|
|
#endif
|
|
do {
|
|
fd_set myset;
|
|
struct timeval tv;
|
|
|
|
tv.tv_sec = 3;
|
|
tv.tv_usec = 0;
|
|
FD_ZERO( &myset );
|
|
FD_SET( m_nSocketFD, &myset );
|
|
int res = select( m_nSocketFD+1, NULL, &myset, NULL, &tv );
|
|
if( res < 0 && errno != EINTR ){
|
|
char tBuff[128];
|
|
sprintf( tBuff, "Error connecting %d - %s", errno, strerror(errno));
|
|
LOG_ERROR( tBuff );
|
|
return false;
|
|
} else if( res > 0 ){
|
|
// Socket selected for write
|
|
int valopt;
|
|
socklen_t lon = sizeof(int);
|
|
if( getsockopt( m_nSocketFD, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon) < 0 ){
|
|
char tBuff[128];
|
|
sprintf( tBuff, "Error in getsockopt() %d - %s", errno, strerror(errno));
|
|
LOG_ERROR( tBuff );
|
|
return false;
|
|
};
|
|
// Check the value returned...
|
|
if( valopt ){
|
|
char tBuff[128];
|
|
sprintf( tBuff, "Error in delayed connection() %d - %s", valopt, strerror(valopt) );
|
|
LOG_ERROR( tBuff );
|
|
return false;
|
|
};
|
|
break;
|
|
} else {
|
|
LOG_ERROR("Timeout in select() - Cancelling!");
|
|
return false;
|
|
};
|
|
} while( 1 );
|
|
} else {
|
|
char tBuff[128];
|
|
sprintf( tBuff, "Error connecting %d - %s", errno, strerror(errno));
|
|
LOG_ERROR( tBuff );
|
|
return false;
|
|
};
|
|
}
|
|
#else
|
|
// Set non-blocking
|
|
u_long arg = 1;
|
|
if( ioctlsocket(m_sSocket, FIONBIO, &arg) < 0 ){
|
|
char tBuf[128];
|
|
sprintf(tBuf, "Error ioctlsocket(..., FIONBIO) (%s)", strerror(errno));
|
|
LOG_ERROR(tBuf);
|
|
return false;
|
|
};
|
|
// connect the client socket to server socket
|
|
if (connect(m_sSocket, (struct sockaddr*) & m_sServerAddr, sizeof(struct sockaddr)) != 0) {
|
|
char cBuffer[128];
|
|
sprintf(cBuffer,"ERROR connect to [%s:%d] (%s)", m_cDeviceAddress, m_nPort, strerror(errno) );
|
|
LOG_ERROR( cBuffer );
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
else LOG("Connected to the server");
|
|
#endif
|
|
setConnectionStatus( CS_CONNECTED );
|
|
break;
|
|
};
|
|
};
|
|
return init();
|
|
};
|
|
|
|
int serialSOL::sendBlock(unsigned char* Data, int DataSize) {
|
|
int RetVal = 0;
|
|
if( m_eConnectionStatus!= CS_CONNECTED ) return -1; // Exit after unsuccess reconnect
|
|
#ifdef __linux__
|
|
if (m_nSocketFD > -1) {
|
|
|
|
#ifdef _DEBUG_SOL_COMMUNICATION_
|
|
char cBuffer[256];
|
|
sprintf(cBuffer, "Write into Socket %d bytes", DataSize);
|
|
LOG(cBuffer);
|
|
#endif
|
|
|
|
socklen_t addr_len = sizeof(m_sClientAddr);
|
|
RetVal = sendto(m_nSocketFD, (const char*)Data, DataSize, MSG_CONFIRM, (const struct sockaddr*) &m_sClientAddr, addr_len );
|
|
|
|
if ((RetVal == -1) && (errno != EINTR) && (errno != EWOULDBLOCK)) {
|
|
LOG_ERROR("Error acures while writing data into the Socket");
|
|
shutdown(m_nSocketFD, 2);
|
|
close(m_nSocketFD);
|
|
m_nSocketFD = -1;
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
return -1;
|
|
};
|
|
|
|
if (RetVal < 0) RetVal = 0;
|
|
|
|
#ifdef _DEBUG_SOL_COMMUNICATION_
|
|
sprintf(cBuffer, "Bytes Sent: %ld", RetVal);
|
|
LOG(cBuffer);
|
|
for(int zz=0; zz < RetVal; zz++ ) {
|
|
sprintf(cBuffer, "SD: 0x%02X", (uint8_t)Data[zz]);
|
|
LOG(cBuffer);
|
|
};
|
|
#endif
|
|
|
|
} else {
|
|
LOG_ERROR("Not Connected!");
|
|
//m_bConnected = false;
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
return -1;
|
|
};
|
|
#else
|
|
if (sendto( m_sSocket, (char *)Data, DataSize, 0, (struct sockaddr*) & m_sServerAddr, sizeof(m_sServerAddr)) == SOCKET_ERROR) {
|
|
printf("sendto() failed with error code : %d", WSAGetLastError());
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
#endif
|
|
return RetVal;
|
|
};
|
|
|
|
int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){
|
|
int RetVal = 0;
|
|
#ifdef __linux__
|
|
if (m_eConnectionStatus != CS_CONNECTED) {
|
|
//make prep for connection
|
|
if (m_eType == SOL_TCP_CLIENT) {
|
|
//ACCEPT
|
|
struct sockaddr ClientAddress;
|
|
socklen_t size = sizeof(struct sockaddr_in);
|
|
//int ClientSocket;
|
|
m_nSocketFD = accept(m_nMasterSocketFD, &ClientAddress, &size);
|
|
if (m_nSocketFD < 0) {
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
LOG_ERROR("Connection Accept Failure!");
|
|
return -1;
|
|
};
|
|
}
|
|
else {
|
|
LOG_ERROR("RCPT ON not connected!");
|
|
shutdown(m_nSocketFD, 2);
|
|
close(m_nSocketFD);
|
|
*BufferLength = 0;
|
|
m_nSocketFD = -1;
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
return -1;
|
|
};
|
|
};
|
|
if( m_nSocketFD > -1 ) {
|
|
socklen_t addr_len = sizeof( m_sClientAddr ); //len is value/resuslt
|
|
//RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len );
|
|
RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_DONTWAIT, ( struct sockaddr *) &m_sClientAddr, &addr_len );
|
|
if( RetVal < 1 ){
|
|
if( errno!=EAGAIN && errno!=EINTR ) {
|
|
LOG_ERROR("Peer Closes Connection!");
|
|
shutdown( m_nSocketFD, 2 );
|
|
close( m_nSocketFD );
|
|
*BufferLength = 0;
|
|
m_nSocketFD = -1;
|
|
setConnectionStatus( CS_DISCONNECTED );
|
|
return -1;
|
|
};
|
|
};
|
|
|
|
} else {
|
|
LOG_ERROR("Not Connected!");
|
|
*BufferLength = 0;
|
|
setConnectionStatus( CS_DISCONNECTED );
|
|
return -1;
|
|
};
|
|
#else
|
|
if (m_eConnectionStatus != CS_CONNECTED) {
|
|
//make prep for connection
|
|
if (m_eType == SOL_TCP_CLIENT) {
|
|
//ACCEPT
|
|
int size = sizeof(m_sClientAddr);
|
|
//int ClientSocket;
|
|
m_sSocket = accept(m_sMasterSocket, (sockaddr *) &m_sClientAddr, &size);
|
|
if( m_sSocket == INVALID_SOCKET ){
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
LOG_ERROR("Connection Accept Failure!");
|
|
return -1;
|
|
};
|
|
} else {
|
|
LOG_ERROR("RCPT ON not connected!");
|
|
shutdown(m_sSocket, 2);
|
|
closesocket(m_sSocket);
|
|
*BufferLength = 0;
|
|
m_sSocket = INVALID_SOCKET;
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
return -1;
|
|
};
|
|
};
|
|
if( m_sSocket != INVALID_SOCKET ) {
|
|
switch (m_eType) {
|
|
case SOL_UDP_CLIENT:
|
|
case SOL_TCP_CLIENT:
|
|
case SOL_UDP_SERVER: {
|
|
int tLen = sizeof(m_sClientAddr);
|
|
RetVal = recvfrom(m_sSocket, (char*)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0, (struct sockaddr*) &m_sClientAddr, &tLen);
|
|
if (RetVal == SOCKET_ERROR) {
|
|
char cBuffer[165];
|
|
sprintf(cBuffer, "recvfrom() failed with error code : %d", WSAGetLastError());
|
|
LOG_ERROR(cBuffer);
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
} else {
|
|
LOG_ERROR("Not Connected!");
|
|
*BufferLength = 0;
|
|
setConnectionStatus(CS_DISCONNECTED);
|
|
return -1;
|
|
};
|
|
#endif
|
|
if (RetVal > 0) {
|
|
#ifdef _DEBUG_SOL_COMMUNICATION_
|
|
char cBuffer[165];
|
|
sprintf(cBuffer, "Bytes received: %d", RetVal);
|
|
LOG(cBuffer);
|
|
#endif
|
|
*BufferLength = RetVal;
|
|
return RetVal;
|
|
};
|
|
|
|
*BufferLength = 0;
|
|
|
|
if (RetVal == -1) return 0;
|
|
|
|
if (RetVal == 0){
|
|
errno = 0;
|
|
return 0;
|
|
};
|
|
|
|
/* r < -1, should never happen. */
|
|
errno = EIO;
|
|
return 0;
|
|
};
|
|
|
|
/* In Case Server Instance - Accepting Connection Thread Is Used */
|
|
/*
|
|
void serialSOL::m_fThreadProc( void ){
|
|
m_bThreadStatus = TH_WORKING;
|
|
LOG( "Core Worker Thread Started" );
|
|
LOG( "Ready to Accept Connections" );
|
|
while( m_bThreadStatus < TH_ENDED ) {
|
|
switch( m_sPortSettings.eConnectionType ){
|
|
case SOL_UDP_CLIENT:{
|
|
|
|
break;
|
|
};
|
|
case SOL_TCP_CLIENT:{
|
|
struct sockaddr ClientAddress;
|
|
socklen_t size;
|
|
int ClientSocket;
|
|
size = (socklen_t) sizeof( struct sockaddr_in );
|
|
ClientSocket = accept( m_nSocketFD, &ClientAddress, &size );
|
|
#ifdef SOL_SINGLE_CLIENT
|
|
if( m_eConnectionStatus == CS_DISCONNECTED ) {
|
|
setConnectionStatus( CS_CONNECTED );
|
|
} else {
|
|
LOG_ERROR("Another Client Tryes To Connect!");
|
|
close( ClientSocket );
|
|
};
|
|
#endif
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
*/
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|