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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
-- Prosody IM
-- Copyright (C) 2014,2016 Daurnimator
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--luacheck: ignore
--[[
This file is a template for writing a net.server compatible backend.
]]
--[[
Read patterns (also called modes) can be one of:
- "*a": Read as much as possible
- "*l": Read until end of line
]]
--- Handle API
local handle_mt = {};
local handle_methods = {};
handle_mt.__index = handle_methods;
function handle_methods:set_mode(new_pattern)
end
function handle_methods:setlistener(listeners)
end
function handle_methods:setoption(option, value)
end
function handle_methods:ip()
end
function handle_methods:starttls(sslctx)
end
function handle_methods:write(data)
end
function handle_methods:close()
end
function handle_methods:pause()
end
function handle_methods:resume()
end
--[[
Returns
- socket: the socket object underlying this handle
]]
function handle_methods:socket()
end
--[[
Returns
- boolean: if an ssl context has been set on this handle
]]
function handle_methods:ssl()
end
--- Listeners API
local listeners = {}
--[[ connect
Called when a client socket has established a connection with it's peer
]]
function listeners.onconnect(handle)
end
--[[ incoming
Called when data is received
If reading data failed this will be called with `nil, "error message"`
]]
function listeners.onincoming(handle, buff, err)
end
--[[ status
Known statuses:
- "ssl-handshake-complete"
]]
function listeners.onstatus(handle, status)
end
--[[ disconnect
Called when the peer has closed the connection
]]
function listeners.ondisconnect(handle)
end
--[[ drain
Called when the handle's write buffer is empty
]]
function listeners.ondrain(handle)
end
--[[ readtimeout
Called when a socket inactivity timeout occurs
]]
function listeners.onreadtimeout(handle)
end
--[[ detach: Called when other listeners are going to be removed
Allows for clean-up
]]
function listeners.ondetach(handle)
end
--- Top level functions
--[[ Returns the syscall level event mechanism in use.
Returns:
- backend: e.g. "select", "epoll"
]]
local function get_backend()
end
--[[ Starts the event loop.
Returns:
- "quitting"
]]
local function loop()
end
--[[ Stop a running loop()
]]
local function setquitting(quit)
end
--[[ Links to two handles together, so anything written to one is piped to the other
Arguments:
- sender, receiver: handles to link
- buffersize: maximum #bytes until sender will be locked
]]
local function link(sender, receiver, buffersize)
end
--[[ Binds and listens on the given address and port
If `sslctx` is given, the connecting clients will have to negotiate an SSL session
Arguments:
- address: address to bind to, may be "*" to bind all addresses. will be resolved if it is a string.
- port: port to bind (as number)
- listeners: a table of listeners
- pattern: the read pattern
- sslctx: is a valid luasec constructor
Returns:
- handle
- nil, "an error message": on failure (e.g. out of file descriptors)
]]
local function addserver(address, port, listeners, pattern, sslctx)
end
--[[ Wraps a lua-socket socket client socket in a handle.
The socket must be already connected to the remote end.
If `sslctx` is given, a SSL session will be negotiated before listeners are called.
Arguments:
- socket: the lua-socket object to wrap
- ip: returned by `handle:ip()`
- port:
- listeners: a table of listeners
- pattern: the read pattern
- sslctx: is a valid luasec constructor
- typ: the socket type, one of:
- "tcp"
- "tcp6"
- "udp"
Returns:
- handle, socket
- nil, "an error message": on failure (e.g. )
]]
local function wrapclient(socket, ip, serverport, listeners, pattern, sslctx)
end
--[[ Connects to the given address and port
If `sslctx` is given, a SSL session will be negotiated before listeners are called.
Arguments:
- address: address to connect to. will be resolved if it is a string.
- port: port to connect to (as number)
- listeners: a table of listeners
- pattern: the read pattern
- sslctx: is a valid luasec constructor
- typ: the socket type, one of:
- "tcp"
- "tcp6"
- "udp"
Returns:
- handle
- nil, "an error message": on failure (e.g. out of file descriptors)
]]
local function addclient(address, port, listeners, pattern, sslctx, typ)
end
--[[ Close all handles
]]
local function closeall()
end
--[[ The callback should be called after `delay` seconds.
The callback should be called with the time at the point of firing.
If the callback returns a number, it should be called again after that many seconds.
Arguments:
- delay: number of seconds to wait
- callback: function to call.
]]
local function add_task(delay, callback)
end
--[[ Adds a handler for when a signal is fired.
Optional to implement
callback does not take any arguments
Arguments:
- signal_id: the signal id (as number) to listen for
- handler: callback
]]
local function hook_signal(signal_id, handler)
end
--[[ Adds a low-level FD watcher
Arguments:
- fd_number: A non-negative integer representing a file descriptor or
object with a :getfd() method returning one
- on_readable: Optional callback for when the FD is readable
- on_writable: Optional callback for when the FD is writable
Returns:
- net.server handle
]]
local function watchfd(fd_number, on_readable, on_writable)
end
return {
get_backend = get_backend;
loop = loop;
setquitting = setquitting;
link = link;
addserver = addserver;
wrapclient = wrapclient;
addclient = addclient;
closeall = closeall;
hook_signal = hook_signal;
watchfd = watchfd;
}
|