30template<
typename T,
size_t PoolSize = 1024>
31class TArenaAllocator {
38 for (
auto block : Pools_) {
39 ::operator
delete(block);
44 if (FreePages_.empty()) {
48 T* ret = FreePages_.top();
53 void deallocate(T* obj) {
59 return AllocatedObjects_;
64 T* pool =
static_cast<T*
>(::operator
new(PoolSize *
sizeof(T)));
65 Pools_.emplace_back(pool);
66 for (
size_t i = 0; i < PoolSize; i++) {
67 FreePages_.push(&pool[i]);
71 std::vector<T*> Pools_;
72 std::stack<T*> FreePages_;
73 int AllocatedObjects_ = 0;
118 void Read(
int fd,
void* buf,
int size, std::coroutine_handle<> handle);
127 void Write(
int fd,
const void* buf,
int size, std::coroutine_handle<> handle);
136 void Recv(
int fd,
void* buf,
int size, std::coroutine_handle<> handle);
145 void Send(
int fd,
const void* buf,
int size, std::coroutine_handle<> handle);
154 void Accept(
int fd,
struct sockaddr* addr, socklen_t* len, std::coroutine_handle<> handle);
163 void Connect(
int fd,
const sockaddr* addr, socklen_t len, std::coroutine_handle<> handle);
191 OVERLAPPED overlapped;
193 struct sockaddr* addr =
nullptr;
194 socklen_t* len =
nullptr;
198 memset(&overlapped, 0,
sizeof(overlapped));
209 TArenaAllocator<TIO> Allocator_;
210 std::vector<OVERLAPPED_ENTRY> Entries_;
211 std::queue<int> Results_;
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.
NNet::TPollerDrivenSocket< TIOCp > TSocket
Alias for the poller-driven socket type.
Definition iocp.hpp:104
void Accept(int fd, struct sockaddr *addr, socklen_t *len, std::coroutine_handle<> handle)
Posts an asynchronous accept operation.
NNet::TPollerDrivenFileHandle< TIOCp > TFileHandle
Alias for the poller-driven file handle type.
Definition iocp.hpp:106
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.
TPollerBase()=default
Default constructor.
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