connectivity/com.nokia.tcf/native/TCFNative/TCFCommTCP/TcpComm.cpp
changeset 366 b054461d2f85
parent 60 9d2210c8eed2
child 389 de80f483b7e6
equal deleted inserted replaced
365:666472f6d7ae 366:b054461d2f85
    22 #include "TcpComm.h"
    22 #include "TcpComm.h"
    23 //#include "pn_const.h"
    23 //#include "pn_const.h"
    24 //#include "OSTConstants.h"
    24 //#include "OSTConstants.h"
    25 #include "Connection.h"
    25 #include "Connection.h"
    26 
    26 
    27 #ifdef _DEBUG
       
    28 static char sTcpLogMsg[3000];
       
    29 #endif
       
    30 //////////////////////////////////////////////////////////////////////
    27 //////////////////////////////////////////////////////////////////////
    31 // Construction/Destruction
    28 // Construction/Destruction
    32 //////////////////////////////////////////////////////////////////////
    29 //////////////////////////////////////////////////////////////////////
    33 CTcpComm::CTcpComm()
    30 CTcpComm::CTcpComm()
    34 {
    31 {
    35 #ifdef _DEBUG
    32 #ifdef _DEBUG
    36 	if (gDoLogging)
    33 	if (gDoLogging)
    37 	{
    34 	{
    38 		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    35 //		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    39 		fprintf(f, "CTcpComm::CTcpComm() (default constructor)\n");
    36 //		fprintf(f, "CTcpComm::CTcpComm() (default constructor)\n");
    40 		fclose(f);
    37 //		fclose(f);
    41 	}
    38 	}
    42 #endif
    39 #endif
    43 	m_socket = INVALID_SOCKET;
    40 	m_socket = INVALID_SOCKET;
    44 	m_timeOut.tv_sec = TIMEOUT_SEC(DEFAULT_SOCKET_TIMEOUT);
    41 	m_timeOut.tv_sec = TIMEOUT_SEC(DEFAULT_SOCKET_TIMEOUT);
    45 	m_timeOut.tv_usec = TIMEOUT_USEC(DEFAULT_SOCKET_TIMEOUT);
    42 	m_timeOut.tv_usec = TIMEOUT_USEC(DEFAULT_SOCKET_TIMEOUT);
    46 
    43 
    47 	m_hSocketEvent = WSA_INVALID_EVENT;
    44 	m_hSocketEvent = WSA_INVALID_EVENT;
       
    45 
    48 }
    46 }
    49 
    47 
    50 CTcpComm::CTcpComm(ConnectData* connectSettings, DWORD connectionId, CBaseProtocol* protocol)
    48 CTcpComm::CTcpComm(ConnectData* connectSettings, DWORD connectionId, CBaseProtocol* protocol)
    51 {
    49 {
    52 #ifdef _DEBUG
    50 #ifdef _DEBUG
    53 	if (gDoLogging)
    51 	if (gDoLogging)
    54 	{
    52 	{
    55 		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    53 //		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    56 		fprintf(f, "connectSettings=%x connectionId=%d, protocol=%x\n", connectSettings, connectionId, protocol);
    54 //		fprintf(f, "connectSettings=%x connectionId=%d, protocol=%x\n", connectSettings, connectionId, protocol);
    57 		fclose(f);
    55 //		fclose(f);
    58 	}
    56 	}
    59 #endif
    57 #endif
    60 	m_connId = connectionId;
    58 	m_connId = connectionId;
    61 	m_Protocol = protocol;
    59 	m_Protocol = protocol;
    62 
    60 
    73 	m_socket = INVALID_SOCKET;
    71 	m_socket = INVALID_SOCKET;
    74 	m_timeOut.tv_sec = TIMEOUT_SEC(DEFAULT_SOCKET_TIMEOUT);
    72 	m_timeOut.tv_sec = TIMEOUT_SEC(DEFAULT_SOCKET_TIMEOUT);
    75 	m_timeOut.tv_usec = TIMEOUT_USEC(DEFAULT_SOCKET_TIMEOUT);
    73 	m_timeOut.tv_usec = TIMEOUT_USEC(DEFAULT_SOCKET_TIMEOUT);
    76 
    74 
    77 	m_hSocketEvent = WSA_INVALID_EVENT;
    75 	m_hSocketEvent = WSA_INVALID_EVENT;
       
    76 
    78 }
    77 }
    79 CTcpComm::~CTcpComm()
    78 CTcpComm::~CTcpComm()
    80 {
    79 {
    81 #ifdef _DEBUG
    80 #ifdef _DEBUG
    82 	if (gDoLogging)
    81 	if (gDoLogging)
    83 	{
    82 	{
    84 		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    83 //		FILE* f = fopen("c:\\tcf\\tcpcommlog.txt", "at");
    85 		fprintf(f, "CTcpComm::~CTcpComm()\n");
    84 //		fprintf(f, "CTcpComm::~CTcpComm()\n");
    86 		fclose(f);
    85 //		fclose(f);
    87 	}
    86 	}
    88 #endif
    87 #endif
    89 	if (IsConnected())
    88 	if (IsConnected())
    90 	{
    89 	{
    91 		shutdown(m_socket, SD_BOTH);
    90 		if (m_socket != INVALID_SOCKET)
    92 		closesocket(m_socket);
    91 		{
    93 		WSACleanup();
    92 			shutdown(m_socket, SD_BOTH);
       
    93 			closesocket(m_socket);
       
    94 			WSAClose();
       
    95 		}
       
    96 		m_isConnected = false;
    94 	}
    97 	}
    95 	if (m_pBuffer)
    98 	if (m_pBuffer)
    96 		delete[] m_pBuffer;
    99 		delete[] m_pBuffer;
    97 
   100 
    98 	if (m_hSocketEvent != WSA_INVALID_EVENT)
   101 	if (m_hSocketEvent != WSA_INVALID_EVENT)
   114 	// DWORD nonblock = 1;		// non-blocking
   117 	// DWORD nonblock = 1;		// non-blocking
   115 	DWORD nonblock = 0;		// blocking
   118 	DWORD nonblock = 0;		// blocking
   116 
   119 
   117 	COMMLOGA2("CTcpComm::OpenPort ipAddress=%s ipPort=%s\n", ipAddress, ipPort);
   120 	COMMLOGA2("CTcpComm::OpenPort ipAddress=%s ipPort=%s\n", ipAddress, ipPort);
   118 
   121 
   119 	WSADATA wsaData;
   122 	int wsaErr = 0;
   120 	int wsaErr = WSAStartup(MAKEWORD(2,2), &wsaData);
   123 	wsaErr = WSAInit();
   121 	if (wsaErr != 0)
   124 	if (wsaErr != 0)
   122 	{
   125 	{
   123 		err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   126 		err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   124 //		err = -1;
   127 //		err = -1;
   125 	}
   128 	}
   126 	else
   129 	else
   127 	{
   130 	{
   128 		m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
   131 		m_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
       
   132 		COMMLOGA1("CTcpComm::OpenPort socket=%x\n", m_socket);
   129 		if (m_socket == INVALID_SOCKET)
   133 		if (m_socket == INVALID_SOCKET)
   130 		{
   134 		{
   131 			m_lastCommError = WSAGetLastError();
   135 			m_lastCommError = WSAGetLastError();
   132 			WSACleanup();
   136 			WSASetLastError(0);
       
   137 			WSAClose();
   133 			err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   138 			err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   134 		}
   139 		}
   135 		else
   140 		else
   136 		{
   141 		{
   137 			if (ioctlsocket(m_socket, FIONBIO, &nonblock) == SOCKET_ERROR)
   142 			if (ioctlsocket(m_socket, FIONBIO, &nonblock) == SOCKET_ERROR)
   138 			{
   143 			{
   139 				m_lastCommError = WSAGetLastError();
   144 				m_lastCommError = WSAGetLastError();
       
   145 				WSASetLastError(0);
   140 				closesocket(m_socket);
   146 				closesocket(m_socket);
   141 				m_socket = INVALID_SOCKET;
   147 				m_socket = INVALID_SOCKET;
   142 				WSACleanup();
   148 				WSAClose();
   143 				err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   149 				err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   144 			}
   150 			}
   145 			else
   151 			else
   146 			{
   152 			{
   147 				int i = SO_MAX_MSG_SIZE;
   153 				int i = SO_MAX_MSG_SIZE;
   148 				// set socket options
   154 				// set socket options
   149 				BOOL keepAlive = TRUE;
   155 				BOOL keepAlive = FALSE;
   150 				setsockopt(m_socket, SOL_SOCKET, SO_KEEPALIVE, (const char*)&keepAlive, sizeof(BOOL));
   156 				setsockopt(m_socket, SOL_SOCKET, SO_KEEPALIVE, (const char*)&keepAlive, sizeof(BOOL));
       
   157 
       
   158 				struct linger l;
       
   159 				l.l_onoff = 0; l.l_linger = 0;
       
   160 				setsockopt(m_socket, SOL_SOCKET, SO_LINGER, (const char*)&l, sizeof(l));
       
   161 
   151 				int sockRecvSize = MAX_TCP_MESSAGE_BUFFER_LENGTH;//(256*1024L);
   162 				int sockRecvSize = MAX_TCP_MESSAGE_BUFFER_LENGTH;//(256*1024L);
   152 				setsockopt(m_socket, SOL_SOCKET, SO_RCVBUF, (const char*)&sockRecvSize, sizeof(int));
   163 				setsockopt(m_socket, SOL_SOCKET, SO_RCVBUF, (const char*)&sockRecvSize, sizeof(int));
   153 				int sockSendSize = (64*1024L);
   164 				int sockSendSize = (64*1024L);
   154 				setsockopt(m_socket, SOL_SOCKET, SO_SNDBUF, (const char*)&sockSendSize, sizeof(int));
   165 				setsockopt(m_socket, SOL_SOCKET, SO_SNDBUF, (const char*)&sockSendSize, sizeof(int));
   155 				WSAGetLastError(); // ignore error for now
   166 				WSAGetLastError(); // ignore error for now
   156 				int gotsockRecvSize, optLen=sizeof(int);
   167 				WSASetLastError(0);
   157 				getsockopt(m_socket, SOL_SOCKET, SO_RCVBUF, (char*)&gotsockRecvSize, &optLen);
   168 
   158 				WSAGetLastError(); // ignore error for now
       
   159 				// connect
   169 				// connect
   160 				WORD wPort = atoi(ipPort);
   170 				WORD wPort = atoi(ipPort);
   161 				m_clientService.sin_family = AF_INET;
   171 				m_clientService.sin_family = AF_INET;
   162 				m_clientService.sin_addr.S_un.S_addr = inet_addr(ipAddress);
   172 				m_clientService.sin_addr.S_un.S_addr = inet_addr(ipAddress);
   163 				m_clientService.sin_port = htons(wPort);
   173 				m_clientService.sin_port = htons(wPort);
   164 				if (connect(m_socket, (SOCKADDR*)&m_clientService, sizeof(m_clientService)) == SOCKET_ERROR)
   174 				if (connect(m_socket, (SOCKADDR*)&m_clientService, sizeof(m_clientService)) == SOCKET_ERROR)
   165 				{
   175 				{
   166 					int wsaErr = WSAGetLastError();
   176 					int wsaErr = WSAGetLastError();
       
   177 					WSASetLastError(0);
       
   178 					COMMLOGA1("CTcpComm::OpenPort connect=wsaErr=%d\n", wsaErr);
       
   179 
   167 					// socket is non-blocking
   180 					// socket is non-blocking
   168 					if (wsaErr != WSAEWOULDBLOCK)
   181 					if (wsaErr != WSAEWOULDBLOCK)
   169 					{
   182 					{
   170 						m_lastCommError = wsaErr;
   183 						m_lastCommError = wsaErr;
   171 
   184 
   172 						closesocket(m_socket);
   185 						closesocket(m_socket);
   173 						m_socket = INVALID_SOCKET;
   186 						m_socket = INVALID_SOCKET;
   174 						WSACleanup();
   187 						WSAClose();
   175 						err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   188 						err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   176 					}
   189 					}
   177 					else // WSAEWOULDBLOCK error returned
   190 					else // WSAEWOULDBLOCK error returned
   178 					{
   191 					{
   179 						// WSAEWOULDBLOCK use select now
   192 						// WSAEWOULDBLOCK use select now
   190 						{
   203 						{
   191 							selRes = select(0, &readfds, &writefds, &exceptfds, &m_timeOut);
   204 							selRes = select(0, &readfds, &writefds, &exceptfds, &m_timeOut);
   192 							if (selRes == SOCKET_ERROR)
   205 							if (selRes == SOCKET_ERROR)
   193 							{
   206 							{
   194 								wsaErr = WSAGetLastError();
   207 								wsaErr = WSAGetLastError();
       
   208 								WSASetLastError(0);
   195 								if (wsaErr != WSAEWOULDBLOCK)
   209 								if (wsaErr != WSAEWOULDBLOCK)
   196 								{
   210 								{
   197 									// real error
   211 									// real error
   198 									m_lastCommError = wsaErr;
   212 									m_lastCommError = wsaErr;
   199 									shutdown(m_socket, SD_BOTH);
   213 									shutdown(m_socket, SD_BOTH);
   200 									closesocket(m_socket);
   214 									closesocket(m_socket);
   201 									m_socket = INVALID_SOCKET;
   215 									m_socket = INVALID_SOCKET;
   202 									WSACleanup();
   216 									WSAClose();
   203 									err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   217 									err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   204 								}
   218 								}
   205 								// else do another select
   219 								// else do another select
   206 							}
   220 							}
   207 							else if (selRes > 0)// select OK 
   221 							else if (selRes > 0)// select OK 
   212 							}
   226 							}
   213 							else
   227 							else
   214 							{
   228 							{
   215 								// timed out
   229 								// timed out
   216 								m_lastCommError = WSAGetLastError();
   230 								m_lastCommError = WSAGetLastError();
       
   231 								WSASetLastError(0);
   217 								shutdown(m_socket, SD_BOTH);
   232 								shutdown(m_socket, SD_BOTH);
   218 								closesocket(m_socket);
   233 								closesocket(m_socket);
   219 								m_socket = INVALID_SOCKET;
   234 								m_socket = INVALID_SOCKET;
   220 								WSACleanup();
   235 								WSAClose();
   221 								err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   236 								err = TCAPI_ERR_WHILE_CONFIGURING_MEDIA;
   222 							}
   237 							}
   223 						}
   238 						}
   224 					}
   239 					}
   225 				}
   240 				}
   226 				else // connect return OK
   241 				else // connect return OK
   227 				{
   242 				{
       
   243 					COMMLOGS("CTcpComm::OpenPort connect OK\n");
   228 					m_lastCommError = 0;
   244 					m_lastCommError = 0;
   229 					m_isConnected = true;
   245 					m_isConnected = true;
   230 				}
   246 				}
   231 			}
   247 			}
   232 		}
   248 		}
   246 		//  thus this ioctlsocket call will fail
   262 		//  thus this ioctlsocket call will fail
   247 		ioctlsocket(m_socket, FIONBIO, &nonblock);
   263 		ioctlsocket(m_socket, FIONBIO, &nonblock);
   248 #endif
   264 #endif
   249 	}
   265 	}
   250 
   266 
       
   267 	COMMLOGA1("CTcpComm::OpenPort err=%d\n", err);
   251 	COMMLOGCLOSE();
   268 	COMMLOGCLOSE();
   252 	return err;
   269 	return err;
   253 }
   270 }
   254 
   271 
   255 long CTcpComm::ClosePort()
   272 long CTcpComm::ClosePort()
   263 	{
   280 	{
   264 		err = TCAPI_ERR_MEDIA_NOT_OPEN;
   281 		err = TCAPI_ERR_MEDIA_NOT_OPEN;
   265 	}
   282 	}
   266 	else
   283 	else
   267 	{
   284 	{
   268 		shutdown(m_socket, SD_BOTH);
   285 		if (m_socket != INVALID_SOCKET)
   269 		closesocket(m_socket);
   286 		{
   270 		m_socket = INVALID_SOCKET;
   287 			shutdown(m_socket, SD_BOTH);
   271 		WSACleanup();
   288 			closesocket(m_socket);
       
   289 			m_socket = INVALID_SOCKET;
       
   290 
       
   291 			WSAClose();
       
   292 		}
       
   293 		m_isConnected = false;
   272 
   294 
   273 		delete[] m_pBuffer;
   295 		delete[] m_pBuffer;
   274 		m_pBuffer = NULL;
   296 		m_pBuffer = NULL;
   275 
   297 
   276 		if (m_hSocketEvent != WSA_INVALID_EVENT)
   298 		if (m_hSocketEvent != WSA_INVALID_EVENT)
   336 			}
   358 			}
   337 		}
   359 		}
   338 		else if (selErr == SOCKET_ERROR)
   360 		else if (selErr == SOCKET_ERROR)
   339 		{
   361 		{
   340 			m_lastCommError = WSAGetLastError();
   362 			m_lastCommError = WSAGetLastError();
       
   363 			WSASetLastError(0);
   341 			err = TCAPI_ERR_COMM_ERROR;
   364 			err = TCAPI_ERR_COMM_ERROR;
   342 		}
   365 		}
   343 	}
   366 	}
   344 
   367 
   345 	if (portReady)
   368 	if (portReady)
   354 				outSize = numBytes;
   377 				outSize = numBytes;
   355 			}
   378 			}
   356 			else // SOCKET_ERROR
   379 			else // SOCKET_ERROR
   357 			{
   380 			{
   358 				m_lastCommError = WSAGetLastError();
   381 				m_lastCommError = WSAGetLastError();
       
   382 				WSASetLastError(0);
   359 				err = TCAPI_ERR_COMM_ERROR;
   383 				err = TCAPI_ERR_COMM_ERROR;
   360 			}
   384 			}
   361 		}
   385 		}
   362 		else if (recvRet == 0)
   386 		else if (recvRet == 0)
   363 		{
   387 		{
   367 		}
   391 		}
   368 		else
   392 		else
   369 		{
   393 		{
   370 			// SOCKET_ERROR: error on recv other than a shutdown
   394 			// SOCKET_ERROR: error on recv other than a shutdown
   371 			m_lastCommError = WSAGetLastError();
   395 			m_lastCommError = WSAGetLastError();
       
   396 			WSASetLastError(0);
   372 			err = TCAPI_ERR_COMM_ERROR;
   397 			err = TCAPI_ERR_COMM_ERROR;
   373 		}
   398 		}
   374 	}
   399 	}
   375 	return err;
   400 	return err;
   376 }
   401 }
   390 			numBytes = inSize;
   415 			numBytes = inSize;
   391 		int res = recv(m_socket, (char*)outData, numBytes, 0);
   416 		int res = recv(m_socket, (char*)outData, numBytes, 0);
   392 		if (res == SOCKET_ERROR)
   417 		if (res == SOCKET_ERROR)
   393 		{
   418 		{
   394 			long commErr = WSAGetLastError();
   419 			long commErr = WSAGetLastError();
       
   420 			WSASetLastError(0);
   395 			if ((DWORD)commErr != m_lastCommError)
   421 			if ((DWORD)commErr != m_lastCommError)
   396 			{
   422 			{
   397 				m_lastCommError = commErr;
   423 				m_lastCommError = commErr;
   398 			}
   424 			}
   399 			err = TCAPI_ERR_COMM_ERROR;
   425 			err = TCAPI_ERR_COMM_ERROR;
   412 	}
   438 	}
   413 	else
   439 	else
   414 	{
   440 	{
   415 		// SOCKET_ERROR on ioctlsocket
   441 		// SOCKET_ERROR on ioctlsocket
   416 		m_lastCommError = WSAGetLastError();
   442 		m_lastCommError = WSAGetLastError();
       
   443 		WSASetLastError(0);
   417 		err = TCAPI_ERR_COMM_ERROR;
   444 		err = TCAPI_ERR_COMM_ERROR;
   418 	}
   445 	}
   419 	return err;
   446 	return err;
   420 }
   447 }
   421 long CTcpComm::ProcessBuffer(CConnection* pConn, CRegistry* pRegistry, long& numberProcessed)
   448 long CTcpComm::ProcessBuffer(CConnection* pConn, CRegistry* pRegistry, long& numberProcessed)
   550 	{
   577 	{
   551 		if (sockErr)
   578 		if (sockErr)
   552 		{
   579 		{
   553 			err = TCAPI_ERR_COMM_ERROR;
   580 			err = TCAPI_ERR_COMM_ERROR;
   554 			m_lastCommError = sockErr;
   581 			m_lastCommError = sockErr;
       
   582 			COMMLOGA1("CTcpComm::SendDataToPort getsockopt=%d\n", sockErr);
   555 			COMMLOGCLOSE();
   583 			COMMLOGCLOSE();
   556 			return err;
   584 			return err;
   557 		}
   585 		}
   558 	}
   586 	}
   559 
   587 
   578 			}
   606 			}
   579 		}
   607 		}
   580 		else if (selErr == SOCKET_ERROR)
   608 		else if (selErr == SOCKET_ERROR)
   581 		{
   609 		{
   582 			m_lastCommError = WSAGetLastError();
   610 			m_lastCommError = WSAGetLastError();
       
   611 			WSASetLastError(0);
       
   612 			COMMLOGA1("CTcpComm::SendDataToPort select(SOCKET_ERROR)=%d\n", m_lastCommError);
   583 			err = TCAPI_ERR_COMM_ERROR;
   613 			err = TCAPI_ERR_COMM_ERROR;
   584 		}
   614 		}
   585 		else if (selErr == 0) // timeout
   615 		else if (selErr == 0) // timeout
   586 		{
   616 		{
   587 			m_lastCommError = WSAGetLastError();
   617 			m_lastCommError = WSAGetLastError();
       
   618 			WSASetLastError(0);
       
   619 			COMMLOGA1("CTcpComm::SendDataToPort select(timeout)=%d\n", m_lastCommError);
   588 			err = TCAPI_ERR_COMM_ERROR;
   620 			err = TCAPI_ERR_COMM_ERROR;
   589 		}
   621 		}
   590 	}
   622 	}
   591 	COMMLOGA1("CTcpComm::SendDataToPort portReady=%d\n", portReady);
   623 	COMMLOGA1("CTcpComm::SendDataToPort portReady=%d\n", portReady);
   592 	if (portReady)
   624 	if (portReady)
   600 		{
   632 		{
   601 			nSent = send(m_socket, unsent, bytesRemaining, 0);
   633 			nSent = send(m_socket, unsent, bytesRemaining, 0);
   602 			if (nSent == SOCKET_ERROR)
   634 			if (nSent == SOCKET_ERROR)
   603 			{
   635 			{
   604 				int wsaErr = WSAGetLastError();
   636 				int wsaErr = WSAGetLastError();
       
   637 				WSASetLastError(0);
   605 				// ignore "would block" errors
   638 				// ignore "would block" errors
   606 				if (wsaErr != WSAEWOULDBLOCK)
   639 				if (wsaErr != WSAEWOULDBLOCK)
   607 				{
   640 				{
   608 					// TODO: error handling
   641 					// TODO: error handling
       
   642 					COMMLOGA1("CTcpComm::SendDataToPort send(SOCKET_ERROR)=%d\n", wsaErr);
   609 					m_lastCommError = wsaErr;
   643 					m_lastCommError = wsaErr;
   610 					err = TCAPI_ERR_COMM_ERROR;
   644 					err = TCAPI_ERR_COMM_ERROR;
   611 					break;
   645 					break;
   612 				}
   646 				}
   613 			}
   647 			}
   651 		m_numberBytes -= inMsgLength;
   685 		m_numberBytes -= inMsgLength;
   652 	}
   686 	}
   653 }
   687 }
   654 bool CTcpComm::IsConnectionEqual(ConnectData* pConn)
   688 bool CTcpComm::IsConnectionEqual(ConnectData* pConn)
   655 {
   689 {
   656 	if ((strcmp(pConn->tcpSettings.ipAddress, m_ConnectSettings->tcpSettings.ipAddress) == 0) &&
   690 	if ((strcmp(pConn->tcpSettings.ipAddress, m_ConnectSettings->tcpSettings.ipAddress) == 0))
   657 		(strcmp(pConn->tcpSettings.ipPort, m_ConnectSettings->tcpSettings.ipPort) == 0))
   691 	{
   658 	{
   692 		if ((strcmp(pConn->tcpSettings.ipPort, m_ConnectSettings->tcpSettings.ipPort) == 0))
   659 		return true;
   693 		{
       
   694 			// same port and same IP
       
   695 			return true;
       
   696 		}
       
   697 		else
       
   698 		{
       
   699 			// different port but same IP
       
   700 			return false;
       
   701 		}
   660 	}
   702 	}
   661 	else
   703 	else
   662 	{
   704 	{
       
   705 		// different IP
   663 		return false;
   706 		return false;
   664 	}
   707 	}
   665 }
   708 }
   666 
   709 
       
   710 int CTcpComm::WSAInit() 
       
   711 {
       
   712 	int wsaErr = 0;
       
   713 
       
   714 	COMMLOGOPEN();
       
   715 	COMMLOGS("CTcpComm::WSAInit\n");
       
   716 
       
   717 	WSADATA wsaData;
       
   718 	wsaErr = WSAStartup(MAKEWORD(2,2), &wsaData);
       
   719 
       
   720 	COMMLOGCLOSE();
       
   721 	return wsaErr;
       
   722 }
       
   723 
       
   724 void CTcpComm::WSAClose()
       
   725 {
       
   726 	COMMLOGOPEN();
       
   727 	COMMLOGS("CTcpComm::WSAClose\n");
       
   728 
       
   729 	WSACleanup();
       
   730 
       
   731 	COMMLOGCLOSE();
       
   732 }
       
   733