1
Transport
Eugene Kabanov edited this page 2018-05-30 09:25:39 +03:00
Transports are high-level interfaces for interaction with the OS IO system. The main task that the Transport concept is designed to solve is to reduce the number of syscalls and of memory allocations for performing a single IO operation.
Current version of asyncdispatch uses at least four (4) syscalls for every single IO operation.
For Linux/BSD/MacOS systems, current version of asyncdispatch performs such operations for every single IO operation:
- Register for a read/write event in the system queue
- Wait for an event in the system queue
- Perform an IO operation
- Unregister a read/write event from the system queue
For Windows system, the current version of asyncdispatch performs allocations of OVERLAPPED structure for every single IO operation.
For example
proc processSomething(socket: AsyncFD) {.async.} =
var request = socket.recv(10) # 4 syscalls (Posix) or 1 allocation (Windows)
var data = socket.recv(100) # 4 syscalls (Posix) or 1 allocation (Windows)
var answer = "ANSWER"
await socket.send(answer) # 4 syscalls (Posix) or 1 allocation (Windows)