Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if (LIBCORO_RUN_GITCONFIG)
endif()

cmake_dependent_option(LIBCORO_FEATURE_NETWORKING "Include networking features, Default=ON." ON "NOT EMSCRIPTEN; NOT MSVC" OFF)
cmake_dependent_option(LIBCORO_FEATURE_TLS "Include TLS encryption features, Default=ON." ON "NOT EMSCRIPTEN; NOT MSVC" OFF)
cmake_dependent_option(LIBCORO_FEATURE_TLS "Include TLS encryption features, Default=ON." ON "NOT EMSCRIPTEN; NOT MSVC; NOT MINGW" OFF)

message(STATUS "LIBCORO_ENABLE_ASAN = ${LIBCORO_ENABLE_ASAN}")
message(STATUS "LIBCORO_ENABLE_MSAN = ${LIBCORO_ENABLE_MSAN}")
Expand Down Expand Up @@ -163,6 +163,13 @@ if(LIBCORO_FEATURE_NETWORKING)
include/coro/detail/io_notifier_kqueue.hpp src/detail/io_notifier_kqueue.cpp
)
endif()
if (WIN32)
list(APPEND LIBCORO_SOURCE_FILES
include/coro/detail/win32_headers.hpp
include/coro/detail/platform.hpp
include/coro/detail/io_notifier_iocp.hpp src/detail/io_notifier_iocp.cpp
)
endif()


list(APPEND LIBCORO_SOURCE_FILES
Expand Down
21 changes: 21 additions & 0 deletions include/coro/detail/io_notifier_iocp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "coro/detail/win32_headers.hpp"
#include "coro/fd.hpp"
#include <chrono>

namespace coro::detail
{
class timer_handle;

class io_notifier_iocp
{
public:
io_notifier_iocp() { m_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 0); }

~io_notifier_iocp() { CloseHandle(m_handle); }

private:
void* m_handle;
};
} // namespace coro::detail
15 changes: 15 additions & 0 deletions include/coro/detail/platform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#if defined(_WIN32) || defined(_WIN64)
#define LIBCORO_PLATFORM_WINDOWS
#endif

#if defined(__linux) || defined(__linux__)
#define LIBCORO_PLATFORM_LINUX
#define LIBCORO_PLATFORM_UNIX
#endif

#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define LIBCORO_PLATFORM_BSD
#define LIBCORO_PLATFORM_UNIX
#endif
16 changes: 16 additions & 0 deletions include/coro/detail/win32_headers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>

// Link with ws2_32.lib
#pragma comment(lib, "ws2_32.lib")
13 changes: 9 additions & 4 deletions include/coro/io_notifier.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
#pragma once
#include "coro/detail/platform.hpp"

#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
#if defined(LIBCORO_PLATFORM_BSD)
#include "coro/detail/io_notifier_kqueue.hpp"
#elif defined(__linux__)
#elif defined(LIBCORO_PLATFORM_LINUX)
#include "coro/detail/io_notifier_epoll.hpp"
#elif defined(LIBCORO_PLATFORM_WINDOWS)
#include "coro/detail/io_notifier_iocp.hpp"
#endif

namespace coro
{

#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
#if defined(LIBCORO_PLATFORM_BSD)
using io_notifier = detail::io_notifier_kqueue;
#elif defined(__linux__)
#elif defined(LIBCORO_PLATFORM_LINUX)
using io_notifier = detail::io_notifier_epoll;
#elif defined(LIBCORO_PLATFORM_WINDOWS)
using io_notifier = detail::io_notifier_iocp;
#endif

} // namespace coro
9 changes: 8 additions & 1 deletion include/coro/net/ip_address.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#pragma once

#include <algorithm>
#include <arpa/inet.h>
#include <array>
#include <cstring>
#include <span>
#include <stdexcept>
#include <string>

#include "coro/detail/platform.hpp"
#if defined(LIBCORO_PLATFORM_WINDOWS)
#include "coro/detail/win32_headers.hpp"
#elif defined(LIBCORO_PLATFORM_UNIX)
#include <arpa/inet.h>
#endif

namespace coro::net
{
enum class domain_t : int
Expand Down Expand Up @@ -62,6 +68,7 @@ class ip_address
ip_address addr{};
addr.m_domain = domain;

// FIXME: inet_pton expects a null-terminated string, std::string_view doesn't guarantee it
auto success = inet_pton(static_cast<int>(addr.m_domain), address.data(), addr.m_data.data());
if (success != 1)
{
Expand Down
8 changes: 8 additions & 0 deletions src/detail/io_notifier_iocp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "coro/detail/io_notifier_iocp.hpp"
#include "coro/detail/timer_handle.hpp"
#include <stdexcept>

auto coro::detail::io_notifier_iocp::watch_timer(const timer_handle& timer, std::chrono::nanoseconds duration) -> bool
{
throw std::runtime_error("watch_timer implemented");
}
Loading