void PVMFLoopbackIOPort::Run() { //data should move through the ports only //when the node is active or flushing if (iNode->GetState() != EPVMFNodeStarted && !iNode->FlushPending()) return; //Process incoming messages if (!iWaiting && IncomingMsgQueueSize() > 0) { //dispatch the incoming data. if (ProcessIncomingMsg() != PVMFSuccess) iNode->ReportErrorEvent(PVMF_NODE_ERROR_EVENT_LAST, (OsclAny*)this); //re-schedule if more data if (!iWaiting && IncomingMsgQueueSize() > 0) { RunIfNotReady(); } } //Process outgoing messages if (OutgoingMsgQueueSize() > 0 && !IsConnectedPortBusy()) { //Send data to connected port PVMFStatus status = Send(); if (status != PVMFSuccess) iNode->ReportErrorEvent(PVMF_NODE_ERROR_EVENT_LAST, (OsclAny*)this); //Reschedule if there's more data to process... if (OutgoingMsgQueueSize() > 0 && !IsConnectedPortBusy()) { RunIfNotReady(); } } }
HRESULT CMBCBaseObj::NetCall_Read(CMBCSocket* pMBCSock, WPARAM wParam, LPARAM lParam ) { int nErr =WSAGETSELECTERROR(lParam); if (nErr != S_OK) { ASSERT(FALSE); return nErr; } int nEvent = WSAGETSELECTEVENT(lParam); SOCKET socRecv = (SOCKET)wParam; char szbuff[MAXRECVBUFF]; ZeroMemory(szbuff, MAXRECVBUFF); DWORD dwFlag = 0; int nHeadRead = recv(socRecv, szbuff, 5, 0); BOOL bSafeEnd = TRUE; while(nHeadRead == 5) { char* pBuff = szbuff; if (*pBuff == MBCCHECKSUM) { pBuff++; int nMsgLen = *((int*)pBuff); ASSERT(nMsgLen > 5 && nMsgLen < MAXINT); char* pRealUsedBuffer = szbuff; char* pLargeBuff = NULL; if (nMsgLen > MAXRECVBUFF) { //buffer not enough! pLargeBuff = new char[nMsgLen]; pRealUsedBuffer = pLargeBuff; memcpy(pLargeBuff, szbuff, 5); pBuff = pLargeBuff; pBuff ++; } pBuff += 4; int nMsgRead = recv(socRecv, pBuff, nMsgLen-5, 0); while(nMsgRead < nMsgLen -5) { int nTmpRead =recv(socRecv, pBuff, nMsgLen-5 - nMsgRead, 0); if (nTmpRead == SOCKET_ERROR) { break; } else { nMsgRead += nTmpRead; } } if (nMsgRead == nMsgLen-5) { int nMsgType = GetMBCMsgType(pRealUsedBuffer, nMsgLen); if (nMsgType != msgtype_NONE) { ProcessIncomingMsg(pMBCSock, nMsgType, pRealUsedBuffer, nMsgLen); //CFWriteLog2Wnd(m_hLogWnd, "msg ReadData, sock = %d, len = %d", (int)wParam, nMsgRead+5); } } else { ASSERT(FALSE); bSafeEnd = FALSE; } if (pLargeBuff) { delete[] pLargeBuff; pLargeBuff = NULL; } if (!bSafeEnd) { break; } } else { ASSERT(FALSE); bSafeEnd = FALSE; break; } nHeadRead = recv(socRecv, szbuff, 5, 0); } if (!bSafeEnd) { //clean all recvdata ASSERT(FALSE); int nRead = recv(socRecv, szbuff, MAXRECVBUFF, 0); while(nRead != SOCKET_ERROR) { nRead = recv(socRecv, szbuff, MAXRECVBUFF, 0); } //CFWriteLog2Wnd(m_hLogWnd, "msg ReadData error, data in sock buffer will clear!!! sock = %d", (int)wParam); return E_FAIL; } return S_OK; }