bool RaptorRemoteSession::checkSessionIntegrity() { if (connected) { int success = sendPingMessage(); if (success == -1) { return false; } } return true; }
void run() override { while (! threadShouldExit()) { if (--countdown <= 0 || ! sendPingMessage (MemoryBlock (pingMessage, specialMessageSize))) { triggerConnectionLostMessage(); break; } wait (1000); } }
void IRCLobby::readIRCLine(char *buf, size_t buf_len) { char *buf_end=buf+buf_len-1; char ch; char *buf_upto=buf; SDLNet_SocketSet sock_set=SDLNet_AllocSocketSet(1); SDLNet_TCP_AddSocket(sock_set,irc_server_socket); int no_activity=0; try { while(buf_upto < buf_end) { SDLNet_CheckSockets(sock_set, 1000); if(!SDLNet_SocketReady(irc_server_socket)) { if(++no_activity>=(60*1) && !expected_ping) { sendPingMessage(); } if(expected_ping && expected_ping<time(NULL)) { throw Exception("no pong received after ping"); } continue; } if(SDLNet_TCP_Recv(irc_server_socket,&ch,1)<=0) throw Exception("Couldn't read TCP: %s", SDLNet_GetError()); if(ch=='\r') { continue; } if(ch=='\n') { break; } *buf_upto++=ch; } } catch(std::exception& e) { buf[0]=0; SDLNet_FreeSocketSet(sock_set); throw; } SDLNet_FreeSocketSet(sock_set); *buf_upto=0; }
/*Main Function Variable Definition: -- argc: the number of command arguments -- argv[]: each vairable of command arguments(argv[0] is the path of execution file forever) Return Value: Client exit number */ int main(int argc, char *argv[]){ //Test for correct number of arguments if (argc != 3){ dieWithUserMessage("Parameter(s)", "<Server Address/Name> <Server Port/Service>"); } struct sigaction handler; //signal handler const char *host = argv[1]; //first argument: host name/ip address const char *service = argv[2]; //second argument: server listening port number int rcvd_buffer_size = 50 * BUFFER_SIZE; //received buffer size //Initialize Pinger initPinger(); //Create a unreliable UDP socket client_socket = setupClientSocket(host, service); if (client_socket < 0){ dieWithSystemMessage("setupClientSocket() failed"); } //Set the received buffer size setsockopt(client_socket, SOL_SOCKET, SO_RCVBUF, &rcvd_buffer_size, sizeof(rcvd_buffer_size)); //Set signal handler for alarm signal handler.sa_handler = catchAlarm; //Blocking everything in handler if (sigfillset(&handler.sa_mask) < 0){ dieWithSystemMessage("sigfillset() failed"); } //No flags handler.sa_flags = 0; //Set the "SIGALRM" signal if (sigaction(SIGALRM, &handler, 0) < 0){ dieWithSystemMessage("sigaction() failed for SIGALRM"); } //Set the "SIGINT" signal if (sigaction(SIGINT, &handler, 0) < 0){ dieWithSystemMessage("sigaction() failed for SIGINT"); } //Output the title printf("PING %s (", host); printSocketAddress((struct sockaddr*)address->ai_addr, stdout); printf(") result:\n"); //Sleep for 1 second sleep(TIMEOUT); //Start to send ping message while (send_count < PING_SIZE){ sendPingMessage(); rcvdPingMessage(TIMEOUT); } //You should put sleep function inside the while loop and after rcvdPingMessage, and you should sleep for TIMEOUT - rtt value for this cycle #13 -4 //Determine that no more replies that comes in if (send_count != rcvd_count){ rcvdPingMessage(REPLY_TIMEOUT); } //SIGINT signal: construct ping statistics catchAlarm(SIGINT); return 0; }