Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix travis build #184

Merged
merged 11 commits into from Jun 15, 2016
Merged
14 changes: 12 additions & 2 deletions .travis.yml
Expand Up @@ -9,13 +9,23 @@ sudo: false
git:
depth: 1

env:
global:
- LLVM_VERSION=3.7.0
- LLVM_ARCHIVE_PATH=$HOME/clang+llvm.tar.xz

before_install:
- wget http://llvm.org/releases/$LLVM_VERSION/clang+llvm-$LLVM_VERSION-x86_64-linux-gnu-ubuntu-14.04.tar.xz -O $LLVM_ARCHIVE_PATH
- mkdir $HOME/clang+llvm
- tar xf $LLVM_ARCHIVE_PATH -C $HOME/clang+llvm --strip-components 1
- export PATH=$HOME/clang+llvm/bin:$PATH
- ln -s $HOME/clang+llvm/bin/clang++ $HOME/clang+llvm/bin/clang++-3.7

addons:
apt:
sources:
- llvm-toolchain-precise-3.7
- ubuntu-toolchain-r-test
packages:
- clang-3.7
- g++-5
- gcc-5
- libhiredis-dev
Expand Down
7 changes: 5 additions & 2 deletions src/onion/websocket.c
Expand Up @@ -420,6 +420,7 @@ static onion_connection_status onion_websocket_read_packet_header(onion_websocke
return OCS_CLOSE_CONNECTION;
}
int r= (*lpreader) (ws->req, tmp, 2);
//ONION_DEBUG("reading input r = %i", r);
if (r!=2){ ONION_DEBUG("Error reading header"); return OCS_CLOSE_CONNECTION; }

ws->flags=0;
Expand Down Expand Up @@ -447,7 +448,8 @@ static onion_connection_status onion_websocket_read_packet_header(onion_websocke
ONION_DEBUG("Data left %d", ws->data_left);
if (ws->flags&WS_MASK){
r= (*lpreader) (ws->req, ws->mask, 4);
if (r!=4){ ONION_DEBUG("Error reading header"); return OCS_CLOSE_CONNECTION; }
//ONION_DEBUG("bytes read=%i", r);
if (r!=4){ ONION_DEBUG("Error reading header (4)"); return OCS_CLOSE_CONNECTION; }
ws->mask_pos=0;
}

Expand All @@ -465,7 +467,7 @@ static onion_connection_status onion_websocket_read_packet_header(onion_websocke
status[0] = utmp[0] ^ ws->mask[0];
status[1] = utmp[1] ^ ws->mask[1];
ONION_DEBUG("Connection closed by client, status=%u", (status[0]<<8) + status[1]);
onion_websocket_close(ws, status);
onion_websocket_close(ws, (const char *)&status);
return OCS_CLOSE_CONNECTION;
}
return OCS_NEED_MORE_DATA;
Expand Down Expand Up @@ -494,6 +496,7 @@ onion_connection_status onion_websocket_call(onion_websocket* ws)
else
sleep(1); // FIXME Worst possible solution. But solution anyway to the problem of not know when new data is available.
if (ws->callback){
//ONION_DEBUG("data left %i", ws->data_left);
if (ws->data_left==0){
onion_connection_status err=onion_websocket_read_packet_header(ws);
if (err<0){
Expand Down
Binary file added tests/01-internal/14-websockets
Binary file not shown.
7 changes: 3 additions & 4 deletions tests/01-internal/14-websockets.c
Expand Up @@ -201,7 +201,7 @@ void t03_websocket_server_receive_small_packet(){

onion_websocket_read(ws, (char *)&buffer2, 120);

buffer2[114] = '\0';
buffer2[113] = '\0';
FAIL_IF_NOT_EQUAL_STR(buffer2, "Some UTF-8-encoded chars which will be cut at the 117th char so I write some gap-filling text with no meaning unti");

onion_websocket_free(ws);
Expand All @@ -213,8 +213,7 @@ void t03_websocket_server_receive_small_packet(){
void t04_websocket_server_close_handshake(){
INIT_LOCAL();
int length = 0;
char *buffer = NULL;
unsigned char buffer2[8];
unsigned char *buffer = NULL, buffer2[8];
onion *o=websocket_server_new();
onion_request *req=websocket_start_handshake(o);
req->connection.listen_point->read = (lpreader_sig_t*) websocket_data_buffer_read;
Expand All @@ -224,7 +223,7 @@ void t04_websocket_server_close_handshake(){
onion_websocket *ws = onion_websocket_new(req, res);

length = websocket_forge_close_packet((char **)&buffer);
websocket_data_buffer_write(req, buffer, length);
websocket_data_buffer_write(req, (char *)buffer, length);
onion_connection_status ret = onion_websocket_call(ws);
FAIL_IF(ret!=-2);
websocket_data_buffer_read(req, (char *)&buffer2, 8);
Expand Down