summaryrefslogtreecommitdiffhomepage
path: root/NetEx
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-03-30 21:38:27 +0200
committerAki <please@ignore.pl>2022-03-30 21:38:27 +0200
commite2a9666f356ab0a71ef10113ed0b0b696ddf1075 (patch)
treee082788590665d9bb341a12d3f09ca183ee9fac3 /NetEx
parent5ec69c1f7ce048f16302feaddc76778003bb4d71 (diff)
downloadstarshatter-e2a9666f356ab0a71ef10113ed0b0b696ddf1075.zip
starshatter-e2a9666f356ab0a71ef10113ed0b0b696ddf1075.tar.gz
starshatter-e2a9666f356ab0a71ef10113ed0b0b696ddf1075.tar.bz2
Removed windows header usage in NetClient
Diffstat (limited to 'NetEx')
-rw-r--r--NetEx/NetClient.cpp27
-rw-r--r--NetEx/NetClient.h7
2 files changed, 23 insertions, 11 deletions
diff --git a/NetEx/NetClient.cpp b/NetEx/NetClient.cpp
index 8c9ee51..7a62160 100644
--- a/NetEx/NetClient.cpp
+++ b/NetEx/NetClient.cpp
@@ -13,7 +13,10 @@
#include "NetClient.h"
-#include <windows.h>
+#include <chrono>
+#include <cstdint>
+#include <ratio>
+#include <thread>
#include "NetAddr.h"
#include "NetSock.h"
@@ -23,8 +26,8 @@
NetClient::NetClient(const NetAddr& server_addr) :
addr(server_addr),
sock(nullptr),
- delta(0),
- time(0),
+ delta(std::chrono::high_resolution_clock::duration::zero()),
+ time(),
err(0)
{
}
@@ -45,8 +48,8 @@ NetClient::Send(Text msg)
delete sock;
sock = new NetSock(addr, true);
- delta = 0;
- time = timeGetTime();
+ delta = std::chrono::high_resolution_clock::duration::zero();
+ time = std::chrono::high_resolution_clock::now();
if (!sock) {
err = ERR_NOBUFS;
@@ -85,8 +88,8 @@ NetClient::Recv()
if (sock) {
int ready = sock->select();
- while (!ready && timeGetTime() - time < 2000) {
- Sleep(5);
+ while (!ready && std::chrono::high_resolution_clock::now() - time < std::chrono::seconds(2000)) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(5));
ready = sock->select();
}
@@ -98,7 +101,7 @@ NetClient::Recv()
msg = sock->recv();
}
- delta = timeGetTime() - time;
+ delta = std::chrono::high_resolution_clock::now() - time;
}
delete sock;
@@ -120,3 +123,11 @@ NetClient::SendRecv(Text msg)
return response;
}
+
+
+std::uint32_t
+NetClient::GetTime() const
+{
+ using target_duration = std::chrono::duration<std::uint32_t, std::milli>;
+ return std::chrono::duration_cast<target_duration>(delta).count();
+}
diff --git a/NetEx/NetClient.h b/NetEx/NetClient.h
index 5bd7d10..db5543d 100644
--- a/NetEx/NetClient.h
+++ b/NetEx/NetClient.h
@@ -14,6 +14,7 @@
#ifndef NetClient_h
#define NetClient_h
+#include <chrono>
#include <cstdint>
#include "NetAddr.h"
@@ -38,13 +39,13 @@ public:
Text SendRecv(Text msg);
int GetLastError() const { return err; }
- std::uint32_t GetTime() const { return delta; }
+ std::uint32_t GetTime() const;
protected:
NetAddr addr;
NetSock* sock;
- std::uint32_t delta;
- std::uint32_t time;
+ std::chrono::high_resolution_clock::duration delta;
+ std::chrono::high_resolution_clock::time_point time;
int err;
public: