summaryrefslogtreecommitdiff
path: root/networking/pscan.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-06-17 19:09:05 +0000
committerDenis Vlasenko2007-06-17 19:09:05 +0000
commit459be35234cc24b69309eb0ee22600024c73713e (patch)
tree15ac4122d9c42ec75ba68d342827e37fcb1306ed /networking/pscan.c
parente79dd06782175d50f639180cde5b2c56933aa2ee (diff)
downloadbusybox-459be35234cc24b69309eb0ee22600024c73713e.zip
busybox-459be35234cc24b69309eb0ee22600024c73713e.tar.gz
hwclock: size optimizations
libbb/time.c: new file, introducing monotonic_us() pscan, traceroute, arping: use it instead of gettimeofday ping, zcip: TODO function old new delta monotonic_us - 89 +89 find_pair 164 180 +16 .rodata 129747 129763 +16 refresh 1144 1152 +8 ............ timeout 8 4 -4 static.start 8 4 -4 last 8 4 -4 parse_conf 1303 1284 -19 time_main 1149 1124 -25 gettimeofday_us 39 - -39 arping_main 2042 1969 -73 hwclock_main 594 501 -93 catcher 485 380 -105 traceroute_main 4300 4117 -183 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 8/11 up/down: 157/-562) Total: -405 bytes
Diffstat (limited to 'networking/pscan.c')
-rw-r--r--networking/pscan.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/networking/pscan.c b/networking/pscan.c
index 10bf3b6..9fa6993 100644
--- a/networking/pscan.c
+++ b/networking/pscan.c
@@ -17,19 +17,6 @@
#define DERR(...) ((void)0)
#endif
-/* return time in usec */
-// TODO: move to libbb and use in traceroute, zcip, arping etc
-// (maybe also use absolute monotonic clock - no time warps
-// due to admin resetting date/time?)
-static unsigned gettimeofday_us(void)
-{
- struct timeval now;
-
- if (gettimeofday(&now, NULL))
- return 0;
- return (now.tv_sec * 1000000 + now.tv_usec);
-}
-
static const char *port_name(unsigned port)
{
struct servent *server;
@@ -40,6 +27,9 @@ static const char *port_name(unsigned port)
return "unknown";
}
+/* We don't expect to see 1000+ seconds delay, unsigned is enough */
+#define MONOTONIC_US() ((unsigned)monotonic_us())
+
int pscan_main(int argc, char **argv);
int pscan_main(int argc, char **argv)
{
@@ -91,7 +81,7 @@ int pscan_main(int argc, char **argv)
/* Nonblocking connect typically "fails" with errno == EINPROGRESS */
ndelay_on(s);
DMSG("connect to port %u", port);
- start = gettimeofday_us();
+ start = MONOTONIC_US();
if (connect(s, &lsap->sa, lsap->len) == 0) {
/* Unlikely, for me even localhost fails :) */
DMSG("connect succeeded");
@@ -110,15 +100,15 @@ int pscan_main(int argc, char **argv)
closed_ports++;
break;
}
- DERR("port %u errno %d @%u", port, errno, gettimeofday_us() - start);
- if ((gettimeofday_us() - start) > rtt_4)
+ DERR("port %u errno %d @%u", port, errno, MONOTONIC_US() - start);
+ if ((MONOTONIC_US() - start) > rtt_4)
break;
/* Can sleep (much) longer than specified delay.
* We check rtt BEFORE we usleep, otherwise
* on localhost we'll do zero writes done (!)
* before we exceed (rather small) rtt */
usleep(rtt_4/8);
- DMSG("write to port %u @%u", port, gettimeofday_us() - start);
+ DMSG("write to port %u @%u", port, MONOTONIC_US() - start);
if (write(s, " ", 1) >= 0) { /* We were able to write to the socket */
open:
open_ports++;
@@ -126,13 +116,13 @@ int pscan_main(int argc, char **argv)
break;
}
}
- DMSG("out of loop @%u", gettimeofday_us() - start);
+ DMSG("out of loop @%u", MONOTONIC_US() - start);
/* Estimate new rtt - we don't want to wait entire timeout
* for each port. *4 allows for rise in net delay.
* We increase rtt quickly (*4), decrease slowly (4/8 == 1/2)
* because we don't want to accidentally miss ports. */
- rtt_4 = (gettimeofday_us() - start) * 4;
+ rtt_4 = (MONOTONIC_US() - start) * 4;
if (rtt_4 < min_rtt)
rtt_4 = min_rtt;
if (rtt_4 > timeout)