int32_t File::read(char* buf,size_t len) { DWORD nRead(0); if(::ReadFile(impl.get(),buf,len,&nRead,NULL)==FALSE) { flags.add(FLAG_READER_FAILBIT); System::CheckError("File::Read Error"); return -1; } return nRead; }
int recv(char* buf,int len) { DWORD nRead(0); if(::ReadFile(hReader,buf,len,&nRead,NULL)==FALSE) { if(::GetLastError()==0x6d) // pipe closed { return 0; } flags.add(FLAG_READER_FAILBIT); System::CheckError("File::Read Error"); return -1; } return nRead; }
bool wxGISLocalServerConnection::ProcessInputNetMessage(void) { if(!m_pSock || m_pSock->IsDisconnected()) { return false; } if (m_pSock->WaitForRead(0, WAITFOR)) { wxJSONValue value; wxJSONReader reader; #ifdef USE_STREAMS wxSocketInputStream in(*m_pSock); int numErrors = reader.Parse( in, &value ); #ifdef _DEBUG //wxString sOut; //wxJSONWriter writer(wxJSONWRITER_NONE); //writer.Write(value, sOut); //wxLogMessage(sOut); #endif // _DEBUG #else RtlZeroMemory(m_Buffer, sizeof(m_Buffer)); wxUint32 nRead(0); nRead = m_pSock->ReadMsg(m_Buffer, BUFF_SIZE).LastCount(); wxString sIn(m_Buffer, nRead); #ifdef _DEBUG wxLogDebug(wxString::Format(wxT("rcv:%d bits, %s"), nRead, sIn)); #endif // _DEBUG //m_pSock->SetTimeout(SLEEP); //m_pSock->SetFlags(wxSOCKET_WAITALL | wxSOCKET_BLOCK); int numErrors = reader.Parse( sIn, &value ); #endif // USE_STREAMS if ( numErrors > 0 ) { const wxArrayString& errors = reader.GetErrors(); wxString sErrMsg(_("Invalid input message")); for (size_t i = 0; i < errors.GetCount(); ++i) { wxString sErr = errors[i]; sErrMsg.Append(wxT("\n")); sErrMsg.Append(wxString::Format(wxT("%d. %s"), i, sErr.c_str())); } wxLogVerbose(sErrMsg); return false; } wxNetMessage msg(value); if(!msg.IsOk()) { wxLogVerbose(_("Invalid input message")); return false; } PostEvent(new wxGISNetEvent(m_nUserId, wxGISNET_MSG, msg)); return true; } return false; }