diff --git a/uppsrc/Core/WebSocket.cpp b/uppsrc/Core/WebSocket.cpp index eb6ff83a0..0815be40f 100644 --- a/uppsrc/Core/WebSocket.cpp +++ b/uppsrc/Core/WebSocket.cpp @@ -516,6 +516,7 @@ bool WebSocket::WebAccept(TcpSocket& socket_, HttpHeader& hdr) "Sec-WebSocket-Accept: " + Base64Encode((char *)sha1, 20) + "\r\n\r\n" ); + LLOG("HTTP request header received, sending response"); data.Clear(); opcode = READING_FRAME_HEADER; return true; diff --git a/uppsrc/Turtle/Event.cpp b/uppsrc/Turtle/Event.cpp index 764382491..1cd74ee85 100644 --- a/uppsrc/Turtle/Event.cpp +++ b/uppsrc/Turtle/Event.cpp @@ -4,8 +4,8 @@ namespace Upp { -#define LLOG(x) // LLOG(x) -#define LDUMP(x) // RDUMP(x) +#define LLOG(x) // DLOG(x) +#define LDUMP(x) // DDUMP(x) #define LTIMING(x) int Ctrl::serial_time0 = Null; @@ -51,15 +51,17 @@ bool Ctrl::IsWaitingEvent() EndSession(); Exit(0); } - while(socket.Timeout(0).WaitRead()) { - socket.Timeout(20000); + websocket.Do(); + for(;;) { String s = websocket.Receive(); - if(s.IsVoid()) { // No data returned -> means EOF was reached + if(websocket.IsClosed()) { WhenDisconnect(); EndSession(); Exit(0); } - LLOG("Recieved data " << s); + if(s.GetCount() == 0) + break; + LLOG("Received data " << s); StringStream ss(s); while(!ss.IsEof()) { String s = ss.GetLine(); @@ -82,7 +84,6 @@ bool Ctrl::IsWaitingEvent() serial_time0 = Null; } } - socket.Timeout(20000); if(socket.IsError()) LLOG("ERROR: " << socket.GetErrorDesc()); return event_queue.GetCount(); @@ -92,10 +93,11 @@ void Ctrl::GuiSleep(int ms) { GuiLock __; ASSERT(IsMainThread()); -// LLOG("GuiSleep"); + LLOG("GuiSleep " << ms); + websocket.Do(); int level = LeaveGuiMutexAll(); socket.Timeout(ms).WaitRead(); - socket.Timeout(20000); + socket.Timeout(0); EnterGuiMutex(level); } diff --git a/uppsrc/Turtle/Output.cpp b/uppsrc/Turtle/Output.cpp index fd0dd3341..2c519d1c9 100644 --- a/uppsrc/Turtle/Output.cpp +++ b/uppsrc/Turtle/Output.cpp @@ -54,7 +54,6 @@ void Turtle_PutLink(const String& link) void Ctrl::Output() { - socket.Timeout(20000); if(turtle_stream.HasData()) { websocket.SendBinary(ZCompress(String(DISABLESENDING, 1))); // Do not send events until data transfered and processed int64 x = ++update_serial; diff --git a/uppsrc/Turtle/Server.cpp b/uppsrc/Turtle/Server.cpp index f5d47942d..50744b081 100644 --- a/uppsrc/Turtle/Server.cpp +++ b/uppsrc/Turtle/Server.cpp @@ -10,8 +10,8 @@ namespace Upp { -#define LLOG(x) // DLOG(x) -#define LDUMP(x) // DDUMP(x) +#define LLOG(x) // DLOG(x) +#define LDUMP(x) // DDUMP(x) #define LTIMING(x) int Ctrl::main_pid; @@ -71,7 +71,7 @@ bool Ctrl::StartSession() #endif LLOG("Starting to listen on " << port << ", pid: " << getpid()); - socket.Timeout(2000); // TODO: Not quite ideal way to make quit work.. + socket.Timeout(0); // TODO: Not quite ideal way to make quit work.. for(;;) { if(quit) return false; @@ -108,7 +108,7 @@ bool Ctrl::StartSession() socket.Close(); continue; } - #else +#else break; #endif } @@ -128,9 +128,7 @@ bool Ctrl::StartSession() Ctrl::GlobalBackBuffer(); Ctrl::InitTimer(); -#ifdef PLATFORM_POSIX SetStdFont(ScreenSans(12)); //FIXME general handling -#endif ChStdSkin(); DesktopRect().Color(Cyan()); @@ -138,10 +136,14 @@ bool Ctrl::StartSession() SetDesktop(Desktop()); stat_started = GetSysTime(); + + LLOG("Waiting for the event"); while(!IsWaitingEvent()) GuiSleep(10); + LLOG("Starting the server"); + ProcessEvents(); return true;