@@ -3578,86 +3578,86 @@ double Socket::getAveragePingMS(std::string host, int pingCount) {
35783578 #else
35793579 #error "Your compiler needs to support popen!"
35803580
3581- #endif
3581+ #endif
35823582
3583- if(debugPingOutput) printf("Running cmd [%s] got
3584- [%s]\n",szCmd,buf);
3585-
3586- // Linux
3587- //softcoder@softhauslinux:~/Code/megaglest/trunk/mk/linux$
3588- ping -c 5 soft-haus.com
3589- //PING soft-haus.com (65.254.250.110) 56(84) bytes of
3590- data.
3591- //64 bytes from 65-254-250-110.yourhostingaccount.com
3592- (65.254.250.110): icmp_seq=1 ttl=242 time=133 ms
3593- //64 bytes from 65-254-250-110.yourhostingaccount.com
3594- (65.254.250.110): icmp_seq=2 ttl=242 time=137 ms
3595- //
3596- // Windows XP
3597- //C:\Code\megaglest\trunk\data\glest_game>ping -n 5
3598- soft-haus.com
3599- //
3600- //Pinging soft-haus.com [65.254.250.110] with 32 bytes
3601- of data:
3602- //
3603- //Reply from 65.254.250.110: bytes=32 time=125ms
3604- TTL=242
3605- //Reply from 65.254.250.110: bytes=32 time=129ms
3606- TTL=242
3607-
3608- std::string str = buf;
3609- std::string::size_type ms_pos = 0;
3610- int count = 0;
3611- while ( ms_pos != std::string::npos) {
3612- ms_pos = str.find("time=", ms_pos);
3613-
3614- if(debugPingOutput) printf("count = %d ms_pos
3615- = %d\n",count,ms_pos);
3616-
3617- if ( ms_pos != std::string::npos ) {
3618- ++count;
3619-
3620- int endPos = str.find(" ms", ms_pos+5
3621- );
3622-
3623- if(debugPingOutput) printf("count = %d
3624- endPos = %d\n",count,endPos);
3625-
3626- if(endPos == std::string::npos) {
3627- endPos = str.find("ms ",
3628- ms_pos+5 );
3629-
3630- if(debugPingOutput)
3631- printf("count = %d endPos = %d\n",count,endPos);
3632- }
3633-
3634- if(endPos != std::string::npos) {
3635-
3636- if(count == 1) {
3637- result = 0;
3638- }
3639- int startPos = ms_pos + 5;
3640- int posLength = endPos -
3641- startPos; if(debugPingOutput) printf("count = %d startPos = %d posLength = %d
3642- str = [%s]\n",count,startPos,posLength,str.substr(startPos,
3643- posLength).c_str());
3644-
3645- float pingMS =
3646- strToFloat(str.substr(startPos, posLength)); result += pingMS;
3647- }
3648-
3649- ms_pos += 5; // start next search
3650- after this "time="
3651- }
3652- }
3583+ if(debugPingOutput) printf("Running cmd [%s] got
3584+ [%s]\n",szCmd,buf);
3585+
3586+ // Linux
3587+ //softcoder@softhauslinux:~/Code/megaglest/trunk/mk/linux$
3588+ ping -c 5 soft-haus.com
3589+ //PING soft-haus.com (65.254.250.110) 56(84) bytes of
3590+ data.
3591+ //64 bytes from 65-254-250-110.yourhostingaccount.com
3592+ (65.254.250.110): icmp_seq=1 ttl=242 time=133 ms
3593+ //64 bytes from 65-254-250-110.yourhostingaccount.com
3594+ (65.254.250.110): icmp_seq=2 ttl=242 time=137 ms
3595+ //
3596+ // Windows XP
3597+ //C:\Code\megaglest\trunk\data\glest_game>ping -n 5
3598+ soft-haus.com
3599+ //
3600+ //Pinging soft-haus.com [65.254.250.110] with 32 bytes
3601+ of data:
3602+ //
3603+ //Reply from 65.254.250.110: bytes=32 time=125ms
3604+ TTL=242
3605+ //Reply from 65.254.250.110: bytes=32 time=129ms
3606+ TTL=242
3607+
3608+ std::string str = buf;
3609+ std::string::size_type ms_pos = 0;
3610+ int count = 0;
3611+ while ( ms_pos != std::string::npos) {
3612+ ms_pos = str.find("time=", ms_pos);
3613+
3614+ if(debugPingOutput) printf("count = %d ms_pos
3615+ = %d\n",count,ms_pos);
3616+
3617+ if ( ms_pos != std::string::npos ) {
3618+ ++count;
3619+
3620+ int endPos = str.find(" ms", ms_pos+5
3621+ );
3622+
3623+ if(debugPingOutput) printf("count = %d
3624+ endPos = %d\n",count,endPos);
3625+
3626+ if(endPos == std::string::npos) {
3627+ endPos = str.find("ms ",
3628+ ms_pos+5 );
3629+
3630+ if(debugPingOutput)
3631+ printf("count = %d endPos = %d\n",count,endPos);
3632+ }
3633+
3634+ if(endPos != std::string::npos) {
3635+
3636+ if(count == 1) {
3637+ result = 0;
3638+ }
3639+ int startPos = ms_pos + 5;
3640+ int posLength = endPos -
3641+ startPos; if(debugPingOutput) printf("count = %d startPos = %d posLength = %d
3642+ str = [%s]\n",count,startPos,posLength,str.substr(startPos,
3643+ posLength).c_str());
3644+
3645+ float pingMS =
3646+ strToFloat(str.substr(startPos, posLength)); result += pingMS;
3647+ }
3648+
3649+ ms_pos += 5; // start next search
3650+ after this "time="
3651+ }
3652+ }
36533653
3654- if(result > 0 && count > 1) {
3655- result /= count;
3656- }
3657- }
3658- }
3659- return result;
3660- */
3654+ if(result > 0 && count > 1) {
3655+ result /= count;
3656+ }
3657+ }
3658+ }
3659+ return result;
3660+ */
36613661}
36623662
36633663std::string Socket::getIpAddress () {
0 commit comments