COROIO: coroio/backends/iocp.hpp Source File
COROIO
 
Loading...
Searching...
No Matches
iocp.hpp
1#pragma once
2
3#include <coroio/base.hpp>
4#include <coroio/socket.hpp>
5#include <coroio/poller.hpp>
6#include <coroio/arena.hpp>
7
8namespace NNet {
9
35class TIOCp: public TPollerBase {
36public:
41
42 TIOCp();
43 ~TIOCp();
52 void Read(int fd, void* buf, int size, std::coroutine_handle<> handle);
61 void Write(int fd, const void* buf, int size, std::coroutine_handle<> handle);
70 void Recv(int fd, void* buf, int size, std::coroutine_handle<> handle);
79 void Send(int fd, const void* buf, int size, std::coroutine_handle<> handle);
88 void Accept(int fd, struct sockaddr* addr, socklen_t* len, std::coroutine_handle<> handle);
97 void Connect(int fd, const sockaddr* addr, socklen_t len, std::coroutine_handle<> handle);
103 void Cancel(int fd);
109 void Register(int fd);
115 int Result();
121 void Poll();
122
123private:
124 struct TIO {
125 OVERLAPPED overlapped;
126 THandle handle;
127 struct sockaddr* addr = nullptr; // for accept
128 socklen_t* len = nullptr; // for accept
129 int sock = -1; // for accept
130
131 TIO() {
132 memset(&overlapped, 0, sizeof(overlapped));
133 }
134 };
135
136 long GetTimeoutMs();
137 TIO* NewTIO();
138 void FreeTIO(TIO*);
139
140 HANDLE Port_;
141
142 // Allocator to avoid dynamic memory allocation for each IOCP event structure.
143 TArenaAllocator<TIO> Allocator_;
144 std::vector<OVERLAPPED_ENTRY> Entries_;
145 std::queue<int> Results_;
146};
147
148}
IOCP-based poller for asynchronous I/O on Windows.
Definition iocp.hpp:35
void Register(int fd)
Registers a file descriptor with the IOCP.
void Recv(int fd, void *buf, int size, std::coroutine_handle<> handle)
Posts an asynchronous receive operation.
void Cancel(int fd)
Cancels all pending operations on the specified file descriptor.
void Accept(int fd, struct sockaddr *addr, socklen_t *len, std::coroutine_handle<> handle)
Posts an asynchronous accept operation.
void Send(int fd, const void *buf, int size, std::coroutine_handle<> handle)
Posts an asynchronous send operation.
void Poll()
Polls for IOCP events.
void Read(int fd, void *buf, int size, std::coroutine_handle<> handle)
Posts an asynchronous read operation.
void Connect(int fd, const sockaddr *addr, socklen_t len, std::coroutine_handle<> handle)
Posts an asynchronous connect operation.
int Result()
Retrieves the result of the last completed IOCP operation.
void Write(int fd, const void *buf, int size, std::coroutine_handle<> handle)
Posts an asynchronous write operation.
Base class for pollers managing asynchronous I/O events and timers.
Definition poller.hpp:52
Asynchronous file handle driven by the poller's implementation.
Definition socket.hpp:742
Socket type driven by the poller's implementation.
Definition socket.hpp:519