|
|
|
@ -55,15 +55,21 @@ int TTcpSocket::tcpGetSockID()
|
|
|
|
|
//关闭socket
|
|
|
|
|
int TTcpSocket::tcpCloseSocket(int sockfd)
|
|
|
|
|
{
|
|
|
|
|
if(sockfd > 0) {
|
|
|
|
|
if (sockfd > 0) {
|
|
|
|
|
vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d ", sockfd);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
//if(_close(sockfd) == -1)
|
|
|
|
|
if(shutdown(sockfd, 2) == -1)
|
|
|
|
|
#else
|
|
|
|
|
if(close(sockfd) == -1)
|
|
|
|
|
#endif
|
|
|
|
|
vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d return:%d:%s",sockfd, errno, strerror(errno));
|
|
|
|
|
if (shutdown(sockfd, 2) == -1)
|
|
|
|
|
#else
|
|
|
|
|
if (shutdown(sockfd, SHUT_RDWR) == -1)
|
|
|
|
|
#endif
|
|
|
|
|
vPrtLogMsg(LOG_WARNG, RET_FAIL, "_close sockid=%d return:%d:%s", sockfd, errno, strerror(errno));
|
|
|
|
|
else
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
closesocket(sockfd);
|
|
|
|
|
#else
|
|
|
|
|
close(sockfd);
|
|
|
|
|
#endif
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0 ;
|
|
|
|
@ -396,7 +402,8 @@ int TTcpSocket::tcpRecvBuffer(int sockid, char* pBuffer,int nMaxLength, int time
|
|
|
|
|
struct timeval st_TimeOut;
|
|
|
|
|
int isel = 0;
|
|
|
|
|
|
|
|
|
|
if( sockid <= 0 || pBuffer == NULL) return -1;
|
|
|
|
|
// if( sockid <= 0 || pBuffer == NULL) return -1;
|
|
|
|
|
|
|
|
|
|
while(iTop != nMaxLength)
|
|
|
|
|
{
|
|
|
|
|
st_TimeOut.tv_sec = timeout ;
|
|
|
|
|