BelaPlatform / Bela

Bela: core code, IDE and lots of fun!
Other
491 stars 139 forks source link

core: WSServer stops working with `-O0` #608

Open giuliomoro opened 4 years ago

giuliomoro commented 4 years ago

this in turn breaks Scope and Gui. If running a Gui example after WSServer.cpp was built with -O0, you will see in the console of the sketch:

BelaWebSocket.js:30 WebSocket connection to 'ws://192.168.7.2:5555/gui_control' failed: Error during WebSocket handshake: Unexpected response code: 404
giuliomoro commented 4 years ago

this will show the SeaSocks log, maybe it helps?

--- a/core/WSServer.cpp
+++ b/core/WSServer.cpp
@@ -1,6 +1,6 @@
 /***** WSServer.cpp *****/
 #include <WSServer.h>
-#include <seasocks/IgnoringLogger.h>
+#include <seasocks/PrintfLogger.h>
 #include <seasocks/Server.h>
 #include <seasocks/WebSocket.h>
 #include <AuxTaskNonRT.h>
@@ -64,7 +69,7 @@ void WSServer::client_task_func(std::shared_ptr<WSServerDataHandler> handler, vo
 void WSServer::setup(int _port) {
        port = _port;

-       auto logger = std::make_shared<seasocks::IgnoringLogger>();
+       auto logger = std::make_shared<seasocks::PrintfLogger>();
        server = std::make_shared<seasocks::Server>(logger);

        server_task = std::unique_ptr<AuxTaskNonRT>(new AuxTaskNonRT());

e.g.: with -O0:

info: Serving content from /dev/null
info: Listening on http://bela:5555/
info: 192.168.7.1:64001 : Accepted on descriptor 16
access: 192.168.7.1:64001 : Request: GET /gui_data HTTP/1.1
debug: 192.168.7.1:64001 : Key: Host || 192.168.7.2:5555
debug: 192.168.7.1:64001 : Key: Connection || Upgrade
debug: 192.168.7.1:64001 : Key: Pragma || no-cache
debug: 192.168.7.1:64001 : Key: Cache-Control || no-cache
debug: 192.168.7.1:64001 : Key: User-Agent || Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
debug: 192.168.7.1:64001 : Key: Upgrade || websocket
debug: 192.168.7.1:64001 : Key: Origin || http://192.168.7.2
debug: 192.168.7.1:64001 : Key: Sec-WebSocket-Version || 13
debug: 192.168.7.1:64001 : Key: Accept-Encoding || gzip, deflate
debug: 192.168.7.1:64001 : Key: Accept-Language || en-GB,en;q=0.9,it-IT;q=0.8,it;q=0.7,es-ES;q=0.6,es;q=0.5,el-GR;q=0.4,el;q=0.3,en-US;q=0.2
debug: 192.168.7.1:64001 : Key: Cookie || io=8YTpgU70c4AF1AqMAAAF
debug: 192.168.7.1:64001 : Key: Sec-WebSocket-Key || 7AlOyDuL4q9Od1IH/DQtdg==
debug: 192.168.7.1:64001 : Key: Sec-WebSocket-Extensions || permessage-deflate; client_max_window_bits
info: 192.168.7.1:64001 : Websocket request for /gui_data'
warning: 192.168.7.1:64001 : Couldn't find WebSocket end point for '/gui_data'
access: 192.168.7.1:64001 : Response: HTTP/1.1 404 Not Found
debug: Graceful hang-up (EPOLLIN, EPOLLHUP) of socket: 192.168.7.1:64001
debug: Deleting connection: 192.168.7.1:64001
debug: 192.168.7.1:64001 : Closing socket
info: 192.168.7.1:64010 : Accepted on descriptor 16
access: 192.168.7.1:64010 : Request: GET /gui_control HTTP/1.1
debug: 192.168.7.1:64010 : Key: Host || 192.168.7.2:5555
debug: 192.168.7.1:64010 : Key: Connection || Upgrade
debug: 192.168.7.1:64010 : Key: Pragma || no-cache
debug: 192.168.7.1:64010 : Key: Cache-Control || no-cache
debug: 192.168.7.1:64010 : Key: User-Agent || Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
debug: 192.168.7.1:64010 : Key: Upgrade || websocket
debug: 192.168.7.1:64010 : Key: Origin || http://192.168.7.2
debug: 192.168.7.1:64010 : Key: Sec-WebSocket-Version || 13
debug: 192.168.7.1:64010 : Key: Accept-Encoding || gzip, deflate
debug: 192.168.7.1:64010 : Key: Accept-Language || en-GB,en;q=0.9,it-IT;q=0.8,it;q=0.7,es-ES;q=0.6,es;q=0.5,el-GR;q=0.4,el;q=0.3,en-US;q=0.2
debug: 192.168.7.1:64010 : Key: Cookie || io=8YTpgU70c4AF1AqMAAAF
debug: 192.168.7.1:64010 : Key: Sec-WebSocket-Key || HP3T/4W+nc/ssP+HkNvYxg==
debug: 192.168.7.1:64010 : Key: Sec-WebSocket-Extensions || permessage-deflate; client_max_window_bits
info: 192.168.7.1:64010 : Websocket request for /gui_control'
warning: 192.168.7.1:64010 : Couldn't find WebSocket end point for '/gui_control'
access: 192.168.7.1:64010 : Response: HTTP/1.1 404 Not Found
debug: Graceful hang-up (EPOLLIN, EPOLLHUP) of socket: 192.168.7.1:64010
debug: Deleting connection: 192.168.7.1:64010
debug: 192.168.7.1:64010 : Closing socket

while with -O3:

info: Serving content from /dev/null
info: Listening on http://bela:5555/
info: 192.168.7.1:64323 : Accepted on descriptor 16
access: 192.168.7.1:64323 : Request: GET /gui_control HTTP/1.1
debug: 192.168.7.1:64323 : Key: Host || 192.168.7.2:5555
debug: 192.168.7.1:64323 : Key: Connection || Upgrade
debug: 192.168.7.1:64323 : Key: Pragma || no-cache
debug: 192.168.7.1:64323 : Key: Cache-Control || no-cache
debug: 192.168.7.1:64323 : Key: User-Agent || Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
debug: 192.168.7.1:64323 : Key: Upgrade || websocket
debug: 192.168.7.1:64323 : Key: Origin || http://192.168.7.2
debug: 192.168.7.1:64323 : Key: Sec-WebSocket-Version || 13
debug: 192.168.7.1:64323 : Key: Accept-Encoding || gzip, deflate
debug: 192.168.7.1:64323 : Key: Accept-Language || en-GB,en;q=0.9,it-IT;q=0.8,it;q=0.7,es-ES;q=0.6,es;q=0.5,el-GR;q=0.4,el;q=0.3,en-US;q=0.2
debug: 192.168.7.1:64323 : Key: Cookie || io=8YTpgU70c4AF1AqMAAAF
debug: 192.168.7.1:64323 : Key: Sec-WebSocket-Key || P5byeTC8kVZp6dg08q1WJA==
debug: 192.168.7.1:64323 : Key: Sec-WebSocket-Extensions || permessage-deflate; client_max_window_bits
info: 192.168.7.1:64323 : Websocket request for /gui_control'
debug: 192.168.7.1:64323 : Got a hybi-8 websocket with key=P5byeTC8kVZp6dg08q1WJA==
debug: 192.168.7.1:64323 : Attempting websocket upgrade
access: 192.168.7.1:64323 : Response: HTTP/1.1 101 WebSocket Protocol Handshake
Handler onConnect()
client_task_func
debug: 192.168.7.1:64323 : Got text web socket message: '{"event":"connection-reply"}'
Handler onData()
info: 192.168.7.1:64325 : Accepted on descriptor 17
access: 192.168.7.1:64325 : Request: GET /gui_data HTTP/1.1
debug: 192.168.7.1:64325 : Key: Host || 192.168.7.2:5555
debug: 192.168.7.1:64325 : Key: Connection || Upgrade
debug: 192.168.7.1:64325 : Key: Pragma || no-cache
debug: 192.168.7.1:64325 : Key: Cache-Control || no-cache
debug: 192.168.7.1:64325 : Key: User-Agent || Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36
debug: 192.168.7.1:64325 : Key: Upgrade || websocket
debug: 192.168.7.1:64325 : Key: Origin || http://192.168.7.2
debug: 192.168.7.1:64325 : Key: Sec-WebSocket-Version || 13
debug: 192.168.7.1:64325 : Key: Accept-Encoding || gzip, deflate
debug: 192.168.7.1:64325 : Key: Accept-Language || en-GB,en;q=0.9,it-IT;q=0.8,it;q=0.7,es-ES;q=0.6,es;q=0.5,el-GR;q=0.4,el;q=0.3,en-US;q=0.2
debug: 192.168.7.1:64325 : Key: Cookie || io=8YTpgU70c4AF1AqMAAAF
debug: 192.168.7.1:64325 : Key: Sec-WebSocket-Key || 6tauaQMKvsmmMSpmtT9goQ==
debug: 192.168.7.1:64325 : Key: Sec-WebSocket-Extensions || permessage-deflate; client_max_window_bits
info: 192.168.7.1:64325 : Websocket request for /gui_data'
debug: 192.168.7.1:64325 : Got a hybi-8 websocket with key=6tauaQMKvsmmMSpmtT9goQ==
debug: 192.168.7.1:64325 : Attempting websocket upgrade
access: 192.168.7.1:64325 : Response: HTTP/1.1 101 WebSocket Protocol Handshake
Handler onConnect()
giuliomoro commented 4 years ago

on a v0.3.5b image, it seems that building seasocks ba8d7cb4cbb2b741e9e43ca2c0751232fcf60a07 with distcc-clang instead of gcc fixes it :/

giuliomoro commented 4 years ago

pfff it looks like any time you build libseasocks (even a recent version such as 1.4.3) with gcc it will fail if WSServer.cpp is built with -O0. Truth table:

WSServer.cpp libseasocks works
clang++, -O0 clang 1
clang++, -O3 clang 1
clang++, -O0 gcc 0
clang++, -O3 clang 1