On Mon, 15 Oct 2012 08:53:43 +0200, Sönke Ludwig wrote:

On Sun, 14 Oct 2012 22:45:22 +0200, Eldar Insafutdinov wrote:

I found that there is a module in vibe to handle Websockets upgrade request and perform handshaking.
However I don't really understand how to then listen for incoming data on the websocket:
vibe.http.websockets.Websocket class doesn't provide any interface for that. Is it still a work in progress?

Also looking at the sources of libevent driver I am wondering - won't websocket be closed immediately after
handling of incoming request: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/drivers/libevent2_tcp.d#L373?

The vibenotes project contains a usage example of WebSockets in its broadcast module. It doesn't seem work as it should though. I'll notify Jan, who did the WebSocket implementation.

After some digging into why vibenotes example didn't work I figured that sending a signal wouldn't make it into the other fibers. The reason for that is that in the processing loop for each websocket we check for WebSocket.connected property:

while( socket.connected ) {
    ...
    rawYield();
}

However the implementation of WebSocket.connected() checks for Libevent2TcpConnection.empty property which itself calls leastSize() method. And this function only returns when there is some new data to read. So as a result emitting of the signal from each fiber can never trigger socket.connected to return. As a workaround I made WebSocket.connected() call TcpConnection.connected instead(for that I had to downcast Stream to TcpConnection). Is this a correct strategy to do so?