Added fixes suggested in PR

This commit is contained in:
Tomer Lev 2022-11-10 19:01:29 +02:00
parent 9a74be1558
commit e2be5ddc0c
2 changed files with 15 additions and 3 deletions

View file

@ -202,10 +202,16 @@ void File::SetBuf(bool arg_buffered)
if ( ! f ) if ( ! f )
return; return;
#ifndef _MSC_VER
if ( setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 ) if ( setvbuf(f, NULL, arg_buffered ? _IOFBF : _IOLBF, 0) != 0 )
reporter->Error("setvbuf failed"); #else
// TODO: this turns off buffering altogether because Windows wants us to pass a valid
// buffer and length if we're going to pass one of the other modes. We need to
// investigate the performance ramifications of this.
if ( setvbuf(f, NULL, _IONBF, 0) != 0 )
#endif reporter->Error("setvbuf failed");
buffered = arg_buffered; buffered = arg_buffered;
} }
bool File::Close() bool File::Close()

View file

@ -2038,9 +2038,15 @@ RETSIGTYPE sig_handler(int signo);
double current_time(bool real) double current_time(bool real)
{ {
struct timeval tv; struct timeval tv;
#ifdef _MSC_VER
auto now = std::chrono::system_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
tv.tv_sec = ms.count() / 1000;
tv.tv_usec = (ms.count() % 1000) * 1000;
#else
if ( gettimeofday(&tv, 0) < 0 ) if ( gettimeofday(&tv, 0) < 0 )
reporter->InternalError("gettimeofday failed in current_time()"); reporter->InternalError("gettimeofday failed in current_time()");
#endif
double t = double(tv.tv_sec) + double(tv.tv_usec) / 1e6; double t = double(tv.tv_sec) + double(tv.tv_usec) / 1e6;
if ( ! run_state::pseudo_realtime || real || ! iosource_mgr || ! iosource_mgr->GetPktSrc() ) if ( ! run_state::pseudo_realtime || real || ! iosource_mgr || ! iosource_mgr->GetPktSrc() )