void Main_OnDisplay( HWND hWnd ) { TCHAR strAppName[MAX_PATH]={0}; TCHAR strBlock[10]={0}; TCHAR* pEnd=nullptr; TABLEDLG_DATA tblDlgData={0}; // Get the appname, the selected block ID & the selected // language. Create the string block. If the block creation is successful, // bring up the table dialog box. CWindow wnd(hWnd); if (!wnd.GetDlgItemText(IDC_EDIT_APPNAME, strAppName, MAX_PATH)) { DisplayMsg(hWnd, IDS_INVALIDAPPNAME); return; } CComboBox combo(wnd.GetDlgItem(IDC_COMBO_LANGUAGES)); int nSel = combo.GetCurSel(); if( CB_ERR == nSel ) { DisplayMsg(hWnd, IDS_INVALIDLANGUAGE); return; } if (!wnd.GetDlgItemText(IDC_EDIT_BLOCKID, strBlock, _countof(strBlock))) { DisplayMsg(hWnd, IDS_INVALIDBLOCKID); return; } UINT nBlockID = _tcstoul(strBlock, &pEnd, 10); if( *pEnd != 0 ) { DisplayMsg(hWnd, IDS_INVALIDBLOCKID); return; } HSTRBLOCK hStrBlock = GetStringBlock(strAppName, nBlockID, s_langInfo[nSel].wLangID); if( nullptr == hStrBlock ) { DisplayStatus(hWnd, GetStringBlockError()); return; } // Show up the table dialog-box that displays the string block. tblDlgData.strAppName = strAppName; tblDlgData.nBlockID = nBlockID; tblDlgData.wStrID = static_cast<WORD>(s_langInfo[nSel].nStrID); tblDlgData.hStrBlock = hStrBlock; DialogBoxParam(GetAppInstance(), MAKEINTRESOURCE(IDD_DIALOG_TABLE), hWnd, Table_DlgProc, reinterpret_cast<LPARAM>(&tblDlgData)); // Delete the string block. DeleteStringBlock(hStrBlock); }
/////////////////////////////////////////////////////////////////// // CheckForRequest // See SocketPort.h for details /////////////////////////////////////////////////////////////////// int CSocketPort::CheckForRequest(void) { char Buffer[128]; struct timeval Timeout; Timeout.tv_sec = 0; Timeout.tv_usec = SELECT_TIMEOUT_MICROSECS; fd_set readfds; FD_ZERO(&readfds); FD_SET(m_hLocalSrvr, &readfds); int ret = select(m_hLocalSrvr+1, &readfds, NULL, NULL, &Timeout); if( ret == SOCKET_ERROR ) { sprintf(Buffer, "select error in check for request: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(Buffer); return 1; } if ( !FD_ISSET(m_hLocalSrvr, &readfds)) return 2; m_hDriver = accept(m_hLocalSrvr,(sockaddr*)&m_RemoteAddr, &m_SockAddrLen); if (m_hDriver == INVALID_SOCKET) { sprintf(Buffer, "failure accepting connection on \"%s:%d\" (%d)", m_SrvIPAddr, m_SrvPort, this->GetLastError()); DisplayMsg( Buffer ) ; return 3; } else { // //Provo ad attivare il keep alive con invio ad un minuto // int on = 1; // setsockopt ( m_hDriver, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof ( on ) ); // int firstKeepAlive = 60, nextKeepAlive=5 ; // //Il primo keepalive viene mandato dopo un minuto di inattivita' // setsockopt ( m_hDriver, IPPROTO_TCP, TCP_KEEPIDLE, &firstKeepAlive, sizeof ( firstKeepAlive ) ); // //Se non c'è risposta invio un messaggio ogni 5 secondi // setsockopt ( m_hDriver, IPPROTO_TCP, TCP_KEEPINTVL, &nextKeepAlive, sizeof ( nextKeepAlive ) ); m_IsConnected = 1 ; sprintf(Buffer, "Accepted connection on \"%s:%d\"", m_SrvIPAddr, m_SrvPort); DisplayMsg( Buffer ); return 0; } }
////////////////////////////////////////////////////////////////////// // Disconnect function, see .h file for description ////////////////////////////////////////////////////////////////////// bool CSocketPort::Disconnect() { bool retval = true; char buf[512] ; buf[0] = '\0' ; if(m_IsConnected == false) { DisplayMsg("Socket already Closed"); } else { if(m_hDriver == INVALID_SOCKET) { DisplayMsg("socket invalid in Disconnect") ; retval = false; } else { if( m_ShutDownFlag ) { if( shutdown( m_hDriver, SD_BOTH ) == SOCKET_ERROR ) { sprintf(buf, "Error Shutting Down Server: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); retval = false; } } flushInFlow(); if( closesocket( m_hDriver ) == SOCKET_ERROR) { sprintf(buf, "Error Closing socket: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); retval = false; } m_hDriver = INVALID_SOCKET ; } } m_IsConnected = false ; DisplayMsg("Socket Closed"); return retval ; }
//******************************************************************************* // Method : CTestAppConsole::ProcessMainInput() // Purpose : Obtain user's option and decide which test case to run next. // Parameters : // Return Value: //******************************************************************************* void CTestAppConsole::ProcessMainInput() { TBuf<80> line; GetStringFromConsole(line); if ( line.Length() > 0 ) { TChar inputChar = line[0]; TInt err( KErrNone ); TBool testsRun( ETrue ); switch( inputChar ) { case '1': err = RunInterfaceTests(); break; case '2': err = RunAudioControlTests(); break; case '3': err = RunRtcpTests(); break; case '4': err = RunDtmfTests(); break; case '5': err = RunAsyncFeatureTests(); break; case 's': err = RunSecureTests(); break; case '0': testsRun = EFalse; CActiveScheduler::Stop(); break; default: testsRun = EFalse; DisplayMsg( KTxtWrongOption ); break; } if ( err ) { iConsole->Printf( _L("Some tests failed: %d, check logs\n"), err ); RDebug::Print( _L("\nSome tests failed: %d, check logs\n"), err ); } else if ( testsRun ) { iConsole->Printf( _L( "ALL TESTS OK\n" ) ); RDebug::Print( _L( "\nAll tests OK\n" ) ); } else { } } // Ready to get next input option. DoRead(); }
//******************************************************************************* // Method : CTestAppConsole::ProcessMainInput() // Purpose : Obtain user's option and decide which test case to run next. // Parameters : // Return Value: //******************************************************************************* void CTestAppConsole::ProcessMainInput() { TChar inputChar = iConsole->KeyCode(); switch(inputChar) { case '1': RunTest1(); break; case '2': //RunTest2(); break; case '9': CActiveScheduler::Stop(); Stop(); break; default: _LIT(KTxtWrongOption, "Wrong Option! Try Again."); DisplayMsg(KTxtWrongOption); break; } // Ready to get next input option. DoRead(); }
INT Help( IN INT argc, IN PWSTR argv[] ) /*++ Routine Description: This routine lists out the various command supported by the tool. Arguments: None Return Value: None --*/ { DisplayMsg( MSG_USAGE ); return EXIT_CODE_SUCCESS; }
////////////////////////////////////////////////////////////////////// // Shutdown Server function, see .h file for description ////////////////////////////////////////////////////////////////////// void CSocketPort::ShutdownServer() { char buf[512];//Temporary buffer used for messages if (m_hLocalSrvr != INVALID_SOCKET) { if( m_ShutDownFlag ) { if( shutdown( m_hLocalSrvr, SD_BOTH ) == SOCKET_ERROR ) { sprintf(buf, "Shutting Down LocalSrvr socket I got: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf) ; } else { sprintf(buf, "Local Server on: %s %d -- Shutdown Complete", m_SrvIPAddr, m_SrvPort ); DisplayMsg(buf) ; } } if( closesocket(m_hLocalSrvr) == SOCKET_ERROR) { sprintf(buf, "warning Closing LocalSrvr socket: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf) ; } m_hLocalSrvr = INVALID_SOCKET ; } }
//******************************************************************************* void CTestAppConsole::Stop() { #ifdef DEBUG_INFO RDebug::Print (_L ("------The End------\n")); #endif DisplayMsg(_L("------The End------")); // iConsole->Getch(); }
/* * TCPmsgd - MSG server */ int TCPmsgd(int fd) { char rbuf[BUFSIZE]; char wbuf[BUFSIZE]; int cc; #ifdef TCPMSGD_DEBUG MESSAGE_U_T *msgptr; #endif /* main loop */ while (cc = read(fd, rbuf, sizeof rbuf)) { if (cc < 0) { errexit("msgd read: %s\n", strerror(errno)); } #ifdef TCPMSGD_DEBUG msgptr = (MESSAGE_U_T *)&rbuf[0]; DisplayMsg( msgptr, "from client:" ); #endif cc = sizeof(MESSAGE_U_T); memcpy(wbuf, rbuf, cc); #ifdef TCPMSGD_DEBUG msgptr = (MESSAGE_U_T *)&wbuf[0]; DisplayMsg( msgptr, "to client:" ); #endif if (write(fd, wbuf, cc) < 0) { errexit("msgd write: %s\n", strerror(errno)); } } return 0; }
//******************************************************************************* // Method : CTestAppConsole::GetAddrFromConsole() // Purpose : // Parameters : // Return Value: //******************************************************************************* TKeyCode CTestAppConsole::GetStringFromConsole(TDes &aAddr) { // Get a line from console TKeyCode input = EKeyNull; const TInt start_pos = iConsole->WhereX(); aAddr.Zero(); // loop until descriptor full or EKeyEnter or EKeyEscape entered do { // get one character input = iConsole->Getch(); // process it if(input == EKeyBackspace || input == EKeyDelete) { // backspace or delete if(iConsole->WhereX() > start_pos) { iConsole->SetPos(iConsole->WhereX() - 1); iConsole->ClearToEndOfLine(); if(aAddr.Length() > 0) { aAddr.SetLength(aAddr.Length() - 1); } } } else { // other than backspace or delete TChar ch(input); if(ch.IsPrint()) { aAddr.Append(ch); iConsole->Printf(_L("%c"), input); } } } while(aAddr.Length() < aAddr.MaxLength() && input != EKeyEnter && input != EKeyEscape); DisplayMsg(KTxtLineBreak); return input; }
//******************************************************************************* // Method : CTestAppConsole::ProcessMainInput() // Purpose : Obtain user's option and decide which test case to run next. // Parameters : // Return Value: //******************************************************************************* void CTestAppConsole::ProcessMainInput() { TChar inputChar = iConsole->KeyCode(); switch(inputChar) { case '1': __UHEAP_MARK; RunTest1(); __UHEAP_MARKEND; break; case '3': __UHEAP_MARK; RunTest3(); __UHEAP_MARKEND; break; case '4': __UHEAP_MARK; RunTest4(); __UHEAP_MARKEND; break; case '5': __UHEAP_MARK; RunTest5(); __UHEAP_MARKEND; break; case '6': RunTest6(); break; case '9': CActiveScheduler::Stop(); break; default: _LIT(KTxtWrongOption, "Wrong Option! Try Again."); DisplayMsg(KTxtWrongOption); break; } // Ready to get next input option. DoRead(); }
void CMUSHclientDoc::MXP_collected_entity (void) { m_strMXPstring.TrimLeft (); m_strMXPstring.TrimRight (); // case insensitive // m_strMXPstring.MakeLower (); // count them m_iMXPentities++; // TRACE1 ("MXP collected entity %s\n", (LPCTSTR) m_strMXPstring); MXP_error (DBG_ALL, msgMXP_CollectedEntity, TFormat ("MXP entity: &%s;", (LPCTSTR) m_strMXPstring)); if (!IsValidName (m_strMXPstring) && m_strMXPstring.Left (1) != "#") { MXP_error (DBG_ERROR, errMXP_InvalidEntityName, TFormat ("Invalid MXP entity name \"%s\" supplied.", m_strMXPstring)); return; } // see if we know of this entity CString strEntityContents = MXP_GetEntity (m_strMXPstring); if (!strEntityContents.IsEmpty ()) { // if the entity happens to be < & > etc. don't reprocess it m_bMXP = false; DisplayMsg (strEntityContents, strEntityContents.GetLength (), 0); m_bMXP = true; } } // end of CMUSHclientDoc::MXP_collected_entity
/////////////////////////////////////////////////////////////////// // flushInFlow // See SocketPort.h for details /////////////////////////////////////////////////////////////////// bool CSocketPort::flushInFlow() { bool retval = true ; struct timeval Timeout; Timeout.tv_sec = 0; Timeout.tv_usec = SELECT_TIMEOUT_MICROSECS; fd_set readfds; FD_ZERO(&readfds); int nCharsRead = 1; // DisplayMsg( "flushing input flow" ); while( nCharsRead ) { FD_ZERO(&readfds); FD_SET(m_hDriver, &readfds); int ret = select(m_hDriver+1, &readfds, NULL, NULL, &Timeout); if( ret == SOCKET_ERROR ) { char buf[64] ; sprintf(buf, "select error in flushInFlow: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); return false; } if ( FD_ISSET(m_hDriver, &readfds)) { char Buffer[128]; nCharsRead = recv(m_hDriver, Buffer, 128, 0 ) ; if( nCharsRead == SOCKET_ERROR )break; }else break ; } return retval ; }
void CMUSHclientDoc::Simulate(LPCTSTR Text) { DisplayMsg(Text, strlen (Text), 0); } // end of CMUSHclientDoc::Simulate
TST_tpRetCode TST_TestSpecific :: PerformSpecificTest( char * Command ) { int numRead = -1 ; // Handle verify data structure if ( strcmp( Command , VerifyCmd ) == 0 ) { return TST_RetCodeNotImplemented ; } // end selection: Handle verify data structure // Test Compare hexadecimal else if ( strcmp( Command , CompareHexCmd ) == 0 ) { int sizString = -1 ; int sizHex = -1 ; char Str[ TAL_dimBuffer ] ; char Hex[ TAL_dimBuffer ] ; numRead = TST_pReader->ReadCommandLine( "ss" , &sizString , Str , &sizHex , Hex ) ; if ( numRead != 2 ) { return TST_RetCodeParmError ; } /* if */ return Compare( Str , Hex , "Incorrect hexadecimal compare" ) ; } // end selection: Test Compare hexadecimal // Trigger system exception else if ( strcmp( Command , ExcSysCmd ) == 0 ) { MSG_Message * pMsg = NULL ; pMsg->AssembleMessage( ) ; return TST_RetCodeFailure ; } // end selection: Trigger system exception // Corrupt data spaces list else if ( strcmp( Command , CorruptCmd ) == 0 ) { char * pChar = new char[ 10 ] ; int Mode = -1 ; numRead = TST_pReader->ReadCommandLine( "i" , &Mode ) ; if ( numRead != 1 ) { return TST_RetCodeParmError ; } /* if */ switch ( Mode ) { case 1 : pChar[ -1 ] = 0 ; break ; case 2 : pChar[ -12 ] = '\x0FF' ; break ; default : pChar[ 10 ] = 0 ; break ; } /* switch */ return TST_RetCodeOK ; } // end selection: Corrupt data spaces list // Log space else if ( strcmp( Command , LogSpaceCmd ) == 0 ) { char Line[ TAL_dimMsg + 1 ] ; Line[ 0 ] = 0 ; numRead = TST_pReader->ReadCommandLine( "s" , Line ) ; if ( numRead != 1 ) { return TST_RetCodeParmError ; } /* if */ Line[ TAL_dimMsg ] = 0 ; if ( Line[ 0 ] == '.' ) { Line[ 0 ] = 0 ; } /* if */ if ( Line[ 0 ] == '!' ) { GLB_GetGlobal( )->GetEventLogger( )->LogDataSpace( 17 , GLB_GetGlobal( )->GetEventLogger( )) ; } else { GLB_GetGlobal( )->GetEventLogger( )->LogDataSpace( strlen( Line ) , Line ) ; } /* if */ return TST_RetCodeOK ; } // end selection: Log space // Test parameter lists else if ( strcmp( Command , ParmListCmd ) == 0 ) { char ParmBuffer[ 60 ] ; TST_tpParmCondRet CondRet = TST_ParmCondRetOK ; while ( CondRet == TST_ParmCondRetOK ) { CondRet = ReadParameterCommand( ParmBuffer , 50 ) ; DisplayMsg( "+++" , "Parameter command: " , ParmBuffer ) ; } /* while */ if ( CondRet == TST_ParmCondRetEnd ) { DisplayMsg( "+++" , "End of parameter list found" ) ; } /* if */ return TST_RetCodeOK ; } // end selection: Test parameter lists // Test failure while some mutant is being sought to be killed else if ( strcmp( Command , TestMutantCmd ) == 0 ) { return Compare( TST_GetIdMutant( ) , 0 , "Mutant killed." ) ; } // end selection: Test failure while some mutant is being sought to be killed return TST_RetCodeUnknown ; } // End of function: TTST !Perform specific actions
////////////////////////////////////////////////////////////////////// // Read function, see .h file for description ////////////////////////////////////////////////////////////////////// unsigned long CSocketPort::Read(char *Block, int MaxReadBlockLength) { char Buffer[128]; struct timeval Timeout; Timeout.tv_sec = 0; Timeout.tv_usec = SELECT_TIMEOUT_MICROSECS; fd_set readfds; FD_ZERO(&readfds); int ret = 0; int nCharsRead = 0; if( m_SockType == SERVER_SOCKET && m_IsConnected == false ) { CheckForRequest() ; } if( m_IsConnected == false ) return 0L; if (m_hDriver == INVALID_SOCKET) { sprintf(Buffer,"socket invalid in Read()\n" ) ; DisplayMsg(Buffer); m_IsConnected = false; return 0L; } //Check if it is a dummy read if (Block == NULL) return 0L; if (HasConnectionDropped()) { Disconnect(); return 0; } //Check for incoming messages FD_SET(m_hDriver, &readfds); ret = select(m_hDriver+1, &readfds, NULL, NULL, &Timeout); if( ret == SOCKET_ERROR ) { sprintf(Buffer, "select error in read: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(Buffer); return 0L; } if ( FD_ISSET(m_hDriver, &readfds)) { //Get incoming messages GetCharsToRead( &nCharsRead ); if (nCharsRead != 0) { //Ok, it's a valid message nCharsRead = recv(m_hDriver, Block, MaxReadBlockLength, 0 ) ; } else { //The socket has been closed from the remote FD_CLR(m_hDriver, &readfds); Disconnect(); DisplayMsg( "connection closed by the remote" ); nCharsRead = 0 ; } } return (unsigned long)nCharsRead; }
void CMUSHclientDoc::Hyperlink_Helper (LPCTSTR Action, LPCTSTR Text, LPCTSTR Hint, LPCTSTR TextColour, LPCTSTR BackColour, BOOL URL, BOOL NoUnderline) { // return if attempt to do tell (or note) before output buffer exists if (m_pCurrentLine == NULL || m_pLinePositions == NULL) return; // don't muck around if empty message if (Action [0] == 0) return; // If current line is not a note line, force a line change (by displaying // an empty string), so that the style change is on the note line and not // the back of the previous line. This has various implications, including // the way that "bleed colour to edge" will work. Otherwise it bleeds the // forthcoming note colour to the edge of the previous (mud) line. if ((m_pCurrentLine->flags & NOTE_OR_COMMAND) != COMMENT) DisplayMsg ("", 0, COMMENT); COLORREF forecolour = m_iHyperlinkColour, backcolour; if (m_bNotesInRGB) backcolour = m_iNoteColourBack; else { if (m_iNoteTextColour == SAMECOLOUR) { if (m_bCustom16isDefaultColour) backcolour = m_customback [15]; else backcolour = m_normalcolour [BLACK]; } // not same colour else backcolour = m_customback [m_iNoteTextColour]; } SetColour (TextColour, forecolour); SetColour (BackColour, backcolour); // change to underlined hyperlink AddStyle (COLOUR_RGB | (URL ? ACTION_HYPERLINK : ACTION_SEND) | (NoUnderline ? 0 : UNDERLINE), forecolour, backcolour, 0, GetAction (Action, Hint [0] == 0 ? Action : Hint, "")); // output the link text if (strlen (Text) > 0) AddToLine (Text, COMMENT); else AddToLine (Action, COMMENT); // add another style to finish the hyperlink if (m_bNotesInRGB) AddStyle (COLOUR_RGB, m_iNoteColourFore, m_iNoteColourBack, 0, NULL); else { if (m_iNoteTextColour == SAMECOLOUR) { if (m_bCustom16isDefaultColour) AddStyle (COLOUR_CUSTOM, 15, BLACK, 0, NULL); else AddStyle (COLOUR_ANSI, WHITE, BLACK, 0, NULL); } // not same colour else AddStyle (COLOUR_CUSTOM, m_iNoteTextColour, BLACK, 0, NULL); } // not RGB } // end of CMUSHclientDoc::Hyperlink_Helper
void CMUSHclientDoc::Tell(LPCTSTR Message) { // don't muck around if empty message if (Message [0] == 0) return; // if output buffer doesn't exist yet, remember note for later if (m_pCurrentLine == NULL || m_pLinePositions == NULL) { COLORREF fore = m_iNoteColourFore, back = m_iNoteColourBack; // need to do this in case a normal Note follows a ColourNote ... // select correct colour, if needed, from custom pallette if (!m_bNotesInRGB) { if (m_iNoteTextColour >= 0 && m_iNoteTextColour < MAX_CUSTOM) { fore = m_customtext [m_iNoteTextColour]; back = m_customback [m_iNoteTextColour]; } // end of notes in custom colour } m_OutstandingLines.push_back (CPaneStyle (Message, fore, back, m_iNoteStyle)); return; } // If current line is not a note line, force a line change (by displaying // an empty string), so that the style change is on the note line and not // the back of the previous line. This has various implications, including // the way that "bleed colour to edge" will work. Otherwise it bleeds the // forthcoming note colour to the edge of the previous (mud) line. if ((m_pCurrentLine->flags & NOTE_OR_COMMAND) != COMMENT) DisplayMsg ("", 0, COMMENT); CStyle * pOldStyle = NULL; if (!m_pCurrentLine->styleList.IsEmpty ()) pOldStyle = m_pCurrentLine->styleList.GetTail (); if (m_bNotesInRGB) { // change style if we need to if (!(pOldStyle && (pOldStyle->iFlags & COLOURTYPE) == COLOUR_RGB && pOldStyle->iForeColour == m_iNoteColourFore && pOldStyle->iBackColour == m_iNoteColourBack && (pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle )) AddStyle (COLOUR_RGB | m_iNoteStyle, m_iNoteColourFore, m_iNoteColourBack, 0, NULL); } // end or RGB notes else { // finally found Poremenos's bug - he was doing a world.colournote // with the note colour as -1 (65535) which gave an access violation if (m_iNoteTextColour == SAMECOLOUR) { // change style if we need to if (!(pOldStyle && (pOldStyle->iFlags & COLOURTYPE) == COLOUR_ANSI && pOldStyle->iForeColour == WHITE && pOldStyle->iBackColour == BLACK && (pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle )) AddStyle (COLOUR_ANSI | m_iNoteStyle, WHITE, BLACK, 0, NULL); } else { // change style if we need to if (!(pOldStyle && (pOldStyle->iFlags & COLOURTYPE) == COLOUR_CUSTOM && pOldStyle->iForeColour == m_iNoteTextColour && pOldStyle->iBackColour == BLACK && (pOldStyle->iFlags & TEXT_STYLE) == m_iNoteStyle )) AddStyle (COLOUR_CUSTOM | m_iNoteStyle, m_iNoteTextColour, BLACK, 0, NULL); } // not samecolour } // end of palette notes DisplayMsg (Message, strlen (Message), COMMENT); } // end of CMUSHclientDoc::Tell
void CheckKeys (void) { //extern id0_boolean_t autofire; if (screenfaded) // don't do anything with a faded screen return; #if 0 // // pause key wierdness can't be checked as a scan code // if (Paused) { CenterWindow (8,3); US_PrintCentered ("PAUSED"); VW_UpdateScreen (); // SD_MusicOff(); IN_Ack(); // SD_MusicOn(); Paused = false; // (REFKEEN) Minor difference from vanilla Catacomb if (MousePresent) BE_ST_GetEmuAccuMouseMotion(NULL, NULL); // Clear accumulated mouse movement //if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement } else if (Keyboard[sc_Enter]) // P = pause with no screen disruptioon { // SD_MusicOff(); DisplaySMsg("PAUSED",NULL); IN_Ack(); // SD_MusicOn(); // (REFKEEN) Minor difference from vanilla Catacomb if (MousePresent) BE_ST_GetEmuAccuMouseMotion(NULL, NULL); // Clear accumulated mouse movement //if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement } else if (Keyboard[sc_S]) { id0_char_t *Text[] = {{"Slow Mode ON"},{"Slow Mode OFF"}}; SlowMode ^= 1; extravbls = SlowMode << 3; CenterWindow (8,3); US_PrintCentered (Text[SlowMode]); VW_UpdateScreen (); // SD_MusicOff(); IN_Ack(); // SD_MusicOn(); // (REFKEEN) Minor difference from vanilla Catacomb if (MousePresent) BE_ST_GetEmuAccuMouseMotion(NULL, NULL); // Clear accumulated mouse movement //if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement } #endif // F2 - SOUND OPTIONS // if (Keyboard[sc_F2]) { id0_int_t height=7; id0_boolean_t ChoiceMade = false; if (AdLibPresent) height++; VW_FixRefreshBuffer(); CenterWindow(22,height); US_Print( "\n 1 ) NO SOUND \n"); US_Print( " 2 ) PC AUDIO \n"); if (AdLibPresent) US_Print(" 3 ) ADLIB AUDIO\n"); US_Print( "\n ESC) EXIT "); VW_UpdateScreen(); // REFKEEN - Alternative controllers support extern BE_ST_ControllerMapping g_ingame_altcontrol_mapping_soundoptions; g_ingame_altcontrol_mapping_soundoptions.buttons[BE_ST_CTRL_BUT_X].mapClass = AdLibPresent ? BE_ST_CTRL_MAP_KEYSCANCODE : BE_ST_CTRL_MAP_NONE; // A bit of patching BE_ST_AltControlScheme_Push(); BE_ST_AltControlScheme_PrepareControllerMapping(&g_ingame_altcontrol_mapping_soundoptions); // Switch audio device ON/OFF & load sounds if there // was a change in the device. do { if (Keyboard[1]) // ESC - Exit ChoiceMade = true; else if (Keyboard[2]) // 1 - No Sound { SD_SetSoundMode(sdm_Off); ChoiceMade = true; } else if (Keyboard[3]) // 2 - PC Audio { SD_SetSoundMode(sdm_PC); // if (oldsoundmode != sdm_PC) CA_LoadAllSounds(); ChoiceMade = true; } else if ((Keyboard[4]) && AdLibPresent) // 3 - AdLib Audio { SD_SetSoundMode(sdm_AdLib); // if (oldsoundmode != sdm_AdLib) CA_LoadAllSounds(); ChoiceMade = true; } BE_ST_ShortSleep(); } while (!ChoiceMade); // REFKEEN - Alternative controllers support BE_ST_AltControlScheme_Pop(); tics = realtics = 1; IN_ClearKeysDown(); } // F5 - CALIBRATE JOYSTICK // if (Keyboard[sc_F5]) { CalibrateJoystick(0); tics = realtics = 1; IN_ClearKeysDown(); } deadloop:; // ESCAPE - quits game // if ((Keyboard[sc_Escape]) || (Flags & FL_DEAD)) { id0_char_t ch; DisplaySMsg("Options", NULL); status_flag = S_NONE; if (Flags & FL_DEAD) { id0_char_t choices[] = {sc_Escape,sc_R,sc_N,sc_Q,0}; ch = DisplayMsg("Restore New Quit",choices); } else { id0_char_t choices[] = {sc_Escape,sc_S,sc_R,sc_N,sc_Q,0}; ch = DisplayMsg("Save Restore New Quit",choices); } DrawText(true); switch (ch) { case sc_S: if (!(Flags & FL_DEAD)) Keyboard[sc_F3] = true; break; case sc_R: Keyboard[sc_F4] = true; break; case sc_N: DisplaySMsg("Starting anew", NULL); VW_WaitVBL(60); playstate = ex_resetgame; Flags &= ~FL_DEAD; break; case sc_Q: // REFKEEN - Alternative controllers support { extern BE_ST_ControllerMapping g_ingame_altcontrol_mapping_inackback; BE_ST_AltControlScheme_Push(); BE_ST_AltControlScheme_PrepareControllerMapping(&g_ingame_altcontrol_mapping_inackback); // REFKEEN - We don't pop this since we quit... } DisplaySMsg("FARE THEE WELL!", NULL); VW_WaitVBL(120); if (!Flags & FL_QUICK) VW_FadeOut(); NormalScreen(); FreeUpMemory(); Quit(NULL); break; } tics = realtics = 1; } // F1 - DISPLAY HELP // if (Keyboard[sc_F1]) { PrintHelp(); #ifdef TEXT_PRESENTER extern PresenterInfo MainHelpText; VW_FadeOut(); FreeUpMemory(); if (!LoadPresenterScript("HELP.TXT",&MainHelpText)) { VW_FadeIn(); CenterWindow(30,5); US_CPrint("\nError loading HELP file.\n"); US_CPrint("Press any key."); IN_Ack(); VW_FadeOut(); } else { VW_SetSplitScreen(200); bufferofs = displayofs = screenloc[0]; VW_Bar(0,0,320,200,0); Display640(); Presenter(&MainHelpText); Display320(); } FreePresenterScript(&MainHelpText); #endif VW_SetSplitScreen(120); VW_SetScreen(screenloc[0],0); screenpage = 0; CacheScaleds(); bufferofs = 0; RedrawStatusWindow(); ThreeDRefresh(); VW_FadeIn(); Keyboard[sc_F1] = false; tics = realtics = 1; IN_ClearKeysDown(); } // F3 - SAVE GAME // if ((Keyboard[sc_F3]) && (!(Flags & FL_DEAD))) { PreFullDisplay(); GE_SaveGame(); PostFullDisplay(true); tics = realtics = 1; IN_ClearKeysDown(); } // F4 - LOAD GAME // if (Keyboard[sc_F4]) { PreFullDisplay(); if (GE_LoadGame()) { loadedgame = true; playstate = ex_loadedgame; Flags &= ~FL_DEAD; lasttext = -1; PostFullDisplay(false); } else if (playstate == ex_victorious) { PostFullDisplay(false); Victory(false); IN_Ack(); // gamestate.mapon++; } else PostFullDisplay(true); Keyboard[sc_F5] = false; tics = realtics = 1; IN_ClearKeysDown(); } if (Flags & FL_DEAD) goto deadloop; // // F10-? debug keys // if (Keyboard[sc_BackSpace]) { DebugKeys(); // (REFKEEN) Minor difference from vanilla Catacomb if (MousePresent) BE_ST_GetEmuAccuMouseMotion(NULL, NULL); // Clear accumulated mouse movement //if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement lasttimecount = SD_GetTimeCount(); } }
void CMUSHclientDoc::CheckTimerList (CTimerMap & TimerMap) { CTimer * timer_item; CString strTimerName; CmcDateTime tNow = CmcDateTime::GetTimeNow(); CmcDateTimeSpan tsOneDay (1, 0, 0, 0); // check for deleted chat sessions for (POSITION chatpos = m_ChatList.GetHeadPosition (); chatpos; ) { POSITION oldpos = chatpos; CChatSocket * pSocket = m_ChatList.GetNext (chatpos); if (pSocket->m_bDeleteMe) { m_ChatList.RemoveAt (oldpos); delete pSocket; break; // list is no longer valid } } set <string> firedTimersList; POSITION pos; // iterate through all timers for this document - first build list of them for (pos = TimerMap.GetStartPosition(); pos; ) { TimerMap.GetNextAssoc (pos, strTimerName, timer_item); if (!timer_item->bEnabled) // ignore un-enabled timers continue; // no timer activity whilst closed or in the middle of connecting, or if not enabled if (!timer_item->bActiveWhenClosed) if (m_iConnectPhase != eConnectConnectedToMud) continue; // if not ready to fire yet, ignore it if (timer_item->tFireTime > tNow) continue; firedTimersList.insert ((LPCTSTR) strTimerName); // add to list of fired timers } // now process list, checking timer still exists in case a script deleted one // see: http://www.gammon.com.au/forum/?id=10358 for (set <string>::iterator it = firedTimersList.begin (); it != firedTimersList.end (); it++) { // get next fired timer from list strTimerName = it->c_str (); // check still exists, get pointer if so if (!TimerMap.Lookup (strTimerName, timer_item)) continue; timer_item->nMatched++; // count timer matches timer_item->tWhenFired = tNow; // when it fired m_iTimersFiredCount++; m_iTimersFiredThisSessionCount++; // TRACE1 ("Fired at = %10.8f\n", timer_item->tWhenFired.m_dt); if (timer_item->strLabel.IsEmpty ()) Trace ("Fired unlabelled timer "); else Trace ("Fired timer %s", (LPCTSTR) timer_item->strLabel); // TRACE1 ("Fire time = %10.8f\n", timer_item->tFireTime.m_dt); // update fire time - before calling the script, in case it takes a long time if (timer_item->iType == CTimer::eAtTime) timer_item->tFireTime += tsOneDay; else timer_item->tFireTime += CmcDateTimeSpan (0, // add the interval timer_item->iEveryHour, timer_item->iEveryMinute, timer_item->fEverySecond); // in case clock changes or some such thing, make sure timer will be due to // fire in the future, not the past, or it might go mad and keep firing if (timer_item->tFireTime <= tNow) ResetOneTimer (timer_item); // if one-shot, disable it, so if the timer routine finds it again while // it is still executing (eg. due to a syntax error dialog box) then // it won't fire again. if (timer_item->bOneShot) timer_item->bEnabled = false; // send timer message, if this timer list is "active" CString strExtraOutput; timer_item->bExecutingScript = true; // cannot be deleted now m_iCurrentActionSource = eTimerFired; SendTo (timer_item->iSendTo, timer_item->strContents, timer_item->bOmitFromOutput, // omit from output timer_item->bOmitFromLog, // omit from log TFormat ("Timer: %s", (LPCTSTR) timer_item->strLabel), timer_item->strVariable, strExtraOutput ); m_iCurrentActionSource = eUnknownActionSource; timer_item->bExecutingScript = false; // can be deleted now // display any stuff sent to output window if (!strExtraOutput.IsEmpty ()) DisplayMsg (strExtraOutput, strExtraOutput.GetLength (), COMMENT); // invoke script subroutine, if any if (!timer_item->strProcedure.IsEmpty ()) if (CheckScriptingAvailable ("Timer", timer_item->dispid, timer_item->strProcedure)) continue; if (timer_item->dispid != DISPID_UNKNOWN) // if we have a dispatch id { CString strType = "timer"; CString strReason = TFormat ("processing timer \"%s\"", (LPCTSTR) timer_item->strLabel); // get unlabelled timer's internal name const char * pLabel = timer_item->strLabel; if (pLabel [0] == 0) pLabel = GetTimerRevMap () [timer_item].c_str (); if (GetScriptEngine () && GetScriptEngine ()->IsLua ()) { list<double> nparams; list<string> sparams; sparams.push_back (pLabel); timer_item->bExecutingScript = true; // cannot be deleted now GetScriptEngine ()->ExecuteLua (timer_item->dispid, timer_item->strProcedure, eTimerFired, strType, strReason, nparams, sparams, timer_item->nInvocationCount); timer_item->bExecutingScript = false; // can be deleted now } // end of Lua else { // prepare for the arguments (so far, 1 which is the timer name) // WARNING - arguments should appear in REVERSE order to what the sub expects them! enum { eTimerName, eArgCount, // this MUST be last }; COleVariant args [eArgCount]; DISPPARAMS params = { args, NULL, eArgCount, 0 }; // args [eTimerName] = strTimerName; args [eTimerName] = pLabel; timer_item->bExecutingScript = true; // cannot be deleted now ExecuteScript (timer_item->dispid, timer_item->strProcedure, eTimerFired, strType, strReason, params, timer_item->nInvocationCount); timer_item->bExecutingScript = false; // can be deleted now } // not Lua } // end of having a dispatch ID // If they passed the wrong arguments to the timer routine, the dialog box // might appear, and the timer be deleted, before we get a chance to // do this code, in which case the timer has gone. // Just get it again to be sure ... [#430] if (!TimerMap.Lookup (strTimerName, timer_item)) return; // if one-shot timer, delete from list if (timer_item->bOneShot) { TimerMap.RemoveKey (strTimerName); delete timer_item; SortTimers (); } } // end of processing each timer } // end of CMUSHclientDoc::CheckTimerMap
bool CMUSHclientDoc::ProcessOneAliasSequence (const CString strCurrentLine, const bool bCountThem, bool & bOmitFromLog, bool & bEchoAlias, CAliasList & AliasList, OneShotItemMap & mapOneShotItems) { for (int iAlias = 0; iAlias < GetAliasArray ().GetSize (); iAlias++) { CAlias * alias_item = GetAliasArray () [iAlias]; // ignore non-enabled aliases if (!alias_item->bEnabled) continue; m_iAliasesEvaluatedCount++; BOOL bMatched; // empty wildcards now for (int i = 0; i < MAX_WILDCARDS; i++) alias_item->wildcards [i] = ""; CString strTarget = strCurrentLine; try { bMatched = regexec (alias_item->regexp, strTarget); } catch(CException* e) { e->ReportError (); e->Delete (); bMatched = false; } if (!bMatched) // no match, try next one continue; m_iAliasesMatchedCount++; m_iAliasesMatchedThisSessionCount++; if (alias_item->bOneShot) mapOneShotItems.push_back ( OneShotItem (m_CurrentPlugin, (const char *) alias_item->strInternalName)); // if alias wants it, omit entire typed line from command history if (alias_item->bOmitFromCommandHistory) m_bOmitFromCommandHistory = true; alias_item->wildcards.clear (); for (int iWildcard = 0; iWildcard < MAX_WILDCARDS; iWildcard++) alias_item->wildcards.push_back ( FixWildcard (alias_item->regexp->GetWildcard (iWildcard), false, alias_item->iSendTo, m_strLanguage) ); // echo the alias they typed, unless command echo off, or previously displayed // (if wanted - v3.38) if (bEchoAlias && // not already done alias_item->bEchoAlias) // alias wants to be echoed { DisplayMsg (strCurrentLine + ENDLINE, strCurrentLine.GetLength () + strlen (ENDLINE), USER_INPUT | (LoggingInput () ? LOG_LINE : 0)); bEchoAlias = false; // don't echo the same line twice // and log the command the actually typed if (LoggingInput ()) LogCommand (strCurrentLine); } if (bCountThem) alias_item->nMatched++; // count alias matches bOmitFromLog = alias_item->bOmitFromLog; alias_item->tWhenMatched = CTime::GetCurrentTime(); // when it matched if (alias_item->strLabel.IsEmpty ()) Trace ("Matched alias \"%s\"", (LPCTSTR) alias_item->name); else Trace ("Matched alias %s", (LPCTSTR) alias_item->strLabel); // if we have to do parameter substitution on the alias, do it now CString strSendText; // copy contents to strSendText area, replacing %1, %2 etc. with appropriate contents try { strSendText = FixSendText (::FixupEscapeSequences (alias_item->contents), alias_item->iSendTo, // where it is going alias_item->regexp, // regexp GetLanguage (), // eg. vbscript false, // lower-case wildcards alias_item->bExpandVariables, // expand variables true, // expand wildcards false, // convert regexps false, // is it regexp or normal? true); // throw exceptions } catch (CException* e) { e->ReportError(); e->Delete(); return true; } AliasList.AddTail (alias_item); // add to list of aliases CString strExtraOutput; // let them know if they are foolishly trying to send to a closed connection // - only applies to commands that actually send to the world if (!strSendText.IsEmpty ()) switch (alias_item->iSendTo) { case eSendToWorld: case eSendToCommandQueue: case eSendToSpeedwalk: case eSendImmediate: if (CheckConnected ()) return true; break; } alias_item->bExecutingScript = true; // cannot be deleted now SendTo (alias_item->iSendTo, strSendText, alias_item->bOmitFromOutput, alias_item->bOmitFromLog, TFormat ("Alias: %s", (LPCTSTR) alias_item->strLabel), alias_item->strVariable, strExtraOutput); alias_item->bExecutingScript = false; // can be deleted now // display any stuff sent to output window if (!strExtraOutput.IsEmpty ()) DisplayMsg (strExtraOutput, strExtraOutput.GetLength (), COMMENT); // only re-match if they want multiple matches if (!alias_item->bKeepEvaluating) break; } // end of looping, checking each alias return FALSE; } // end of CMUSHclientDoc::ProcessOneAliasSequence
INT __cdecl wmain( INT argc, PWSTR argv[] ) /*++ Routine Description: This routine is the 'main' routine for the tool 'fscutl'. Arguments: argc - The argument count. argv - Array of Strings of the form : ' fscutl <command> <options/flags> <parameters> ...' Return Value: INT - Return Status --*/ { PCOMMAND_VECTOR Cmds = NULL; PCOMMAND_VECTOR Cmds2 = NULL; OSVERSIONINFOEX OsVer; #if FALSE LANGID (WINAPI *pSetThreadUILanguage)( ) = NULL; if (pSetThreadUILanguage == NULL) { pSetThreadUILanguage = (PVOID) GetProcAddress( GetModuleHandle( TEXT( "kernel32" )), "SetThreadUILanguage" ); } if (pSetThreadUILanguage == NULL) { SetThreadLocale( MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), SORT_DEFAULT )); } else { (*pSetThreadUILanguage)( 0 ); } #endif setlocale( LC_ALL, ".OCP" ) ; SHIFT( argc, argv ); OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if (GetVersionEx( (LPOSVERSIONINFO)&OsVer ) && OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 0) { RunningOnWin2K = TRUE; } if (!IsUserAdmin()) { DisplayMsg( MSG_ADMIN_REQUIRED ); return EXIT_CODE_FAILURE; } // // Check for blind usage // if (argc == 0) { Help( 0, NULL ); return EXIT_CODE_SUCCESS; } // // We have a two-level dispatch scheme. First level selects a table and second // selects a function // Cmds = FindCommand( CmdVectorGroups, argv[0] ); if (Cmds == NULL) { DisplayMsg( MSG_INVALID_PARAMETER, argv[0] ); Help( 0, NULL ); return EXIT_CODE_FAILURE; } SHIFT( argc, argv ); // // If there's no argument, then it's a cry for help // if (argc == 0) { Cmds2 = FindCommand( Cmds->CommandVector, L"?" ); Cmds2->CommandFunc( argc, argv ); return EXIT_CODE_SUCCESS; } // // Go to second level dispatch. // Cmds2 = FindCommand( Cmds->CommandVector, argv[0] ); if (Cmds2 == NULL) { DisplayMsg( MSG_INVALID_PARAMETER, argv[0] ); Cmds2 = FindCommand( Cmds->CommandVector, L"?" ); SHIFT( argc, argv ); Cmds2->CommandFunc( argc, argv ); return EXIT_CODE_FAILURE; } SHIFT( argc, argv ); return Cmds2->CommandFunc( argc, argv ); }
////////////////////////////////////////////////////////////////////// // Connect function, see .h file for description ////////////////////////////////////////////////////////////////////// bool CSocketPort::Connect() { int ret = 0; bool retval = false; char buf[512] ; buf[0] = '\0' ; // m_ShutDownFlag = true ; m_SockAddr.sin_addr.s_addr = inet_addr(m_SrvIPAddr); m_SockAddr.sin_family = AF_INET; m_SockAddr.sin_port = htons(m_SrvPort); // Port MUST be in Network Byte Order memset(&(m_SockAddr.sin_zero), 0, 8); // zero the rest of the struct m_SockAddrLen = sizeof(sockaddr); if( m_SockType == CLIENT_SOCKET ) { m_hDriver = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP); if (m_hDriver == INVALID_SOCKET) { sprintf(buf, "failure creating socket (%d: %s)\n", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); return false; } #ifdef __linux__ int on = 1; if ( setsockopt ( m_hDriver, SOL_SOCKET, SO_REUSEADDR, &on, sizeof ( on ) ) == -1 ) { sprintf(buf, "An Error occurred in setting options for socket (%d - %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); return false; } #endif ret = connect(m_hDriver,(sockaddr*) &m_SockAddr, m_SockAddrLen); if ( ret == -1 ) { sprintf(buf, "failure connecting socket to \"%s:%d\" (%d: %s)", m_SrvIPAddr, m_SrvPort, this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); return false; } else { //Per il client questo NON funziona: c'e' comunque un timeout interno di ca 16 minuti su Linux // //Provo ad attivare il keep alive con invio ad un minuto // setsockopt ( m_hDriver, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof ( on ) ); // int firstKeepAlive = 60, nextKeepAlive=5 ; // //Il primo keepalive viene mandato dopo un minuto di inattivita' // setsockopt ( m_hDriver, IPPROTO_TCP, TCP_KEEPIDLE, &firstKeepAlive, sizeof ( firstKeepAlive ) ); // //Se non c'è risposta invio un messaggio ogni 5 secondi // setsockopt ( m_hDriver, IPPROTO_TCP, TCP_KEEPINTVL, &nextKeepAlive, sizeof ( nextKeepAlive ) ); sprintf(buf,"Connected to \"%s:%d\" ",m_SrvIPAddr, m_SrvPort) ; m_IsConnected = 1; DisplayMsg(buf); return true; } } else { if( (m_SockType == SERVER_SOCKET ) && (m_hLocalSrvr == INVALID_SOCKET) ) { //m_hLocalSrvr = socket( AF_INET, SOCK_STREAM, 0); //TBC m_hLocalSrvr = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP); #ifdef __linux__ int on = 1; //if ( setsockopt ( m_hLocalSrvr, SOL_SOCKET, SO_REUSEADDR, ( const char* ) &on, sizeof ( on ) ) == -1 ) //TBC if ( setsockopt ( m_hLocalSrvr, SOL_SOCKET, SO_REUSEADDR, &on, sizeof ( on ) ) == -1 ) { sprintf(buf, "An Error occurred in setting options for socket (%d - %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(buf); return false; } #endif if (m_hLocalSrvr == INVALID_SOCKET) { sprintf(buf, "failure creating socket (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); retval = 0 ; } if (m_hLocalSrvr != INVALID_SOCKET) { SetNonBlocking(); } int ret = bind(m_hLocalSrvr,(sockaddr*) &m_SockAddr, m_SockAddrLen ); if ( ret == -1 ) { sprintf(buf, "failure binding socket to \"%s:%d\" (%d: %s)", m_SrvIPAddr, m_SrvPort, this->GetLastError(), strerror(this->GetLastError()) ); retval = false; } else { // Listen only if bind succeeded ret = listen(m_hLocalSrvr, 5) ; if ( ret == -1 ) { sprintf(buf, "failure listening to socket \"%s:%d\" (%d: %s)", m_SrvIPAddr, m_SrvPort, this->GetLastError(), strerror(this->GetLastError()) ); retval = false; } else { sprintf(buf, "Listening on \"%s:%d\" ", m_SrvIPAddr, m_SrvPort); retval = true; } } } } if( strlen(buf) != 0 ) { DisplayMsg(buf) ; } return retval ; }
////////////////////////////////////////////////////////////////////// // Write function, see .h file for description ////////////////////////////////////////////////////////////////////// unsigned long CSocketPort::WriteClient(const char *Buffer, int BlockSize = -1) { char ErrorMsg[64]; if (m_IsConnected == false) return 0 ; if (m_hLocalSrvr == INVALID_SOCKET) { sprintf(ErrorMsg,"socket invalid (Write)\n" ) ; DisplayMsg(ErrorMsg); m_IsConnected = false; return 0; } if(BlockSize < 0 )BlockSize = strlen(Buffer) ; long nWrittenChars = 0; unsigned long nTotalWrittenChars = 0L; struct timeval Timeout; Timeout.tv_sec = 0; Timeout.tv_usec = SELECT_TIMEOUT_MICROSECS; fd_set writefds; while(nTotalWrittenChars < (unsigned long) BlockSize) { FD_ZERO(&writefds); FD_SET(m_hLocalSrvr, &writefds); int ret = select( m_hLocalSrvr+1, NULL, &writefds, NULL, &Timeout); if( ( ret == SOCKET_ERROR )||( ret > (m_hLocalSrvr+1) )||( ret < 0 ) ) { sprintf(ErrorMsg, "select error in write: (%d: %s)", this->GetLastError(), strerror(this->GetLastError()) ); DisplayMsg(ErrorMsg); return 0L; } if (ret == 0) { nTotalWrittenChars = 0; sprintf(ErrorMsg, "select returned 0 in write: (%d)", this->GetLastError() ); DisplayMsg(ErrorMsg); break; } if ( FD_ISSET(m_hLocalSrvr, &writefds)) { nWrittenChars = send( m_hLocalSrvr, Buffer+nTotalWrittenChars, BlockSize-nTotalWrittenChars, 0); if(nWrittenChars <= 0) { sprintf(ErrorMsg, "WARNING: %ld bytes sent to socket", nWrittenChars ); DisplayMsg(ErrorMsg); Disconnect() ; break; } }else{ DisplayMsg(" socket not writeable "); Disconnect() ; break; } nTotalWrittenChars += nWrittenChars ; } return nTotalWrittenChars ; }