Skip to content

Commit 6b571e2

Browse files
committed
Merge pull request lipp#79 from lipp/remove-struct-dep-2
replace struct pack/unpack with bitops
2 parents f8dbe73 + ef4b7de commit 6b571e2

File tree

12 files changed

+208
-70
lines changed

12 files changed

+208
-70
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
language: python
1+
language: node_js
22

33
env:
44
global:
@@ -27,7 +27,6 @@ before_install:
2727
- cd $TRAVIS_BUILD_DIR
2828

2929
install:
30-
- sudo pip install autobahntestsuite
3130
- sudo apt-get install libev-dev
3231
- git clone http://github.com/brimworks/lua-ev
3332
- cd lua-ev && sudo luarocks make rockspec/lua-ev-scm-1.rockspec && cd ..

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ubuntu:14.04
2+
# install autobahn tests suite (python)
3+
RUN apt-get update -y && apt-get install build-essential libssl-dev python -y
4+
# install lua
5+
ENV LUAROCKS_VERSION=2.0.13
6+
ENV LUAROCKS_BASE=luarocks-$LUAROCKS_VERSION
7+
ENV LUA luajit
8+
ENV LUA_DEV libluajit-5.1-dev
9+
ENV LUA_VER 5.1
10+
ENV LUA_SFX jit
11+
ENV LUA_INCDIR /usr/include/luajit-2.0
12+
13+
# - LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1
14+
# - LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2
15+
# - LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0
16+
RUN apt-get install ${LUA} ${LUA_DEV} wget libev-dev git-core unzip -y
17+
RUN lua${LUA_SFX} -v
18+
WORKDIR /
19+
RUN wget --quiet https://github.com/keplerproject/luarocks/archive/v$LUAROCKS_VERSION.tar.gz -O $LUAROCKS_BASE.tar.gz
20+
RUN wget --quiet https://nodejs.org/dist/latest/node-v4.0.0-linux-x64.tar.gz
21+
RUN tar xf node-v4.0.0-linux-x64.tar.gz
22+
ENV PATH /node-v4.0.0-linux-x64/bin:$PATH
23+
RUN node --version
24+
RUN npm install -g ws
25+
RUN tar zxpf $LUAROCKS_BASE.tar.gz
26+
RUN cd $LUAROCKS_BASE && ./configure --lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR" && make install && cd ..
27+
RUN luarocks --version
28+
RUN git clone http://github.com/brimworks/lua-ev && cd lua-ev && luarocks make LIBEV_LIBDIR=/usr/lib/x86_64-linux-gnu/ rockspec/lua-ev-scm-1.rockspec && cd ..
29+
RUN luarocks install LuaCov
30+
RUN luarocks install lua_cliargs 2.3-3
31+
RUN luarocks install busted 1.10.0-1
32+
ADD . /lua-websockets
33+
WORKDIR /lua-websockets
34+
RUN luarocks make rockspecs/lua-websockets-scm-1.rockspec
35+
RUN ./test.sh
36+

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ var echoWs = new WebSocket('ws://127.0.0.1:8002','echo');
115115
The client and server modules depend on:
116116

117117
- luasocket
118-
- struct
119118
- luabitop (if not using Lua 5.2 nor luajit)
120-
- luacrypto (optionally)
121119
- copas (optionally)
122120
- lua-ev (optionally)
123121

echows.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var WebSocketServer = require('ws').Server;
2+
var wss = new WebSocketServer({ port: parseInt(process.argv[2]) });
3+
4+
wss.on('connection', function connection(ws) {
5+
ws.on('message', function incoming(message, flags) {
6+
ws.send(message, flags);
7+
});
8+
});

lua-websockets.rockspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ description = {
1010
summary = "Websockets for Lua",
1111
homepage = "http://github.com/lipp/lua-websockets",
1212
license = "MIT/X11",
13-
detailed = "Provides sync and async clients and servers for copas."
13+
detailed = "Provides sync and async clients and servers for copas and lua-ev."
1414
}
1515

