本文介绍了关于WSAECONNRESET的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当客户端中的recv函数返回WSAECONNRESET错误时,我尝试再次连接服务器。但它总是失败.Who
可以帮我解决客户端中WSAECONNRESET的错误。谢谢
when the recv function in client return WSAECONNRESET error,I try connect the server again.But it always failed.Who
can help me solve the error of WSAECONNRESET in client.Thanks
/**
* receive a packet from souce,then enter it into queue
* @brief 供ctrl起线程调用,出错时上报错误码
* @param[OUT] pstDataPacket 。
* @return 参考CISourceFilter::readDataPacket注释。
*/
ULONG CMsgMutualTcp::receiveMsg(CMsgData &stMsgData)
{
/* 收包的返回值 */
LONG lRecvLen = -1;
ULONG ulRet = ERR_COMMON_FAIL;
/* 判断tcp连接是否已经创建,如果没有创建则创建tcp连接 */
if (BOOL_FALSE == m_bTcpConEstablished)
{
ulRet = createTcpConnect();
switch (ulRet)
{
/* 表示连接tcp成功 */
case ERR_COMMON_SUCCEED:
{
m_bTcpConEstablished = BOOL_TRUE;
m_bReBldSocketStatus = BOOL_FALSE;
setKeepLive();
return ERR_COMMON_SUCCEED;
}
case ERR_RECEIVE_MEDIA_TIMEOUT:
{
// Sleep(50);
/* 表示超时没有创建tcp链接,属于正常情况 */
return ERR_RECEIVE_MEDIA_TIMEOUT;
}
default:
{
/* 在创建tcp连接过程中产生了错误 */
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__,"failed to create tcp connect.\n");
return ERR_COMMON_FAIL;
}
}
}
if (0 == m_ulKeepLiveTimerID)
{
/* 启动一个定时器定时发送引流包 */
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__," start sending msg pkt timer.\n");
m_stLiveMsg.stMsgHdr.usMessageFlag = MSG_VMP_DATA_HEAD_FLAG;
m_stLiveMsg.stMsgHdr.ucVersion = 2; //版本号, 统一填2
m_stLiveMsg.stMsgHdr.ucSubVersion = 0; //子版本号, 统一填0
m_stLiveMsg.stMsgHdr.ucType = 0; //0表示请求消息
m_stLiveMsg.stMsgHdr.usCommand = VMP_MSG_USER_KEEPLIVE; //待定
m_stLiveMsg.stMsgHdr.usStatus = 0; //
m_stLiveMsg.stMsgHdr.ulSeqNum = sequencePlus(); //待定
m_stLiveMsg.stMsgHdr.ulSrcModId = 0; //
m_stLiveMsg.stMsgHdr.ulDstModId = 0; //待定
m_stLiveMsg.stMsgHdr.ulFromHandle = 0; //
m_stLiveMsg.stMsgHdr.ulToHandle = 0; //待定
m_stLiveMsg.stMsgHdr.ulContentLength = sizeof(IE_USER_LOG_INFO_S); //vmp消息的总长度
m_stLiveMsg.stMsgHdr.ucFeature = 0; //小端模式
m_stLiveMsg.stUserLogInfo.stIEHdr.usIEID = IE_USER_LOG_INFO;
m_stLiveMsg.stUserLogInfo.stIEHdr.usIEBodyLen = sizeof(IE_USER_LOG_INFO_S) - sizeof(VMP_IE_HEADER_S);
strncpy(m_stLiveMsg.stUserLogInfo.szUserName, m_strUserName.c_str(), (sizeof(m_stLiveMsg.stUserLogInfo.szUserName) - 1));
m_stLiveMsg.stUserLogInfo.ulUserLoginHandle = m_ulLoginID;
m_stLiveMsg.stUserLogInfo.stUserLoginIP.usDomainType = MSG_AF_INET;
m_stLiveMsg.stUserLogInfo.stUserLoginIP.ulIpv4Addr = m_ulLocalIP;
m_stTimerParam.hSocket = m_hSocket;
m_stTimerParam.ulDstIP = m_ulSrcIP;
m_stTimerParam.usDstPort = m_usSrcPort;
sendKeepLivePktCallback(this);
m_ulKeepLiveTimerID = UWARE_XP_StartIndependTimer(OCX_KEEPLIVE_PACKET_SEND_INTERVAL,
sendKeepLivePktCallback,
this);
if (0 == m_ulKeepLiveTimerID)
{
m_ucLiveFailCount = MSG_LIVE_FAIL_COUNT;
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__," startIndependTimer return error.\n");
return ERR_COMMON_FAIL;
}
sendBookNotifyPkt();
}
if (OCX_INVALID_HANDLE == m_hSocket)
{
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__,"invalid handle of socket\n");
return ERR_COMMON_INVALID_PARAM;
}
OCX_POLLFD_S stPollFD = {0};
stPollFD.lFd = (LONG) m_hSocket;
stPollFD.usEvents = POLLIN;
stPollFD.usRevents = 0;
LONG lRet = OCX_poll(&stPollFD, 1, OCX_NETSTREAM_TIMEOUT_MAX);
if (0 == lRet)
{
if (0 == g_tick)
{
g_tick = GetTickCount();
}
else
{
if (GetTickCount() - g_tick > 30000)
{
ulRet = retryConnectServer();
if ( ERR_COMMON_SUCCEED == ulRet)
{
g_tick = 0;
m_bConnenctStatus = BOOL_TRUE;
FRAME_writeLog("CMsgMutualTcp::sendKeepLivePktCallback",__LINE__,"The RetryConnect has succeeded.\n");
}
else
{
m_bConnenctStatus = BOOL_FALSE;
//FRAME_writeLog("CMsgMutualTcp::sendKeepLivePktCallback",__LINE__,"The RetryConnect has failed.\n");
}
}
}
//OCX_MPM_LOG1(UWARE_DEBUG, ERR_MPM_RECEIVE_MEDIA_TIMEOUT, "%s poll time out.", STR_PORT_ID(m_ulChannelID));
return ERR_COMMON_FAIL;
}
else if (0 > lRet)
{
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__,"poll failed, system errcode is %ld, handled as time out.\n", GetLastError());
/* begin add by shiyouhua04562 VVD58736 */
(VOID)Sleep(OCX_NETSTREAM_TIMEOUT_MAX);
/* end add by shiyouhua04562 VVD58736 */
return ERR_COMMON_FAIL;
/* END: Modified by jinqifeng 06715, 2010/3/15 问题单号:VVD54479 */
}
g_tick = 0;
m_stRecvAddr.sin_family = AF_INET;
m_stRecvAddr.sin_addr.s_addr = m_ulSrcIP;
m_stRecvAddr.sin_port = m_usSrcPort;
/* 从指定的socket上接收媒体数据 */
lRecvLen = recv(m_hSocket, (CHAR *)stMsgData.aucBuffer, stMsgData.lDataLength, 0);
if (0 == lRecvLen)
{
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__,"Client connecttion closed");
//ULONG retryStatus = retryConnectServer();
return ERR_COMMON_FAIL;
}
else if(SOCKET_ERROR == lRecvLen)
{
DWORD errCode = GetLastError();
FRAME_writeLog("CMsgMutualTcp::receiveMsg",__LINE__,"recv is fail %ld\n", errCode);
ULONG retryStatus = retryConnectServer();
if ( ERR_COMMON_SUCCEED == retryStatus)
{
Sleep(10);
m_bConnenctStatus = BOOL_TRUE;
FRAME_writeLog("CMsgMutualTcp::sendKeepLivePktCallback",__LINE__,"The RetryConnect has succeeded.\n");
}
else
{
m_bConnenctStatus = BOOL_FALSE;
FRAME_writeLog("CMsgMutualTcp::sendKeepLivePktCallback",__LINE__,"The RetryConnect has failed.\n");
}
return ERR_COMMON_FAIL;
}
else
{
/* 先设置包的大小,否则校验引流报文错误 */
stMsgData.lDataLength = lRecvLen;
}
return ERR_COMMON_SUCCEED;
}
推荐答案
这篇关于关于WSAECONNRESET的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!