From 6336435f8118ab9a5d41ce7ea4a9a14459f4c1a7 Mon Sep 17 00:00:00 2001 From: Sacha Date: Sun, 13 Jul 2014 07:58:42 +1000 Subject: [PATCH] Fix a bug where it would sleep for a full second instead of a millisecond on non-Windows. --- base/buffer.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/base/buffer.cpp b/base/buffer.cpp index 49e86b09e0..6516528e9b 100644 --- a/base/buffer.cpp +++ b/base/buffer.cpp @@ -14,6 +14,7 @@ #endif #include "base/logging.h" +#include "base/timeutil.h" #include "file/fd_util.h" Buffer::Buffer() { } @@ -137,26 +138,21 @@ bool Buffer::FlushToFile(const char *filename) { } bool Buffer::FlushSocket(uintptr_t sock) { - for (size_t pos = 0, end = data_.size(); pos < end; ) { - int sent = send(sock, &data_[pos], end - pos, 0); - if (sent < 0) { - ELOG("FlushSocket failed"); - return false; - } - pos += sent; + for (size_t pos = 0, end = data_.size(); pos < end; ) { + int sent = send(sock, &data_[pos], end - pos, 0); + if (sent < 0) { + ELOG("FlushSocket failed"); + return false; + } + pos += sent; - // Buffer full, don't spin. - if (sent == 0) { -#ifdef _WIN32 - Sleep(1); -#else - sleep(1); -#endif - } - } - - data_.resize(0); - return true; + // Buffer full, don't spin. + if (sent == 0) { + sleep_ms(1); + } + } + data_.resize(0); + return true; } bool Buffer::ReadAll(int fd) {