1616
dependencies = {
1717
"lua >= 5.1",
18-
"struct",
1918
"luasocket",
2019
"luabitop",
2120
"copas"

rockspecs/lua-websockets-scm-1.rockspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ description = {
1414

1515
dependencies = {
1616
"lua >= 5.1",
17-
"struct",
1817
"luasocket",
1918
"luabitop",
2019
"lua-ev",

spec/frame_spec.lua

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package.path = package.path..'../src'
22

33
local frame = require'websocket.frame'
4+
local tools = require'websocket.tools'
45

56
local bytes = string.char
67

@@ -18,7 +19,7 @@ describe(
1819
function()
1920
assert.is_same(type(frame),'table')
2021
end)
21-
22+
2223
it(
2324
'provides a decode and a encode function',
2425
function()
@@ -27,7 +28,7 @@ describe(
2728
assert.is.same(type(frame.encode_close),'function')
2829
assert.is.same(type(frame.decode_close),'function')
2930
end)
30-
31+
3132
it(
3233
'provides correct OPCODES',
3334
function()
@@ -38,8 +39,29 @@ describe(
3839
assert.is.same(frame.PING,9)
3940
assert.is.same(frame.PONG,10)
4041
end)
41-
42-
42+
43+
it('.encode_header_small is correct',
44+
function()
45+
local enc = frame.encode_header_small(123,33)
46+
local enc_ref = tools.write_int8(123)..tools.write_int8(33)
47+
assert.is_same(enc, enc_ref)
48+
end)
49+
50+
it('.encode_header_medium is correct',
51+
function()
52+
local enc = frame.encode_header_medium(123,33,555)
53+
local enc_ref = tools.write_int8(123)..tools.write_int8(33)..tools.write_int16(555)
54+
assert.is_same(enc, enc_ref)
55+
end)
56+
57+
it('.encode_header_big is correct',
58+
function()
59+
local enc = frame.encode_header_big(123,33,555,12987)
60+
local enc_ref = tools.write_int8(123)..tools.write_int8(33)..tools.write_int32(555)..tools.write_int32(12987)
61+
assert.is_same(enc, enc_ref)
62+
end)
63+
64+
4365
it(
4466
'RFC: decode a single-frame unmasked text message',
4567
function()
@@ -50,7 +72,7 @@ describe(
5072
assert.is_same(rest,'foo')
5173
assert.is_false(masked)
5274
end)
53-
75+
5476
it(
5577
'RFC: decode a single-frame unmasked text message bytewise and check min length',
5678
function()
@@ -70,7 +92,7 @@ describe(
7092
end
7193
end
7294
end)
73-
95+
7496
it(
7597
'RFC: decode a single-frame masked text message',
7698
function()
@@ -81,7 +103,7 @@ describe(
81103
assert.is_same(rest,'foo')
82104
assert.is_truthy(masked)
83105
end)
84-
106+
85107
it(
86108
'RFC: decode a fragmented test message',
87109
function()
@@ -91,15 +113,15 @@ describe(
91113
assert.is.same(decoded,'Hel')
92114
assert.is_same(rest,'')
93115
assert.is_falsy(masked)
94-
116+
95117
decoded,fin,opcode,rest,masked = frame.decode(lo)
96118
assert.is_true(fin)
97119
assert.is_same(opcode,0x0)
98120
assert.is.same(decoded,'lo')
99121
assert.is_same(rest,'')
100122
assert.is_falsy(masked)
101123
end)
102-
124+
103125
it(
104126
'refuse incomplete unmasked frame',
105127
function()
@@ -108,7 +130,7 @@ describe(
108130
assert.is_same(fin,#hello_unmasked-4)
109131
assert.is_falsy(opcode)
110132
end)
111-
133+
112134
it(
113135
'refuse incomplete masked frame',
114136
function()
@@ -117,7 +139,7 @@ describe(
117139
assert.is_same(fin,#hello_masked-4)
118140
assert.is_falsy(opcode)
119141
end)
120-
142+
121143
it(
122144
'encode single-frame unmasked text',
123145
function()
@@ -135,15 +157,15 @@ describe(
135157
assert.is_same(opcode,frame.TEXT)
136158
assert.is_falsy(masked)
137159
end)
138-
160+
139161
local random_text = function(len)
140162
local chars = {}
141163
for i=1,len do
142164
chars[i] = string.char(math.random(33,126))
143165
end
144166
return table.concat(chars)
145167
end
146-
168+
147169
it(
148170
'encode and decode single-frame of length 127 unmasked text',
149171
function()
@@ -159,7 +181,7 @@ describe(
159181
assert.is_same(rest,'')
160182
assert.is_falsy(masked)
161183
end)
162-
184+
163185
it(
164186
'encode and decode single-frame of length 0xffff-1 unmasked text',
165187
function()
@@ -175,7 +197,7 @@ describe(
175197
assert.is_same(rest,'')
176198
assert.is_falsy(masked)
177199
end)
178-
200+
179201
it(
180202
'encode and decode single-frame of length 0xffff+1 unmasked text',
181203
function()
@@ -189,7 +211,7 @@ describe(
189211
assert.is_true(fin)
190212
assert.is_same(opcode,frame.TEXT)
191213
end)
192-
214+
193215
it(
194216
'encode single-frame masked text',
195217
function()
@@ -201,7 +223,7 @@ describe(
201223
assert.is_same(rest,'')
202224
assert.is_truthy(masked)
203225
end)
204-
226+
205227
it(
206228
'encode fragmented unmasked text',
207229
function()
@@ -210,14 +232,14 @@ describe(
210232
assert.is_falsy(fin)
211233
assert.is_same(opcode,0x1)
212234
assert.is.same(decoded,'Hel')
213-
235+
214236
local lo = frame.encode('lo',frame.CONTINUATION,false)
215237
decoded,fin,opcode = frame.decode(lo)
216238
assert.is_true(fin)
217239
assert.is_same(opcode,0x0)
218240
assert.is.same(decoded,'lo')
219241
end)
220-
242+
221243
it(
222244
'encodes and decodes close packet correctly',
223245
function()
@@ -229,5 +251,5 @@ describe(
229251
assert.is_same(dcode,code)
230252
assert.is_same(dreason,reason)
231253
end)
232-
254+
233255
end)

spec/server_copas_spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ describe(
256256
it(
257257
'broadcast works',
258258
function(done)
259+
settimeout(6)
259260
local n = 20
260261
local n_clients = 0
261262
local closed = 0

spec/server_ev_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe(
232232
it(
233233
'echo works with 0xffff-1 byte messages',
234234
function(done)
235-
settimeout(3.0)
235+
settimeout(10.0)
236236
local message = random_text(0xffff-1)
237237
local wsc = client.ev()
238238
on_new_echo_client = async(
@@ -264,7 +264,7 @@ describe(
264264
it(
265265
'echo works with 0xffff+1 byte messages',
266266
function(done)
267-
settimeout(3.0)
267+
settimeout(6.0)
268268
local message = random_text(0xffff+1)
269269
local wsc = client.ev()
270270
on_new_echo_client = async(

0 commit comments

Comments
 (0)