join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
io_operation.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_CORE_IO_OPERATION_HPP
26#define JOIN_CORE_IO_OPERATION_HPP
27
28// C.
29#include <sys/socket.h>
30#include <cstdint>
31
32namespace join
33{
34 // forward declaration.
35 class CompletionHandler;
36
40 struct alignas (64) IoOperation
41 {
45 enum class State : uint8_t
46 {
47 Idle,
48 Submitted,
50 };
51
55 enum class Opcode : uint8_t
56 {
57 Accept,
58 Connect,
59 Read,
60 Write,
61 ReadFixed,
63 RecvMsg,
64 SendMsg,
65 Recv,
66 Send,
67 };
68
73 {
75 int fd;
76
78 sockaddr* addr;
79
81 socklen_t* addrlen;
82
84 int flags;
85 };
86
96 static IoOperation makeAccept (int fd, sockaddr* addr, socklen_t* addrlen, int flags,
97 CompletionHandler* handler) noexcept;
98
103 {
105 int fd;
106
108 const sockaddr* addr;
109
111 socklen_t addrlen;
112 };
113
122 static IoOperation makeConnect (int fd, const sockaddr* addr, socklen_t addrlen,
123 CompletionHandler* handler) noexcept;
124
128 struct RwData
129 {
131 int fd;
132
134 void* buf;
135
137 unsigned long len;
138
140 uint16_t index;
141
143 bool fixed;
144 };
145
155 static IoOperation makeRead (int fd, void* buf, uint32_t len, CompletionHandler* handler,
156 bool linked = false) noexcept;
157
167 static IoOperation makeWrite (int fd, const void* buf, uint32_t len, CompletionHandler* handler,
168 bool linked = false) noexcept;
169
180 static IoOperation makeReadFixed (int fd, void* buf, uint32_t len, uint16_t index, CompletionHandler* handler,
181 bool linked = false) noexcept;
182
193 static IoOperation makeWriteFixed (int fd, const void* buf, uint32_t len, uint16_t index,
194 CompletionHandler* handler, bool linked = false) noexcept;
195
199 struct MsgData
200 {
202 int fd;
203
205 msghdr* msg;
206
208 int flags;
209 };
210
220 static IoOperation makeRecvmsg (int fd, msghdr* msg, int flags, CompletionHandler* handler,
221 bool linked = false) noexcept;
222
232 static IoOperation makeSendmsg (int fd, const msghdr* msg, int flags, CompletionHandler* handler,
233 bool linked = false) noexcept;
234
239 {
241 int fd;
242
244 void* buf;
245
247 unsigned long len;
248
250 int flags;
251 };
252
263 static IoOperation makeRecv (int fd, void* buf, uint32_t len, int flags, CompletionHandler* handler,
264 bool linked = false) noexcept;
265
276 static IoOperation makeSend (int fd, const void* buf, uint32_t len, int flags, CompletionHandler* handler,
277 bool linked = false) noexcept;
278
287
292 int fd () const noexcept;
293
295 uint8_t code = 0;
296
299
301 uint32_t index = 0;
302
304 bool linked = false;
305
308
310 Data data = {};
311 };
312}
313
314#endif
completion handler interface class.
Definition proactor.hpp:75
Definition acceptor.hpp:32
payload for accept.
Definition io_operation.hpp:73
socklen_t * addrlen
peer address length.
Definition io_operation.hpp:81
int fd
file descriptor.
Definition io_operation.hpp:75
int flags
accept flags.
Definition io_operation.hpp:84
sockaddr * addr
peer address.
Definition io_operation.hpp:78
payload for connect.
Definition io_operation.hpp:103
const sockaddr * addr
remote address.
Definition io_operation.hpp:108
socklen_t addrlen
address length.
Definition io_operation.hpp:111
int fd
file descriptor.
Definition io_operation.hpp:105
payload for sendmsg / recvmsg.
Definition io_operation.hpp:200
int flags
sendmsg / recvmsg flags.
Definition io_operation.hpp:208
msghdr * msg
message header.
Definition io_operation.hpp:205
int fd
file descriptor.
Definition io_operation.hpp:202
payload for read / read fixed / write / write fixed.
Definition io_operation.hpp:129
unsigned long len
number of bytes to transfer.
Definition io_operation.hpp:137
bool fixed
use registered buffer (ignored with reactor backend).
Definition io_operation.hpp:143
uint16_t index
registered buffer index (ignored with reactor backend).
Definition io_operation.hpp:140
int fd
file descriptor.
Definition io_operation.hpp:131
void * buf
buffer.
Definition io_operation.hpp:134
payload for recv / send.
Definition io_operation.hpp:239
int fd
file descriptor.
Definition io_operation.hpp:241
unsigned long len
number of bytes to transfer.
Definition io_operation.hpp:247
int flags
send / recv flags.
Definition io_operation.hpp:250
void * buf
buffer.
Definition io_operation.hpp:244
Describes a single asynchronous operation submitted to the Proactor.
Definition io_operation.hpp:41
bool linked
link this SQE to the next one (next executes only if this succeeds, io_uring only).
Definition io_operation.hpp:304
static IoOperation makeWrite(int fd, const void *buf, uint32_t len, CompletionHandler *handler, bool linked=false) noexcept
build a regular write operation.
Definition io_operation.cpp:87
State state
operation state.
Definition io_operation.hpp:298
static IoOperation makeSendmsg(int fd, const msghdr *msg, int flags, CompletionHandler *handler, bool linked=false) noexcept
build a send-message operation.
Definition io_operation.cpp:160
static IoOperation makeConnect(int fd, const sockaddr *addr, socklen_t addrlen, CompletionHandler *handler) noexcept
build a connect operation.
Definition io_operation.cpp:53
static IoOperation makeSend(int fd, const void *buf, uint32_t len, int flags, CompletionHandler *handler, bool linked=false) noexcept
build a send operation.
Definition io_operation.cpp:195
static IoOperation makeReadFixed(int fd, void *buf, uint32_t len, uint16_t index, CompletionHandler *handler, bool linked=false) noexcept
build a fixed-buffer read operation.
Definition io_operation.cpp:106
static IoOperation makeWriteFixed(int fd, const void *buf, uint32_t len, uint16_t index, CompletionHandler *handler, bool linked=false) noexcept
build a fixed-buffer write operation.
Definition io_operation.cpp:125
uint32_t index
index of this operation in the proactor pending ops (io_uring only).
Definition io_operation.hpp:301
static IoOperation makeRead(int fd, void *buf, uint32_t len, CompletionHandler *handler, bool linked=false) noexcept
build a regular read operation.
Definition io_operation.cpp:69
static IoOperation makeAccept(int fd, sockaddr *addr, socklen_t *addrlen, int flags, CompletionHandler *handler) noexcept
build an accept operation.
Definition io_operation.cpp:36
Data data
operation code specific payload.
Definition io_operation.hpp:310
State
operation lifecycle state.
Definition io_operation.hpp:46
static IoOperation makeRecvmsg(int fd, msghdr *msg, int flags, CompletionHandler *handler, bool linked=false) noexcept
build a receive-message operation.
Definition io_operation.cpp:144
CompletionHandler * handler
handler to dispatch to on completion.
Definition io_operation.hpp:307
static IoOperation makeRecv(int fd, void *buf, uint32_t len, int flags, CompletionHandler *handler, bool linked=false) noexcept
build a receive operation.
Definition io_operation.cpp:177
uint8_t code
operation code.
Definition io_operation.hpp:295
Opcode
operation code.
Definition io_operation.hpp:56
int fd() const noexcept
return the file descriptor associated with this operation.
Definition io_operation.cpp:213
Definition io_operation.hpp:280
RwData rw
Definition io_operation.hpp:283
MsgData msg
Definition io_operation.hpp:284
AcceptData accept
Definition io_operation.hpp:281
StreamData stream
Definition io_operation.hpp:285
ConnectData connect
Definition io_operation.hpp:282