Skip to content

Commit

Permalink
Win32 preparations (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
resetius authored Nov 10, 2024
1 parent 57a7335 commit d0960a1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion coroio/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ GetDurationPair(TTime now, TTime deadline, std::chrono::milliseconds maxDuration
inline timespec GetTimespec(TTime now, TTime deadline, std::chrono::milliseconds maxDuration)
{
auto [p1, p2] = GetDurationPair<std::chrono::seconds, std::chrono::nanoseconds>(now, deadline, maxDuration);
return {p1.count(), p2.count()};
timespec ret;
ret.tv_sec = p1.count();
ret.tv_nsec = p2.count();
return ret;
}

} // namespace NNet
5 changes: 5 additions & 0 deletions coroio/poll.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#pragma once

#ifdef _WIN32
#include <winsock2.h>
#else
#include <poll.h>
#endif

#include <assert.h>

#include <iostream>
Expand Down
9 changes: 8 additions & 1 deletion coroio/poller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

#include "base.hpp"

#ifdef Yield
#undef Yield
#endif

namespace NNet {

class TPollerBase {
Expand Down Expand Up @@ -142,7 +146,10 @@ class TPollerBase {
static constexpr timespec GetMaxDuration(std::chrono::milliseconds duration) {
auto p1 = std::chrono::duration_cast<std::chrono::seconds>(duration);
auto p2 = std::chrono::duration_cast<std::chrono::nanoseconds>(duration - p1);
return {p1.count(), p2.count()};
timespec ts;
ts.tv_sec = p1.count();
ts.tv_nsec = p2.count();
return ts;
}

void Reset() {
Expand Down
4 changes: 4 additions & 0 deletions coroio/select.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/select.h>
#endif
#include <assert.h>
#include <system_error>

Expand Down
5 changes: 5 additions & 0 deletions coroio/socket.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#pragma once

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#endif

#include <variant>

Expand Down

0 comments on commit d0960a1

Please sign in to comment.