projects
/
rrq
/
rrqnet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d10f3f0
)
change deprecated ftime into gettimeofdate
author
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Thu, 7 Oct 2021 08:34:02 +0000
(19:34 +1100)
committer
Ralph Ronnquist
<ralph.ronnquist@gmail.com>
Thu, 7 Oct 2021 08:34:02 +0000
(19:34 +1100)
rrqnet.c
patch
|
blob
|
history
diff --git
a/rrqnet.c
b/rrqnet.c
index 85f609ebddee6851041be21cd1415cdd2805ac68..90b246a3aba15055ae6cbcf83af0faf16affc179 100644
(file)
--- a/
rrqnet.c
+++ b/
rrqnet.c
@@
-24,7
+24,7
@@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#include <sys/time
b
.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
@@
-66,13
+66,13
@@
struct Allowed {
struct Remote {
struct SockAddr uaddr;
struct Allowed *spec; // Rule being instantiated
struct Remote {
struct SockAddr uaddr;
struct Allowed *spec; // Rule being instantiated
- struct time
b rec_when;
// Last received packet time, in seconds
+ struct time
val rec_when;
// Last received packet time, in seconds
};
// Details of an interface at a remote.
struct Interface {
unsigned char mac[6]; // MAC address used last (key for by_mac table)
};
// Details of an interface at a remote.
struct Interface {
unsigned char mac[6]; // MAC address used last (key for by_mac table)
- struct time
b rec_when;
// Last packet time, in seconds
+ struct time
val rec_when;
// Last packet time, in seconds
struct Remote *remote;
};
struct Remote *remote;
};
@@
-89,21
+89,20
@@
typedef struct _PacketItem {
// heartbeat interval, in seconds
#define HEARTBEAT 30
// heartbeat interval, in seconds
#define HEARTBEAT 30
-#define HEARTBEAT_MI
LLIS ( HEARTBEAT * 1
000 )
+#define HEARTBEAT_MI
CROS ( HEARTBEAT * 1000
000 )
-// Macros for timing, for struct time
b
variables
-#define TIME
B_MILLIS(TM) (((int64_t) (TM)->time * 1000) + (TM)->millitm
)
-#define DIFF
B_MILLIS(TM1,TM2) ( TIMEB_MILLIS(TM1) - TIMEB_MILLI
S(TM2) )
+// Macros for timing, for struct time
val
variables
+#define TIME
_MICROS(TM) (((int64_t) (TM)->tv_sec * 1000000) + (TM)->tv_usec
)
+#define DIFF
_MICROS(TM1,TM2) ( TIME_MICROS(TM1) - TIME_MICRO
S(TM2) )
// RECENT(T,M) is the time logic for requiring a gap time (in
// milliseconds) before shifting a MAC to a new remote. The limit is
// 6000 for broadcast and 20000 for unicast.
#define RECENT(T,M) ((M) < ((T)? 6000 : 20000 ))
// RECENT(T,M) is the time logic for requiring a gap time (in
// milliseconds) before shifting a MAC to a new remote. The limit is
// 6000 for broadcast and 20000 for unicast.
#define RECENT(T,M) ((M) < ((T)? 6000 : 20000 ))
-// VERYOLD_MI
LLI
S is used for discarding downlink remotes whose latest
+// VERYOLD_MI
CROS
S is used for discarding downlink remotes whose latest
// activity is older than this.
// activity is older than this.
-#define VERYOLD_MILLIS 180000
-
+#define VERYOLD_MICROS 180000000
////////// Variables
////////// Variables
@@
-979,10
+978,10
@@
static struct Interface *input_check(
{
VERBOSE2OUT( "RECV %ld bytes from %s\n", len, inet_stoa( src ) );
struct Remote *r = 0;
{
VERBOSE2OUT( "RECV %ld bytes from %s\n", len, inet_stoa( src ) );
struct Remote *r = 0;
- struct time
b
now = { 0 };
- if (
ftime( &now
) ) {
+ struct time
val
now = { 0 };
+ if (
gettimeofday( &now, 0
) ) {
perror( "RECV time" );
perror( "RECV time" );
- now.t
ime
= time( 0 );
+ now.t
v_sec
= time( 0 );
}
Remote_FIND( src, r );
if ( r == 0 ) {
}
Remote_FIND( src, r );
if ( r == 0 ) {
@@
-1065,7
+1064,7
@@
static struct Interface *input_check(
// primary channel, or the time since the last packet for that
// interface is less than RECENT, with different limits for
// broadcast and unicast.
// primary channel, or the time since the last packet for that
// interface is less than RECENT, with different limits for
// broadcast and unicast.
- int64_t dmac = DIFF
B_MILLI
S( &now, &x->rec_when);
+ int64_t dmac = DIFF
_MICRO
S( &now, &x->rec_when);
if ( x->remote->spec == 0 || RECENT( *buf & 1, dmac ) ) {
if ( verbose >= 2 ) {
fprintf(
if ( x->remote->spec == 0 || RECENT( *buf & 1, dmac ) ) {
if ( verbose >= 2 ) {
fprintf(
@@
-1126,10
+1125,10
@@
static void route_packet(unsigned char *buf,int len,struct SockAddr *src) {
}
// broadcast. +x+ is source interface
// x->rec_when is not updated
}
// broadcast. +x+ is source interface
// x->rec_when is not updated
- struct time
b
now = { 0 };
- if (
ftime( &now
) ) {
+ struct time
val
now = { 0 };
+ if (
gettimeofday( &now, 0
) ) {
perror( "RECV time" );
perror( "RECV time" );
- now.t
ime
= time( 0 );
+ now.t
v_sec
= time( 0 );
}
VERBOSE2OUT( "BC %s -> %s from %s\n",
inet_mtoa( buf+6 ), inet_mtoa( buf ),
}
VERBOSE2OUT( "BC %s -> %s from %s\n",
inet_mtoa( buf+6 ), inet_mtoa( buf ),
@@
-1149,11
+1148,11
@@
static void route_packet(unsigned char *buf,int len,struct SockAddr *src) {
continue;
}
if ( r->spec && ! is_uplink( r->spec ) &&
continue;
}
if ( r->spec && ! is_uplink( r->spec ) &&
- DIFF
B_MILLIS( &now, &r->rec_when ) > VERYOLD_MILLI
S ) {
+ DIFF
_MICROS( &now, &r->rec_when ) > VERYOLD_MICRO
S ) {
// remove old downlink connection
VERBOSEOUT( "Old remote discarded %s (%ld)\n",
inet_stoa( &r->uaddr ),
// remove old downlink connection
VERBOSEOUT( "Old remote discarded %s (%ld)\n",
inet_stoa( &r->uaddr ),
- TIME
B_MILLI
S( &r->rec_when ) );
+ TIME
_MICRO
S( &r->rec_when ) );
// Removing a downlink might have threading implications
delete_remote( r );
continue;
// Removing a downlink might have threading implications
delete_remote( r );
continue;
@@
-1227,7
+1226,8
@@
static void doreadUDP(int fd) {
exit( 1 );
}
#ifdef GPROF
exit( 1 );
}
#ifdef GPROF
- if ( len == 17 && memcmp( buf, "STOPSTOPSTOPSTOP", 16 ) == 0 ) {
+ if ( todo->len == 17 &&
+ memcmp( todo->buffer, "STOPSTOPSTOPSTOP", 16 ) == 0 ) {
exit( 0 );
}
#endif
exit( 0 );
}
#endif
@@
-1288,11
+1288,11
@@
static void heartbeat(int fd) {
VERBOSE3OUT( "heartbeat fd=%d\n", fd );
struct Remote *r;
unsigned int i = 0;
VERBOSE3OUT( "heartbeat fd=%d\n", fd );
struct Remote *r;
unsigned int i = 0;
- struct time
b
now;
- if (
ftime( &now
) ) {
+ struct time
val
now;
+ if (
gettimeofday( &now, 0
) ) {
perror( "HEARTBEAT time" );
perror( "HEARTBEAT time" );
- now.t
ime
= time( 0 );
- now.
millitm
= 0;
+ now.t
v_sec
= time( 0 );
+ now.
tv_usec
= 0;
}
Remote_LOCK;
for ( ; i < remotes.by_addr.size; i++ ) {
}
Remote_LOCK;
for ( ; i < remotes.by_addr.size; i++ ) {
@@
-1303,7
+1303,7
@@
static void heartbeat(int fd) {
r = (struct Remote *) tmp;
VERBOSE3OUT( "heartbeat check %s\n", inet_stoa( &r->uaddr ) );
if ( r->spec && is_uplink( r->spec ) ) {
r = (struct Remote *) tmp;
VERBOSE3OUT( "heartbeat check %s\n", inet_stoa( &r->uaddr ) );
if ( r->spec && is_uplink( r->spec ) ) {
- if ( DIFF
B_MILLIS( &now, &r->rec_when ) > HEARTBEAT_MILLI
S ) {
+ if ( DIFF
_MICROS( &now, &r->rec_when ) > HEARTBEAT_MICRO
S ) {
VERBOSE3OUT( "heartbeat %s\n", inet_stoa( &r->uaddr ) );
write_remote( data, 0, r );
}
VERBOSE3OUT( "heartbeat %s\n", inet_stoa( &r->uaddr ) );
write_remote( data, 0, r );
}