Skip to content

Commit

Permalink
Merge pull request #1107 from Yoplitein/websocketCloseReason
Browse files Browse the repository at this point in the history
Add optional reason message and code to WebSocket.close
  • Loading branch information
s-ludwig committed May 16, 2015
2 parents cbb5d2b + 6d16bc1 commit 058c45d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion source/vibe/http/websockets.d
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,23 @@ final class WebSocket {

/**
Actively closes the connection.
Params:
code = Numeric code indicating a termination reason.
reason = Message describing why the connection was terminated.
*/
void close()
void close(short code = 0, string reason = "")
{
//control frame payloads are limited to 125 bytes
assert(reason.length <= 123);

if (connected) {
m_writeMutex.performLocked!({
m_sentCloseFrame = true;
Frame frame;
frame.opcode = FrameOpcode.close;
if(code != 0)
frame.payload = std.bitmanip.nativeToBigEndian(code) ~ cast(ubyte[])reason;
frame.fin = true;
frame.writeFrame(m_conn);
});
Expand Down

0 comments on commit 058c45d

Please sign in to comment.