Software /
code /
prosody
Annotate
net/server_select.lua @ 3010:52146b82f295
Merge 0.7->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 05 May 2010 17:22:43 +0100 |
parent | 3007:9d122a6ae674 |
parent | 3008:23915803adbf |
child | 3021:bf3c4195c5f8 |
rev | line source |
---|---|
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
1 -- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
2 -- server.lua by blastbeat of the luadch project |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
3 -- Re-used here under the MIT/X Consortium License |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
4 -- |
2925 | 5 -- Modifications (C) 2008-2010 Matthew Wild, Waqas Hussain |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
6 -- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
7 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
8 -- // wrapping luadch stuff // -- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
9 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
10 local use = function( what ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
11 return _G[ what ] |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
12 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
13 local clean = function( tbl ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
14 for i, k in pairs( tbl ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
15 tbl[ i ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
16 end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
17 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
18 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
19 local log, table_concat = require ("util.logger").init("socket"), table.concat; |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
20 local out_put = function (...) return log("debug", table_concat{...}); end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
21 local out_error = function (...) return log("warn", table_concat{...}); end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
22 local mem_free = collectgarbage |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
23 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
24 ----------------------------------// DECLARATION //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
25 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
26 --// constants //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
27 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
28 local STAT_UNIT = 1 -- byte |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
29 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
30 --// lua functions //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
31 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
32 local type = use "type" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
33 local pairs = use "pairs" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
34 local ipairs = use "ipairs" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
35 local tostring = use "tostring" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
36 local collectgarbage = use "collectgarbage" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
37 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
38 --// lua libs //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
39 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
40 local os = use "os" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
41 local table = use "table" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
42 local string = use "string" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
43 local coroutine = use "coroutine" |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
44 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
45 --// lua lib methods //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
46 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
47 local os_time = os.time |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
48 local os_difftime = os.difftime |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
49 local table_concat = table.concat |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
50 local table_remove = table.remove |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
51 local string_len = string.len |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
52 local string_sub = string.sub |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
53 local coroutine_wrap = coroutine.wrap |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
54 local coroutine_yield = coroutine.yield |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
55 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
56 --// extern libs //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
57 |
2597
40a174e8cdf6
net.server_select: Fix traceback with no LuaSec available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2582
diff
changeset
|
58 local luasec = use "ssl" |
40a174e8cdf6
net.server_select: Fix traceback with no LuaSec available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2582
diff
changeset
|
59 local luasocket = use "socket" or require "socket" |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
60 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
61 --// extern lib methods //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
62 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
63 local ssl_wrap = ( luasec and luasec.wrap ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
64 local socket_bind = luasocket.bind |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
65 local socket_sleep = luasocket.sleep |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
66 local socket_select = luasocket.select |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
67 local ssl_newcontext = ( luasec and luasec.newcontext ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
68 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
69 --// functions //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
70 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
71 local id |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
72 local loop |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
73 local stats |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
74 local idfalse |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
75 local addtimer |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
76 local closeall |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
77 local addserver |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
78 local getserver |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
79 local wrapserver |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
80 local getsettings |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
81 local closesocket |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
82 local removesocket |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
83 local removeserver |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
84 local changetimeout |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
85 local wrapconnection |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
86 local changesettings |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
87 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
88 --// tables //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
89 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
90 local _server |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
91 local _readlist |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
92 local _timerlist |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
93 local _sendlist |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
94 local _socketlist |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
95 local _closelist |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
96 local _readtimes |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
97 local _writetimes |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
98 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
99 --// simple data types //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
100 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
101 local _ |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
102 local _readlistlen |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
103 local _sendlistlen |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
104 local _timerlistlen |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
105 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
106 local _sendtraffic |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
107 local _readtraffic |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
108 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
109 local _selecttimeout |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
110 local _sleeptime |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
111 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
112 local _starttime |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
113 local _currenttime |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
114 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
115 local _maxsendlen |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
116 local _maxreadlen |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
117 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
118 local _checkinterval |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
119 local _sendtimeout |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
120 local _readtimeout |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
121 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
122 local _cleanqueue |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
123 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
124 local _timer |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
125 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
126 local _maxclientsperserver |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
127 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
128 ----------------------------------// DEFINITION //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
129 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
130 _server = { } -- key = port, value = table; list of listening servers |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
131 _readlist = { } -- array with sockets to read from |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
132 _sendlist = { } -- arrary with sockets to write to |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
133 _timerlist = { } -- array of timer functions |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
134 _socketlist = { } -- key = socket, value = wrapped socket (handlers) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
135 _readtimes = { } -- key = handler, value = timestamp of last data reading |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
136 _writetimes = { } -- key = handler, value = timestamp of last data writing/sending |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
137 _closelist = { } -- handlers to close |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
138 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
139 _readlistlen = 0 -- length of readlist |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
140 _sendlistlen = 0 -- length of sendlist |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
141 _timerlistlen = 0 -- lenght of timerlist |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
142 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
143 _sendtraffic = 0 -- some stats |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
144 _readtraffic = 0 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
145 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
146 _selecttimeout = 1 -- timeout of socket.select |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
147 _sleeptime = 0 -- time to wait at the end of every loop |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
148 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
149 _maxsendlen = 51000 * 1024 -- max len of send buffer |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
150 _maxreadlen = 25000 * 1024 -- max len of read buffer |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
151 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
152 _checkinterval = 1200000 -- interval in secs to check idle clients |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
153 _sendtimeout = 60000 -- allowed send idle time in secs |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
154 _readtimeout = 6 * 60 * 60 -- allowed read idle time in secs |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
155 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
156 _cleanqueue = false -- clean bufferqueue after using |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
157 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
158 _maxclientsperserver = 1000 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
159 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
160 _maxsslhandshake = 30 -- max handshake round-trips |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
161 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
162 ----------------------------------// PRIVATE //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
163 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
164 wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxconnections ) -- this function wraps a server |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
165 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
166 maxconnections = maxconnections or _maxclientsperserver |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
167 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
168 local connections = 0 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
169 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
170 local dispatch, disconnect = listeners.onincoming, listeners.ondisconnect |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
171 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
172 local accept = socket.accept |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
173 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
174 --// public methods of the object //-- |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
175 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
176 local handler = { } |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
177 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
178 handler.shutdown = function( ) end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
179 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
180 handler.ssl = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
181 return sslctx ~= nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
182 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
183 handler.sslctx = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
184 return sslctx |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
185 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
186 handler.remove = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
187 connections = connections - 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
188 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
189 handler.close = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
190 for _, handler in pairs( _socketlist ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
191 if handler.serverport == serverport then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
192 handler.disconnect( handler, "server closed" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
193 handler:close( true ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
194 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
195 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
196 socket:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
197 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
198 _readlistlen = removesocket( _readlist, socket, _readlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
199 _socketlist[ socket ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
200 handler = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
201 socket = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
202 --mem_free( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
203 out_put "server.lua: closed server handler and removed sockets from list" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
204 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
205 handler.ip = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
206 return ip |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
207 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
208 handler.serverport = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
209 return serverport |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
210 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
211 handler.socket = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
212 return socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
213 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
214 handler.readbuffer = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
215 if connections > maxconnections then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
216 out_put( "server.lua: refused new client connection: server full" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
217 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
218 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
219 local client, err = accept( socket ) -- try to accept |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
220 if client then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
221 local ip, clientport = client:getpeername( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
222 client:settimeout( 0 ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
223 local handler, client, err = wrapconnection( handler, listeners, client, ip, serverport, clientport, pattern, sslctx ) -- wrap new client socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
224 if err then -- error while wrapping ssl socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
225 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
226 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
227 connections = connections + 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
228 out_put( "server.lua: accepted new client connection from ", tostring(ip), ":", tostring(clientport), " to ", tostring(serverport)) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
229 return dispatch( handler ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
230 elseif err then -- maybe timeout or something else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
231 out_put( "server.lua: error with new client connection: ", tostring(err) ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
232 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
233 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
234 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
235 return handler |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
236 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
237 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
238 wrapconnection = function( server, listeners, socket, ip, serverport, clientport, pattern, sslctx ) -- this function wraps a client to a handler object |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
239 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
240 socket:settimeout( 0 ) |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
241 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
242 --// local import of socket methods //-- |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
243 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
244 local send |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
245 local receive |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
246 local shutdown |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
247 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
248 --// private closures of the object //-- |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
249 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
250 local ssl |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
251 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
252 local dispatch = listeners.onincoming |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
253 local status = listeners.onstatus |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
254 local disconnect = listeners.ondisconnect |
3002
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
255 local drain = listeners.ondrain |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
256 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
257 local bufferqueue = { } -- buffer array |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
258 local bufferqueuelen = 0 -- end of buffer array |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
259 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
260 local toclose |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
261 local fatalerror |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
262 local needtls |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
263 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
264 local bufferlen = 0 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
265 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
266 local noread = false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
267 local nosend = false |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
268 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
269 local sendtraffic, readtraffic = 0, 0 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
270 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
271 local maxsendlen = _maxsendlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
272 local maxreadlen = _maxreadlen |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
273 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
274 --// public methods of the object //-- |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
275 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
276 local handler = bufferqueue -- saves a table ^_^ |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
277 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
278 handler.dispatch = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
279 return dispatch |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
280 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
281 handler.disconnect = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
282 return disconnect |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
283 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
284 handler.setlistener = function( self, listeners ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
285 dispatch = listeners.onincoming |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
286 disconnect = listeners.ondisconnect |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
287 status = listeners.onstatus |
3002
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
288 drain = listeners.ondrain |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
289 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
290 handler.getstats = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
291 return readtraffic, sendtraffic |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
292 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
293 handler.ssl = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
294 return ssl |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
295 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
296 handler.sslctx = function ( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
297 return sslctx |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
298 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
299 handler.send = function( _, data, i, j ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
300 return send( socket, data, i, j ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
301 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
302 handler.receive = function( pattern, prefix ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
303 return receive( socket, pattern, prefix ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
304 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
305 handler.shutdown = function( pattern ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
306 return shutdown( socket, pattern ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
307 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
308 handler.setoption = function (self, option, value) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
309 if socket.setoption then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
310 return socket:setoption(option, value); |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
311 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
312 return false, "setoption not implemented"; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
313 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
314 handler.close = function( self, forced ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
315 if not handler then return true; end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
316 _readlistlen = removesocket( _readlist, socket, _readlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
317 _readtimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
318 if bufferqueuelen ~= 0 then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
319 if not ( forced or fatalerror ) then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
320 handler.sendbuffer( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
321 if bufferqueuelen ~= 0 then -- try again... |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
322 if handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
323 handler.write = nil -- ... but no further writing allowed |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
324 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
325 toclose = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
326 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
327 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
328 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
329 send( socket, table_concat( bufferqueue, "", 1, bufferqueuelen ), 1, bufferlen ) -- forced send |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
330 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
331 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
332 if socket then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
333 _ = shutdown and shutdown( socket ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
334 socket:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
335 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
336 _socketlist[ socket ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
337 socket = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
338 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
339 out_put "server.lua: socket already closed" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
340 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
341 if handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
342 _writetimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
343 _closelist[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
344 handler = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
345 end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
346 if server then |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
347 server.remove( ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
348 end |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
349 out_put "server.lua: closed client handler and removed socket from list" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
350 return true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
351 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
352 handler.ip = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
353 return ip |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
354 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
355 handler.serverport = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
356 return serverport |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
357 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
358 handler.clientport = function( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
359 return clientport |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
360 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
361 local write = function( self, data ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
362 bufferlen = bufferlen + string_len( data ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
363 if bufferlen > maxsendlen then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
364 _closelist[ handler ] = "send buffer exceeded" -- cannot close the client at the moment, have to wait to the end of the cycle |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
365 handler.write = idfalse -- dont write anymore |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
366 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
367 elseif socket and not _sendlist[ socket ] then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
368 _sendlistlen = addsocket(_sendlist, socket, _sendlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
369 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
370 bufferqueuelen = bufferqueuelen + 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
371 bufferqueue[ bufferqueuelen ] = data |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
372 if handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
373 _writetimes[ handler ] = _writetimes[ handler ] or _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
374 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
375 return true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
376 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
377 handler.write = write |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
378 handler.bufferqueue = function( self ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
379 return bufferqueue |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
380 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
381 handler.socket = function( self ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
382 return socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
383 end |
3001
fa00c6f563b4
net.server_select, net.server_event: Rename :pattern() method to :set_mode() for select backend, and add :set_mode() to event backend
Matthew Wild <mwild1@gmail.com>
parents:
3000
diff
changeset
|
384 handler.set_mode = function( self, new ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
385 pattern = new or pattern |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
386 return pattern |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
387 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
388 handler.set_send = function ( self, newsend ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
389 send = newsend or send |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
390 return send |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
391 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
392 handler.bufferlen = function( self, readlen, sendlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
393 maxsendlen = sendlen or maxsendlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
394 maxreadlen = readlen or maxreadlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
395 return bufferlen, maxreadlen, maxsendlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
396 end |
3000
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
397 --TODO: Deprecate |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
398 handler.lock_read = function (self, switch) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
399 if switch == true then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
400 local tmp = _readlistlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
401 _readlistlen = removesocket( _readlist, socket, _readlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
402 _readtimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
403 if _readlistlen ~= tmp then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
404 noread = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
405 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
406 elseif switch == false then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
407 if noread then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
408 noread = false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
409 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
410 _readtimes[ handler ] = _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
411 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
412 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
413 return noread |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
414 end |
3000
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
415 handler.pause = function (self) |
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
416 return self:lock_read(true); |
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
417 end |
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
418 handler.resume = function (self) |
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
419 return self:lock_read(false); |
43a4cb707fe4
net.server_select, net.server_event: Support for :pause() and :resume() on connections
Matthew Wild <mwild1@gmail.com>
parents:
2970
diff
changeset
|
420 end |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
421 handler.lock = function( self, switch ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
422 handler.lock_read (switch) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
423 if switch == true then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
424 handler.write = idfalse |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
425 local tmp = _sendlistlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
426 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
427 _writetimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
428 if _sendlistlen ~= tmp then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
429 nosend = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
430 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
431 elseif switch == false then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
432 handler.write = write |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
433 if nosend then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
434 nosend = false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
435 write( "" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
436 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
437 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
438 return noread, nosend |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
439 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
440 local _readbuffer = function( ) -- this function reads data |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
441 local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern" |
3002
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
442 if not err or (err == "wantread" or err == "timeout") then -- received something |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
443 local buffer = buffer or part or "" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
444 local len = string_len( buffer ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
445 if len > maxreadlen then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
446 disconnect( handler, "receive buffer exceeded" ) |
2728
3f8d9319d4a3
net.server_select: Fix calling method of some handler.close()s
Matthew Wild <mwild1@gmail.com>
parents:
2598
diff
changeset
|
447 handler:close( true ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
448 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
449 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
450 local count = len * STAT_UNIT |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
451 readtraffic = readtraffic + count |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
452 _readtraffic = _readtraffic + count |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
453 _readtimes[ handler ] = _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
454 --out_put( "server.lua: read data '", buffer:gsub("[^%w%p ]", "."), "', error: ", err ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
455 return dispatch( handler, buffer, err ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
456 else -- connections was closed or fatal error |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
457 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
458 fatalerror = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
459 disconnect( handler, err ) |
2728
3f8d9319d4a3
net.server_select: Fix calling method of some handler.close()s
Matthew Wild <mwild1@gmail.com>
parents:
2598
diff
changeset
|
460 _ = handler and handler:close( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
461 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
462 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
463 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
464 local _sendbuffer = function( ) -- this function sends data |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
465 local succ, err, byte, buffer, count; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
466 local count; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
467 if socket then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
468 buffer = table_concat( bufferqueue, "", 1, bufferqueuelen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
469 succ, err, byte = send( socket, buffer, 1, bufferlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
470 count = ( succ or byte or 0 ) * STAT_UNIT |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
471 sendtraffic = sendtraffic + count |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
472 _sendtraffic = _sendtraffic + count |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
473 _ = _cleanqueue and clean( bufferqueue ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
474 --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
475 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
476 succ, err, count = false, "closed", 0; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
477 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
478 if succ then -- sending succesful |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
479 bufferqueuelen = 0 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
480 bufferlen = 0 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
481 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
482 _ = needtls and handler:starttls(nil, true) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
483 _writetimes[ handler ] = nil |
3002
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
484 if drain then |
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
485 drain(handler) |
d1f864ed44c0
net.server_select, net.server_event: Support for ondrain listener callback for when send buffer is empty
Matthew Wild <mwild1@gmail.com>
parents:
3001
diff
changeset
|
486 end |
2732
dabdc56561f9
net.server_select: Fix typo
Matthew Wild <mwild1@gmail.com>
parents:
2728
diff
changeset
|
487 _ = toclose and handler:close( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
488 return true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
489 elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
490 buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
491 bufferqueue[ 1 ] = buffer -- insert new buffer in queue |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
492 bufferqueuelen = 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
493 bufferlen = bufferlen - byte |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
494 _writetimes[ handler ] = _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
495 return true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
496 else -- connection was closed during sending or fatal error |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
497 out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
498 fatalerror = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
499 disconnect( handler, err ) |
2728
3f8d9319d4a3
net.server_select: Fix calling method of some handler.close()s
Matthew Wild <mwild1@gmail.com>
parents:
2598
diff
changeset
|
500 _ = handler and handler:close( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
501 return false |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
502 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
503 end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
504 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
505 -- Set the sslctx |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
506 local handshake; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
507 function handler.set_sslctx(self, new_sslctx) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
508 ssl = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
509 sslctx = new_sslctx; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
510 local wrote |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
511 local read |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
512 handshake = coroutine_wrap( function( client ) -- create handshake coroutine |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
513 local err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
514 for i = 1, _maxsslhandshake do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
515 _sendlistlen = ( wrote and removesocket( _sendlist, client, _sendlistlen ) ) or _sendlistlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
516 _readlistlen = ( read and removesocket( _readlist, client, _readlistlen ) ) or _readlistlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
517 read, wrote = nil, nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
518 _, err = client:dohandshake( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
519 if not err then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
520 out_put( "server.lua: ssl handshake done" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
521 handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
522 handler.sendbuffer = _sendbuffer |
2996
b0515ed4d9d7
util.sasl: 2009 -> 2010 in copyright header.
Tobias Markmann <tm@ayena.de>
parents:
2598
diff
changeset
|
523 out_put ("server.lua: compression used: "..tostring(client:compression())) |
b0515ed4d9d7
util.sasl: 2009 -> 2010 in copyright header.
Tobias Markmann <tm@ayena.de>
parents:
2598
diff
changeset
|
524 out_put ("server.lua: finished: "..tostring(client:getfinished()):sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")) |
b0515ed4d9d7
util.sasl: 2009 -> 2010 in copyright header.
Tobias Markmann <tm@ayena.de>
parents:
2598
diff
changeset
|
525 out_put ("server.lua: peer finished: "..tostring(client:getpeerfinished()):sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
526 _ = status and status( handler, "ssl-handshake-complete" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
527 _readlistlen = addsocket(_readlist, client, _readlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
528 return true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
529 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
530 out_put( "server.lua: error during ssl handshake: ", tostring(err) ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
531 if err == "wantwrite" and not wrote then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
532 _sendlistlen = addsocket(_sendlist, client, _sendlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
533 wrote = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
534 elseif err == "wantread" and not read then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
535 _readlistlen = addsocket(_readlist, client, _readlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
536 read = true |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
537 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
538 break; |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
539 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
540 --coroutine_yield( handler, nil, err ) -- handshake not finished |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
541 coroutine_yield( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
542 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
543 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
544 disconnect( handler, "ssl handshake failed" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
545 _ = handler and handler:close( true ) -- forced disconnect |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
546 return false -- handshake failed |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
547 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
548 ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
549 end |
2582
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
550 if luasec then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
551 if sslctx then -- ssl? |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
552 handler:set_sslctx(sslctx); |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
553 out_put("server.lua: ", "starting ssl handshake") |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
554 local err |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
555 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
556 if err then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
557 out_put( "server.lua: ssl error: ", tostring(err) ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
558 --mem_free( ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
559 return nil, nil, err -- fatal error |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
560 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
561 socket:settimeout( 0 ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
562 handler.readbuffer = handshake |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
563 handler.sendbuffer = handshake |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
564 handshake( socket ) -- do handshake |
2582
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
565 if not socket then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
566 return nil, nil, "ssl handshake failed"; |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
567 end |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
568 else |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
569 local sslctx; |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
570 handler.starttls = function( self, _sslctx, now ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
571 if _sslctx then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
572 sslctx = _sslctx; |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
573 handler:set_sslctx(sslctx); |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
574 end |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
575 if not now then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
576 out_put "server.lua: we need to do tls, but delaying until later" |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
577 needtls = true |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
578 return |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
579 end |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
580 out_put( "server.lua: attempting to start tls on " .. tostring( socket ) ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
581 local oldsocket, err = socket |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
582 socket, err = ssl_wrap( socket, sslctx ) -- wrap socket |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
583 --out_put( "server.lua: sslwrapped socket is " .. tostring( socket ) ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
584 if err then |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
585 out_put( "server.lua: error while starting tls on client: ", tostring(err) ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
586 return nil, err -- fatal error |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
587 end |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
588 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
589 socket:settimeout( 0 ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
590 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
591 -- add the new socket to our system |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
592 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
593 send = socket.send |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
594 receive = socket.receive |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
595 shutdown = id |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
596 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
597 _socketlist[ socket ] = handler |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
598 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
599 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
600 -- remove traces of the old socket |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
601 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
602 _readlistlen = removesocket( _readlist, oldsocket, _readlistlen ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
603 _sendlistlen = removesocket( _sendlist, oldsocket, _sendlistlen ) |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
604 _socketlist[ oldsocket ] = nil |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
605 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
606 handler.starttls = nil |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
607 needtls = nil |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
608 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
609 -- Secure now |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
610 ssl = true |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
611 |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
612 handler.readbuffer = handshake |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
613 handler.sendbuffer = handshake |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
614 handshake( socket ) -- do handshake |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
615 end |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
616 handler.readbuffer = _readbuffer |
d6afb6d919df
net.server_select: Only allow starttls if luasec is available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2581
diff
changeset
|
617 handler.sendbuffer = _sendbuffer |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
618 end |
2597
40a174e8cdf6
net.server_select: Fix traceback with no LuaSec available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2582
diff
changeset
|
619 else |
40a174e8cdf6
net.server_select: Fix traceback with no LuaSec available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2582
diff
changeset
|
620 handler.readbuffer = _readbuffer |
40a174e8cdf6
net.server_select: Fix traceback with no LuaSec available (thanks Nolan)
Matthew Wild <mwild1@gmail.com>
parents:
2582
diff
changeset
|
621 handler.sendbuffer = _sendbuffer |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
622 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
623 send = socket.send |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
624 receive = socket.receive |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
625 shutdown = ( ssl and id ) or socket.shutdown |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
626 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
627 _socketlist[ socket ] = handler |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
628 _readlistlen = addsocket(_readlist, socket, _readlistlen) |
2970
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
629 if listeners.onconnect then |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
630 _sendlistlen = addsocket(_sendlist, socket, _sendlistlen) |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
631 handler.sendbuffer = function () |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
632 listeners.onconnect(handler); |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
633 handler.sendbuffer = _sendbuffer; |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
634 if bufferqueuelen > 0 then |
3008
23915803adbf
net.server_select: Fix typo affecting connections with an onconnect listener that have data pending in the sendbuffer
Matthew Wild <mwild1@gmail.com>
parents:
3003
diff
changeset
|
635 return _sendbuffer(); |
2970
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
636 end |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
637 end |
9b8e139eff5f
net.server_select: Support for listener.onconnect
Matthew Wild <mwild1@gmail.com>
parents:
2968
diff
changeset
|
638 end |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
639 return handler, socket |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
640 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
641 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
642 id = function( ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
643 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
644 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
645 idfalse = function( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
646 return false |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
647 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
648 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
649 addsocket = function( list, socket, len ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
650 if not list[ socket ] then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
651 len = len + 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
652 list[ len ] = socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
653 list[ socket ] = len |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
654 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
655 return len; |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
656 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
657 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
658 removesocket = function( list, socket, len ) -- this function removes sockets from a list ( copied from copas ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
659 local pos = list[ socket ] |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
660 if pos then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
661 list[ socket ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
662 local last = list[ len ] |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
663 list[ len ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
664 if last ~= socket then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
665 list[ last ] = pos |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
666 list[ pos ] = last |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
667 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
668 return len - 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
669 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
670 return len |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
671 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
672 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
673 closesocket = function( socket ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
674 _sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
675 _readlistlen = removesocket( _readlist, socket, _readlistlen ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
676 _socketlist[ socket ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
677 socket:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
678 --mem_free( ) |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
679 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
680 |
3003
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
681 local function link(sender, receiver, buffersize) |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
682 sender:set_mode(buffersize); |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
683 local sender_locked; |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
684 local _sendbuffer = receiver.sendbuffer; |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
685 function receiver.sendbuffer() |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
686 _sendbuffer(); |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
687 if sender_locked and receiver.bufferlen() < buffersize then |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
688 sender:lock_read(false); -- Unlock now |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
689 sender_locked = nil; |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
690 end |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
691 end |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
692 |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
693 local _readbuffer = sender.readbuffer; |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
694 function sender.readbuffer() |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
695 _readbuffer(); |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
696 if not sender_locked and receiver.bufferlen() >= buffersize then |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
697 sender_locked = true; |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
698 sender:lock_read(true); |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
699 end |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
700 end |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
701 end |
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
702 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
703 ----------------------------------// PUBLIC //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
704 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
705 addserver = function( addr, port, listeners, pattern, sslctx ) -- this function provides a way for other scripts to reg a server |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
706 local err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
707 if type( listeners ) ~= "table" then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
708 err = "invalid listener table" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
709 end |
2968 | 710 if type( port ) ~= "number" or not ( port >= 0 and port <= 65535 ) then |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
711 err = "invalid port" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
712 elseif _server[ port ] then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
713 err = "listeners on port '" .. port .. "' already exist" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
714 elseif sslctx and not luasec then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
715 err = "luasec not found" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
716 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
717 if err then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
718 out_error( "server.lua, port ", port, ": ", err ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
719 return nil, err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
720 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
721 addr = addr or "*" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
722 local server, err = socket_bind( addr, port ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
723 if err then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
724 out_error( "server.lua, port ", port, ": ", err ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
725 return nil, err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
726 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
727 local handler, err = wrapserver( listeners, server, addr, port, pattern, sslctx, _maxclientsperserver ) -- wrap new server socket |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
728 if not handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
729 server:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
730 return nil, err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
731 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
732 server:settimeout( 0 ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
733 _readlistlen = addsocket(_readlist, server, _readlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
734 _server[ port ] = handler |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
735 _socketlist[ server ] = handler |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
736 out_put( "server.lua: new "..(sslctx and "ssl " or "").."server listener on '", addr, ":", port, "'" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
737 return handler |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
738 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
739 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
740 getserver = function ( port ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
741 return _server[ port ]; |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
742 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
743 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
744 removeserver = function( port ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
745 local handler = _server[ port ] |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
746 if not handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
747 return nil, "no server found on port '" .. tostring( port ) .. "'" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
748 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
749 handler:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
750 _server[ port ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
751 return true |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
752 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
753 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
754 closeall = function( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
755 for _, handler in pairs( _socketlist ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
756 handler:close( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
757 _socketlist[ _ ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
758 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
759 _readlistlen = 0 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
760 _sendlistlen = 0 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
761 _timerlistlen = 0 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
762 _server = { } |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
763 _readlist = { } |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
764 _sendlist = { } |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
765 _timerlist = { } |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
766 _socketlist = { } |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
767 --mem_free( ) |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
768 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
769 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
770 getsettings = function( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
771 return _selecttimeout, _sleeptime, _maxsendlen, _maxreadlen, _checkinterval, _sendtimeout, _readtimeout, _cleanqueue, _maxclientsperserver, _maxsslhandshake |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
772 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
773 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
774 changesettings = function( new ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
775 if type( new ) ~= "table" then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
776 return nil, "invalid settings table" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
777 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
778 _selecttimeout = tonumber( new.timeout ) or _selecttimeout |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
779 _sleeptime = tonumber( new.sleeptime ) or _sleeptime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
780 _maxsendlen = tonumber( new.maxsendlen ) or _maxsendlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
781 _maxreadlen = tonumber( new.maxreadlen ) or _maxreadlen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
782 _checkinterval = tonumber( new.checkinterval ) or _checkinterval |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
783 _sendtimeout = tonumber( new.sendtimeout ) or _sendtimeout |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
784 _readtimeout = tonumber( new.readtimeout ) or _readtimeout |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
785 _cleanqueue = new.cleanqueue |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
786 _maxclientsperserver = new._maxclientsperserver or _maxclientsperserver |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
787 _maxsslhandshake = new._maxsslhandshake or _maxsslhandshake |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
788 return true |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
789 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
790 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
791 addtimer = function( listener ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
792 if type( listener ) ~= "function" then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
793 return nil, "invalid listener function" |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
794 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
795 _timerlistlen = _timerlistlen + 1 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
796 _timerlist[ _timerlistlen ] = listener |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
797 return true |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
798 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
799 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
800 stats = function( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
801 return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
802 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
803 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
804 local dontstop = true; -- thinking about tomorrow, ... |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
805 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
806 setquitting = function (quit) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
807 dontstop = not quit; |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
808 return; |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
809 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
810 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
811 loop = function( ) -- this is the main loop of the program |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
812 while dontstop do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
813 local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
814 for i, socket in ipairs( write ) do -- send data waiting in writequeues |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
815 local handler = _socketlist[ socket ] |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
816 if handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
817 handler.sendbuffer( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
818 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
819 closesocket( socket ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
820 out_put "server.lua: found no handler and closed socket (writelist)" -- this should not happen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
821 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
822 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
823 for i, socket in ipairs( read ) do -- receive data |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
824 local handler = _socketlist[ socket ] |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
825 if handler then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
826 handler.readbuffer( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
827 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
828 closesocket( socket ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
829 out_put "server.lua: found no handler and closed socket (readlist)" -- this can happen |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
830 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
831 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
832 for handler, err in pairs( _closelist ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
833 handler.disconnect( )( handler, err ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
834 handler:close( true ) -- forced disconnect |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
835 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
836 clean( _closelist ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
837 _currenttime = os_time( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
838 if os_difftime( _currenttime - _timer ) >= 1 then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
839 for i = 1, _timerlistlen do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
840 _timerlist[ i ]( _currenttime ) -- fire timers |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
841 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
842 _timer = _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
843 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
844 socket_sleep( _sleeptime ) -- wait some time |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
845 --collectgarbage( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
846 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
847 return "quitting" |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
848 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
849 |
2339
b04014f42fce
net.server_select: Add get_backend() method
Matthew Wild <mwild1@gmail.com>
parents:
2318
diff
changeset
|
850 local function get_backend() |
b04014f42fce
net.server_select: Add get_backend() method
Matthew Wild <mwild1@gmail.com>
parents:
2318
diff
changeset
|
851 return "select"; |
b04014f42fce
net.server_select: Add get_backend() method
Matthew Wild <mwild1@gmail.com>
parents:
2318
diff
changeset
|
852 end |
b04014f42fce
net.server_select: Add get_backend() method
Matthew Wild <mwild1@gmail.com>
parents:
2318
diff
changeset
|
853 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
854 --// EXPERIMENTAL //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
855 |
2541
2febd008214e
net.server_select: Remove startssl parameter to the client/server creation functions - passing a sslctx now indicates you want to use SSL from the start
Matthew Wild <mwild1@gmail.com>
parents:
2478
diff
changeset
|
856 local wrapclient = function( socket, ip, serverport, listeners, pattern, sslctx ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
857 local handler = wrapconnection( nil, listeners, socket, ip, serverport, "clientport", pattern, sslctx ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
858 _socketlist[ socket ] = handler |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
859 _sendlistlen = addsocket(_sendlist, socket, _sendlistlen) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
860 return handler, socket |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
861 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
862 |
2541
2febd008214e
net.server_select: Remove startssl parameter to the client/server creation functions - passing a sslctx now indicates you want to use SSL from the start
Matthew Wild <mwild1@gmail.com>
parents:
2478
diff
changeset
|
863 local addclient = function( address, port, listeners, pattern, sslctx ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
864 local client, err = luasocket.tcp( ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
865 if err then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
866 return nil, err |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
867 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
868 client:settimeout( 0 ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
869 _, err = client:connect( address, port ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
870 if err then -- try again |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
871 local handler = wrapclient( client, address, port, listeners ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
872 else |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
873 wrapconnection( nil, listeners, client, address, port, "clientport", pattern, sslctx ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
874 end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
875 end |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
876 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
877 --// EXPERIMENTAL //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
878 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
879 ----------------------------------// BEGIN //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
880 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
881 use "setmetatable" ( _socketlist, { __mode = "k" } ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
882 use "setmetatable" ( _readtimes, { __mode = "k" } ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
883 use "setmetatable" ( _writetimes, { __mode = "k" } ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
884 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
885 _timer = os_time( ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
886 _starttime = os_time( ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
887 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
888 addtimer( function( ) |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
889 local difftime = os_difftime( _currenttime - _starttime ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
890 if difftime > _checkinterval then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
891 _starttime = _currenttime |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
892 for handler, timestamp in pairs( _writetimes ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
893 if os_difftime( _currenttime - timestamp ) > _sendtimeout then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
894 --_writetimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
895 handler.disconnect( )( handler, "send timeout" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
896 handler:close( true ) -- forced disconnect |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
897 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
898 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
899 for handler, timestamp in pairs( _readtimes ) do |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
900 if os_difftime( _currenttime - timestamp ) > _readtimeout then |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
901 --_readtimes[ handler ] = nil |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
902 handler.disconnect( )( handler, "read timeout" ) |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
903 handler:close( ) -- forced disconnect? |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
904 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
905 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
906 end |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
907 end |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
908 ) |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
909 |
2424
7d3b071e3b5b
net.server_select: Fix oops in last commit
Matthew Wild <mwild1@gmail.com>
parents:
2423
diff
changeset
|
910 local function setlogger(new_logger) |
2423
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
911 local old_logger = log; |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
912 if new_logger then |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
913 log = new_logger; |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
914 end |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
915 return old_logger; |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
916 end |
0597c553acf2
net.server_select: Allow setting the logger using server.setlogger
Matthew Wild <mwild1@gmail.com>
parents:
2339
diff
changeset
|
917 |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
918 ----------------------------------// PUBLIC INTERFACE //-- |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
919 |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
920 return { |
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
921 |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
922 addclient = addclient, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
923 wrapclient = wrapclient, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
924 |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
925 loop = loop, |
3003
48871a549b4c
net.server_select, net.server_event: Add server.link() to link 2 connections with an intermediate buffer of the specified size
Matthew Wild <mwild1@gmail.com>
parents:
3002
diff
changeset
|
926 link = link, |
2581
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
927 stats = stats, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
928 closeall = closeall, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
929 addtimer = addtimer, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
930 addserver = addserver, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
931 getserver = getserver, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
932 setlogger = setlogger, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
933 getsettings = getsettings, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
934 setquitting = setquitting, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
935 removeserver = removeserver, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
936 get_backend = get_backend, |
1b9f424e695e
net.server_select: *Major* whitespace refactoring to meet Prosody's coding style guidelines, we now have tabs
Matthew Wild <mwild1@gmail.com>
parents:
2559
diff
changeset
|
937 changesettings = changesettings, |
2318
a831de056de3
net.server_select, net.server_event: Convert to unix line endings from Windows
Matthew Wild <mwild1@gmail.com>
parents:
2312
diff
changeset
|
938 } |