merged Gerrit's nanosleep patch
tweaked type of currLen as fixup for Nathan's patch
This commit is contained in:
parent
0c9092408e
commit
bd8c92d8f6
3
AUTHORS
3
AUTHORS
@ -31,3 +31,6 @@ Stephen Hemminger <shemminger@linux-foundation.org>
|
|||||||
|
|
||||||
Nathan Jones <nmjones@users.sourceforge.net>
|
Nathan Jones <nmjones@users.sourceforge.net>
|
||||||
* patch for underflow when value specified in -n is not a multiple of -l
|
* patch for underflow when value specified in -n is not a multiple of -l
|
||||||
|
|
||||||
|
Gerrit Renker <grenker@users.sourceforge.net>
|
||||||
|
* replace costly gettimeofday() with nanonsleep()
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
2008-05-09 Gerrit Renker <grenker@users.sourceforge.net>
|
||||||
|
|
||||||
|
* replace costly gettimeofday() with nanonsleep() See:
|
||||||
|
https://sourceforge.net/tracker/index.php?func=detail&aid=1940009&group_id=128336&atid=711373
|
||||||
|
|
||||||
|
2008-05-09 Jon Dugan <jdugan@x1024.net>
|
||||||
|
|
||||||
|
* change currLen to unsigned to squelch warning generated by Nathan's patch
|
||||||
|
|
||||||
2008-05-09 Nathan Jones <nmjones@users.sourceforge.net>
|
2008-05-09 Nathan Jones <nmjones@users.sourceforge.net>
|
||||||
|
|
||||||
* prevent underflow when the amount of data to be transmitted (-n) is not a
|
* prevent underflow when the amount of data to be transmitted (-n) is not a
|
||||||
|
@ -51,24 +51,26 @@
|
|||||||
* ------------------------------------------------------------------- */
|
* ------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include "Timestamp.hpp"
|
#include "Timestamp.hpp"
|
||||||
|
#include "util.h"
|
||||||
#include "delay.hpp"
|
#include "delay.hpp"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
* A micro-second delay function. This uses gettimeofday (underneith
|
* A micro-second delay function using POSIX nanosleep(). This allows a
|
||||||
* the Timestamp) which has a resolution of upto microseconds. I've
|
* higher timing resolution (under Linux e.g. it uses hrtimers), does not
|
||||||
* found it's good to within about 10 usecs.
|
* affect any signals, and will use up remaining time when interrupted.
|
||||||
* I used to do calibration, but iperf automatically adjusts itself
|
|
||||||
* so that isn't necesary, and it causes some problems if the
|
|
||||||
* calibration adjustment is larger than your sleep time.
|
|
||||||
* ------------------------------------------------------------------- */
|
* ------------------------------------------------------------------- */
|
||||||
|
void delay_loop(unsigned long usec)
|
||||||
|
{
|
||||||
|
struct timespec requested, remaining;
|
||||||
|
|
||||||
void delay_loop( unsigned long usec ) {
|
requested.tv_sec = 0;
|
||||||
Timestamp end;
|
requested.tv_nsec = usec * 1000L;
|
||||||
end.add( usec * 1e-6 );
|
|
||||||
|
|
||||||
Timestamp now;
|
while (nanosleep(&requested, &remaining) == -1)
|
||||||
while ( now.before( end ) ) {
|
if (errno == EINTR)
|
||||||
now.setnow();
|
requested = remaining;
|
||||||
|
else {
|
||||||
|
WARN_errno(1, "nanosleep");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,16 @@ public:
|
|||||||
(mTime.tv_usec - right.tv_usec);
|
(mTime.tv_usec - right.tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------
|
||||||
|
* Return the number of microseconds from now to last time of setting.
|
||||||
|
* ------------------------------------------------------------------- */
|
||||||
|
long delta_usec(void) {
|
||||||
|
struct timeval previous = mTime;
|
||||||
|
|
||||||
|
setnow();
|
||||||
|
return subUsec(previous);
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
* subtract the right timestamp from my timestamp.
|
* subtract the right timestamp from my timestamp.
|
||||||
* return the difference in seconds as a floating point.
|
* return the difference in seconds as a floating point.
|
||||||
@ -199,15 +209,6 @@ public:
|
|||||||
mTime.tv_usec < kMillion );
|
mTime.tv_usec < kMillion );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
|
||||||
* return true if my timestamp is before the right timestamp.
|
|
||||||
* ------------------------------------------------------------------- */
|
|
||||||
bool before( Timestamp right ) {
|
|
||||||
return mTime.tv_sec < right.mTime.tv_sec ||
|
|
||||||
(mTime.tv_sec == right.mTime.tv_sec &&
|
|
||||||
mTime.tv_usec < right.mTime.tv_usec);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
* return true if my timestamp is before the right timestamp.
|
* return true if my timestamp is before the right timestamp.
|
||||||
* ------------------------------------------------------------------- */
|
* ------------------------------------------------------------------- */
|
||||||
@ -216,15 +217,17 @@ public:
|
|||||||
(mTime.tv_sec == right.tv_sec &&
|
(mTime.tv_sec == right.tv_sec &&
|
||||||
mTime.tv_usec < right.tv_usec);
|
mTime.tv_usec < right.tv_usec);
|
||||||
}
|
}
|
||||||
|
bool before( Timestamp right ) { return before(right.mTime); }
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
* return true if my timestamp is after the right timestamp.
|
* return true if my timestamp is after the right timestamp.
|
||||||
* ------------------------------------------------------------------- */
|
* ------------------------------------------------------------------- */
|
||||||
bool after( Timestamp right ) {
|
bool after( timeval right ) {
|
||||||
return mTime.tv_sec > right.mTime.tv_sec ||
|
return mTime.tv_sec > right.tv_sec ||
|
||||||
(mTime.tv_sec == right.mTime.tv_sec &&
|
(mTime.tv_sec == right.tv_sec &&
|
||||||
mTime.tv_usec > right.mTime.tv_usec);
|
mTime.tv_usec > right.tv_usec);
|
||||||
}
|
}
|
||||||
|
bool after( Timestamp right ) { return after(right.mTime); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function returns the fraction of time elapsed after the beginning
|
* This function returns the fraction of time elapsed after the beginning
|
||||||
|
@ -116,7 +116,7 @@ const double kSecs_to_usecs = 1e6;
|
|||||||
const int kBytes_to_Bits = 8;
|
const int kBytes_to_Bits = 8;
|
||||||
|
|
||||||
void Client::RunTCP( void ) {
|
void Client::RunTCP( void ) {
|
||||||
long currLen = 0;
|
unsigned long currLen = 0;
|
||||||
struct itimerval it;
|
struct itimerval it;
|
||||||
max_size_t totLen = 0;
|
max_size_t totLen = 0;
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ void Client::RunTCP( void ) {
|
|||||||
|
|
||||||
void Client::Run( void ) {
|
void Client::Run( void ) {
|
||||||
struct UDP_datagram* mBuf_UDP = (struct UDP_datagram*) mBuf;
|
struct UDP_datagram* mBuf_UDP = (struct UDP_datagram*) mBuf;
|
||||||
long currLen = 0;
|
unsigned long currLen = 0;
|
||||||
|
|
||||||
int delay_target = 0;
|
int delay_target = 0;
|
||||||
int delay = 0;
|
int delay = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user