X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Ftransports.phh;h=ea592a8d7892dcae9b9bec4baa54f6a2b94b717b;hb=8d024784c4351c263b394caed0d032963659ca4d;hp=fcc5c6d23e35102346758a4bc415b9d17d29e032;hpb=8b0992347fdfdb40715268bb07481d35fc5191fb;p=brisk.git diff --git a/web/Obj/transports.phh b/web/Obj/transports.phh index fcc5c6d..ea592a8 100644 --- a/web/Obj/transports.phh +++ b/web/Obj/transports.phh @@ -75,6 +75,11 @@ class Transport_template { { } + function postclose_get($sock, $curtime) + { + return NULL; + } + function chunk($step, $cont) { } @@ -90,6 +95,38 @@ class Transport_template { } } +define("TRANSP_WS_CLOSE_TOUT", 5); + +class Transport_websocket_postclose { + function Transport_websocket_postclose($transp_ws, $sock, $curtime) { + printf("POSTCLOSE: Creation\n"); + $this->transp_ws = $transp_ws; + $this->sock = $sock; + $this->start = $curtime; + // status not required, currently + // $this->status = "begin"; + } + + function read($payload, $curtime) { + if ($this->start + TRANSP_WS_CLOSE_TOUT < $curtime) { + printf("POSTCLOSE: Closing ws (%d) force close by timeout\n", $this->sock); + return 0; + } + if (mb_strlen($payload, "ASCII") > 1) { + $this->transp_ws->unchunk($payload, $this->sock); + } + if ($this->transp_ws->hasSentClose) { + printf("POSTCLOSE: Closing ws gracefully\n"); + return 0; + } + else { + printf("POSTCLOSE: not yet finished\n"); + return 1; + } + } +} + + class Transport_websocket { protected $magicGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; @@ -99,8 +136,6 @@ class Transport_websocket { $this->headerSecWebSocketProtocolRequired = false; $this->headerSecWebSocketExtensionsRequired = false; - $this->handlingPartialPacket = false; - $this->sendingContinuous = false; $this->handlingPartialPacket = false; @@ -205,10 +240,10 @@ class Transport_websocket { return $strout . "\n"; } - function unchunk($cont) + function unchunk($cont, $sock) { // fprintf(STDERR, "CHUNK: [%s]\n", $cont); - return $this->deframe($cont); + return $this->deframe($cont, $sock); } function chunk($step, $cont) @@ -283,7 +318,7 @@ class Transport_websocket { return chr($b1) . chr($b2) . $lengthField . $message; } - protected function deframe($message) { + protected function deframe($message, $socket) { //echo $this->strtohex($message); $headers = $this->extractHeaders($message); $pongReply = false; @@ -327,7 +362,8 @@ class Transport_websocket { if ($pongReply) { $reply = $this->frame($payload,$this,'pong'); // TODO FIXME ALL socket_write management - socket_write($user->socket,$reply,mb_strlen($reply, "ASCII")); + // socket_write($user->socket,$reply,mb_strlen($reply, "ASCII")); + @fwrite($socket, $reply, mb_strlen($reply, "ASCII")); return false; } if (extension_loaded('mbstring')) { @@ -478,6 +514,11 @@ class Transport_websocket { return(chr(0x88).chr(0x02).chr(0xe8).chr(0x03)); } + function postclose_get($sock, $curtime) + { + return new Transport_websocket_postclose($this, $sock, $curtime); + } + static function fini($init_string, $base, $blockerr) { return (sprintf('@BEGIN@ %s window.onbeforeunload = null; window.onunload = null; document.location.assign("%sindex.php"); @END@', ($blockerr ? 'xstm.stop(); ' : ''), $base).self::close()); @@ -513,6 +554,11 @@ class Transport_xhr { return ""; } + function postclose_get($sock, $curtime) + { + return NULL; + } + static function fini($init_string, $base, $blockerr) { return (sprintf('@BEGIN@ %s window.onbeforeunload = null; window.onunload = null; document.location.assign("%sindex.php"); @END@', ($blockerr ? 'xstm.stop(); ' : ''), $base)); @@ -549,10 +595,10 @@ class Transport_iframe { $ret .= sprintf(" - - + + - + + @@ -615,6 +666,11 @@ class Transport_htmlfile extends Transport_iframe { function Transport_htmlfile() { $this->type = 'htmlfile'; } + + function postclose_get($sock, $curtime) + { + return NULL; + } } class Transport {