Skip to content

Commit

Permalink
tweak a few things to improve readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Jun 21, 2017
1 parent 5c42452 commit 418e61d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions cnping.c
Expand Up @@ -377,12 +377,12 @@ int main( int argc, const char ** argv )

if( argc > 2 )
{
pingperiod = atof( argv[2] );
printf( "Extra ping period: %f\n", pingperiod );
pingperiodseconds = atof( argv[2] );
printf( "Extra ping period: %f\n", pingperiodseconds );
}
else
{
pingperiod = 0.02;
pingperiodseconds = 0.02;
}

if( argc > 3 )
Expand Down
2 changes: 1 addition & 1 deletion os_generic.c
@@ -1,6 +1,5 @@
#include "os_generic.h"


#ifdef USE_WINDOWS

#include <windows.h>
Expand Down Expand Up @@ -56,6 +55,7 @@ void * OGJoinThread( og_thread_t ot )
{
WaitForSingleObject( ot, INFINITE );
CloseHandle( ot );
return 0;
}

void OGCancelThread( og_thread_t ot )
Expand Down
4 changes: 2 additions & 2 deletions os_generic.h
@@ -1,7 +1,7 @@
#ifndef _OS_GENERIC_H
#define _OS_GENERIC_H

#ifdef WIN32
#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32)
#define USE_WINDOWS
#endif

Expand All @@ -25,7 +25,7 @@ og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter );
void * OGJoinThread( og_thread_t ot );
void OGCancelThread( og_thread_t ot );

//Always a recrusive mutex.
//Always a recursive mutex.
og_mutex_t OGCreateMutex();
void OGLockMutex( og_mutex_t om );
void OGUnlockMutex( og_mutex_t om );
Expand Down
30 changes: 15 additions & 15 deletions ping.c
Expand Up @@ -45,10 +45,6 @@ void bzero(void * loc, int len)
}
#endif

void usleep(int x) {
Sleep(x / 1000);
}

#include <windows.h>
#include <stdio.h>
#include <winsock2.h>
Expand Down Expand Up @@ -87,7 +83,7 @@ struct icmphdr {
};
#endif

float pingperiod;
float pingperiodseconds;
int precise_ping;

#define PACKETSIZE 1500
Expand Down Expand Up @@ -133,7 +129,7 @@ void listener(void)

if ( setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0)
{
ERRM("Erro: could not set TTL option\n");
ERRM("Error: could not set TTL option\n");
exit( -1 );
}

Expand Down Expand Up @@ -166,7 +162,9 @@ void listener(void)
if ( bytes > 0 )
display(buf + 28, bytes - 28 );
else
perror("recvfrom");
{
ERRM("Error: recvfrom failed");
}

goto keep_retry_quick;
}
Expand Down Expand Up @@ -219,7 +217,9 @@ void ping(struct sockaddr_in *addr )
pckt.hdr.checksum = checksum(&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize );

if ( sendto(sd, (char*)&pckt, sizeof(pckt) - sizeof( pckt.msg ) + rsize , 0, (struct sockaddr*)addr, sizeof(*addr)) <= 0 )
perror("sendto");
{
ERRM("Sendto failed.");
}


if( precise_ping )
Expand All @@ -228,19 +228,19 @@ void ping(struct sockaddr_in *addr )
do
{
ctime = OGGetAbsoluteTime();
if( pingperiod >= 1000 ) stime = ctime;
} while( ctime < stime + pingperiod );
stime += pingperiod;
if( pingperiodseconds >= 1000 ) stime = ctime;
} while( ctime < stime + pingperiodseconds );
stime += pingperiodseconds;
}
else
{
if( pingperiod > 0 )
if( pingperiodseconds > 0 )
{
uint32_t dlw = 1000000.0*pingperiod;
usleep( dlw );
uint32_t dlw = 1000000.0*pingperiodseconds;
OGUSleep( dlw );
}
}
} while( pingperiod >= 0 );
} while( pingperiodseconds >= 0 );
//close( sd ); //Hacky, we don't close here because SD doesn't come from here, rather from ping_setup. We may want to run this multiple times.
}

Expand Down
4 changes: 2 additions & 2 deletions ping.h
Expand Up @@ -18,8 +18,8 @@ void listener(void);
void ping(struct sockaddr_in *addr );
void do_pinger( const char * strhost );

//If pingperiod = -1, run ping/do_pinger once and exit.
extern float pingperiod;
//If pingperiodseconds = -1, run ping/do_pinger once and exit.
extern float pingperiodseconds;
extern int precise_ping; //if 0, use minimal CPU, but ping send-outs are only approximate, if 1, spinlock until precise time for ping is hit.

void ping_setup();
Expand Down
2 changes: 1 addition & 1 deletion searchnet.c
Expand Up @@ -85,7 +85,7 @@ int main( int argc, char ** argv )
send_id[2] = (cur>>8)&0xff;
send_id[3] = (cur)&0xff;
// printf( "Pinging: %s\n", dispip );
pingperiod = -1;
pingperiodseconds = -1;
do_pinger( dispip );

OGUSleep( (int)(speed * 1000000) );
Expand Down

0 comments on commit 418e61d

Please sign in to comment.