diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 564dd406..b47dbfa0 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -102,6 +102,7 @@ namespace WebSocketSharp private static readonly int _maxRetryCountForConnect; private Action _message; private Queue _messageEventQueue; + private bool _noDelay; private uint _nonceCount; private string _origin; private ManualResetEvent _pongReceived; @@ -530,6 +531,38 @@ namespace WebSocketSharp } } + /// + /// Gets or sets a value indicating whether the underlying TCP socket + /// disables a delay when send or receive buffer is not full. + /// + /// + /// The set operation works if the current state of the interface is + /// New or Closed. + /// + /// + /// + /// true if the delay is disabled; otherwise, false. + /// + /// + /// The default value is false. + /// + /// + /// + public bool NoDelay { + get { + return _noDelay; + } + + set { + lock (_forState) { + if (!canSet ()) + return; + + _noDelay = value; + } + } + } + /// /// Gets or sets the value of the HTTP Origin header to send with /// the handshake request. @@ -886,6 +919,9 @@ namespace WebSocketSharp processSecWebSocketExtensionsClientHeader (val); } + if (_noDelay) + _socket.NoDelay = true; + createHandshakeResponse ().WriteTo (_stream); return true; @@ -2257,6 +2293,10 @@ namespace WebSocketSharp releaseClientResources (); _tcpClient = new TcpClient (_proxyUri.DnsSafeHost, _proxyUri.Port); + + if (_noDelay) + _tcpClient.NoDelay = true; + _stream = _tcpClient.GetStream (); } @@ -2272,6 +2312,10 @@ namespace WebSocketSharp { if (_proxyUri != null) { _tcpClient = new TcpClient (_proxyUri.DnsSafeHost, _proxyUri.Port); + + if (_noDelay) + _tcpClient.NoDelay = true; + _stream = _tcpClient.GetStream (); var res = sendProxyConnectRequest (); @@ -2283,6 +2327,10 @@ namespace WebSocketSharp } else { _tcpClient = new TcpClient (_uri.DnsSafeHost, _uri.Port); + + if (_noDelay) + _tcpClient.NoDelay = true; + _stream = _tcpClient.GetStream (); }