From 6fa2ed2003709e6cf668c3b76e1a0fbb9eca3a33 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 13 Oct 2016 21:29:18 +0200 Subject: [PATCH] [DEV] remove dependency of unistd.h --- enet/Http.cpp | 6 +++--- enet/TcpClient.cpp | 12 ++++++------ enet/WebSocket.cpp | 4 ++-- test/main-client-http.cpp | 4 ++-- test/main-client-websocket.cpp | 4 ++-- test/main-server-http.cpp | 4 ++-- test/main-server-websocket.cpp | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/enet/Http.cpp b/enet/Http.cpp index ccc90ce..f65e2af 100644 --- a/enet/Http.cpp +++ b/enet/Http.cpp @@ -9,7 +9,7 @@ #include #include #include -#include + static std::string escapeChar(const std::string& _value) { return _value; @@ -147,7 +147,7 @@ void enet::Http::start() { } while ( m_threadRunning == true && m_connection.getConnectionStatus() != enet::Tcp::status::link) { - usleep(50000); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } //ethread::setPriority(*m_receiveThread, -6); ENET_DEBUG("connect [STOP]"); @@ -364,7 +364,7 @@ void enet::Http::getHeader() { char type; int32_t len = m_connection.read(&type, 1); if (len == 0) { - usleep(1); + std::this_thread::sleep_for(std::chrono::microseconds(1)); continue; } header += type; diff --git a/enet/TcpClient.cpp b/enet/TcpClient.cpp index 2442a2d..08dbe54 100644 --- a/enet/TcpClient.cpp +++ b/enet/TcpClient.cpp @@ -46,7 +46,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 socketId = socket(AF_INET, SOCK_STREAM, 0); if (socketId < 0) { ENET_ERROR("ERROR while opening socket : errno=" << errno << "," << strerror(errno)); - usleep(200000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } ENET_INFO("Try connect on socket ... (" << iii+1 << "/" << _numberRetry << ")"); @@ -63,7 +63,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 int iResult = getaddrinfo(_hostname.c_str(), portValue.c_str(), &hints, &result); if (iResult != 0) { ENET_ERROR("getaddrinfo failed with error: " << iResult); - usleep(200000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } @@ -92,7 +92,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 if (socketId == INVALID_SOCKET) { ENET_ERROR("Unable to connect to server!"); - usleep(200000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } else { break; @@ -119,7 +119,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 socketId = socket(AF_INET, SOCK_STREAM, 0); if (socketId < 0) { ENET_ERROR("ERROR while opening socket : errno=" << errno << "," << strerror(errno)); - usleep(200000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } ENET_INFO("Try connect on socket ... (" << iii+1 << "/" << _numberRetry << ")"); @@ -127,7 +127,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 struct hostent* server = gethostbyname(_hostname.c_str()); if (server == nullptr) { ENET_ERROR("ERROR, no such host : " << _hostname); - usleep(200000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } bzero((char *) &servAddr, sizeof(servAddr)); @@ -150,7 +150,7 @@ enet::Tcp enet::connectTcpClient(uint8_t _ip1, uint8_t _ip2, uint8_t _ip3, uint8 socketId = -1; } ENET_ERROR("ERROR connecting, maybe retry ... errno=" << errno << "," << strerror(errno)); - usleep(500000); + std::this_thread::sleep_for(std::chrono::milliseconds(200)); continue; } // if we are here ==> then the connextion is done corectly ... diff --git a/enet/WebSocket.cpp b/enet/WebSocket.cpp index bad0d40..8b5baa7 100644 --- a/enet/WebSocket.cpp +++ b/enet/WebSocket.cpp @@ -12,7 +12,7 @@ #include #include #include -#include + namespace enet { @@ -148,7 +148,7 @@ void enet::WebSocket::start(const std::string& _uri, const std::vectorisAlive() == false) { break; } - usleep(10000); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); timeout--; } if ( m_connectionValidate == false diff --git a/test/main-client-http.cpp b/test/main-client-http.cpp index a8eeef6..1b43d1a 100644 --- a/test/main-client-http.cpp +++ b/test/main-client-http.cpp @@ -12,7 +12,7 @@ #include #include -#include + namespace appl { void onReceiveData(std::vector& _data) { @@ -53,7 +53,7 @@ int main(int _argc, const char *_argv[]) { connection.setHeader(req); while (connection.isAlive() == true) { - usleep(100000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } return 0; } diff --git a/test/main-client-websocket.cpp b/test/main-client-websocket.cpp index f3172ed..597d6fb 100644 --- a/test/main-client-websocket.cpp +++ b/test/main-client-websocket.cpp @@ -13,7 +13,7 @@ #include #include -#include + namespace appl { void onReceiveData(std::vector& _data, bool _isString) { @@ -66,7 +66,7 @@ int main(int _argc, const char *_argv[]) { int32_t timeout = 20; while (connection.isAlive() == true && timeout > 0) { - usleep(100000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); timeout--; } return 0; diff --git a/test/main-server-http.cpp b/test/main-server-http.cpp index 84b6682..8e2572a 100644 --- a/test/main-server-http.cpp +++ b/test/main-server-http.cpp @@ -11,7 +11,7 @@ #include #include -#include + #include namespace appl { void onReceiveData(enet::HttpServer* _interface, std::vector& _data) { @@ -82,7 +82,7 @@ int main(int _argc, const char *_argv[]) { connection.start(); while (connection.isAlive() == true) { - usleep(100000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } diff --git a/test/main-server-websocket.cpp b/test/main-server-websocket.cpp index f7e618f..1f95c73 100644 --- a/test/main-server-websocket.cpp +++ b/test/main-server-websocket.cpp @@ -12,7 +12,7 @@ #include #include -#include + #include namespace appl { void onReceiveData(enet::WebSocket* _interface, std::vector& _data, bool _isString) { @@ -85,7 +85,7 @@ int main(int _argc, const char *_argv[]) { connection.start(); while (connection.isAlive() == true) { - usleep(100000); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } return 0; }