-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_iocp.cr
94 lines (79 loc) · 2.1 KB
/
lib_iocp.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "c/winnt"
# Based on the WSAOVERLAPPED structure
# See https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsaoverlapped
@[Extern]
struct AsyncOperation
property internal : LibC::ULONG_PTR
property internalHigh : LibC::ULONG_PTR
property offset : LibC::DWORD
property offsetHigh : LibC::DWORD
property hEvent : LibC::HANDLE
property extraInfo : Int32
def initialize()
@internal = 0
@internalHigh = 0
@offset = 0
@offsetHigh = 0
@hEvent = LibC::HANDLE.null
@extraInfo = 0
end
end
@[Link("advapi32")]
lib LibC
type WINSOCK = Int32
alias LPWSAOVERLAPPED_COMPLETION_ROUTINE = Void*
struct WSABUF
len : ULong
buf : CHAR*
end
struct OVERLAPPED_ENTRY
lpCompletionKey : ULONG_PTR
lpOverlapped : AsyncOperation*
internal : ULONG_PTR
dwNumberOfBytesTransferred : DWORD
end
fun WriteFile(
hFile : HANDLE,
lpBuffer : Void*,
nNumberOfBytesToWrite : DWORD,
lpNumberOfBytesWritten : DWORD*,
lpOverlapped : AsyncOperation*
) : BOOL
fun WSARecv(
socket : WINSOCK,
lpBuffers : WSABUF*,
dwBufferCount : DWORD,
lpNumberOfBytesRecvd : DWORD*,
lpFlags : DWORD*,
lpOverlapped : AsyncOperation*,
lpCompletionRoutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE
) : Int
fun WSAGetLastError() : Int
fun CreateIoCompletionPort(
fileHandle : HANDLE,
existingCompletionPort : HANDLE,
completionKey : ULONG_PTR,
numberOfConcurrentThreads : DWORD
) : HANDLE
fun PostQueuedCompletionStatus(
completionPort : HANDLE,
dwNumberofBytesTransferred : DWORD,
dwCompletionKey : ULONG_PTR,
lpOverlapped : AsyncOperation*
)
fun GetQueuedCompletionStatus(
completionPort : HANDLE,
lpNumberOfBytesTransferred : DWORD*,
lpCompletionKey : ULONG_PTR*,
lpOverlapped : AsyncOperation*,
dwMilliseconds : DWORD,
) : BOOL
fun GetQueuedCompletionStatusEx(
completionPort : HANDLE,
lpCompletionPortEntries : OVERLAPPED_ENTRY*,
ulCount : ULong,
ulNumEntriesRemoved : ULong*,
dwMilliseconds : DWORD,
fAlertable : BOOL
) : BOOL
end