+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;
+ }
+ }
+}
+
+