Exemple #1
0
        public static ManagedWebSocket CreateClientWebSocket(Stream innerStream,
                                                             string subProtocol, int receiveBufferSize, int sendBufferSize,
                                                             TimeSpan keepAliveInterval, bool useZeroMaskingKey, ArraySegment <byte> internalBuffer)
        {
            if (innerStream == null)
            {
                throw new ArgumentNullException(nameof(innerStream));
            }

            if (!innerStream.CanRead || !innerStream.CanWrite)
            {
                throw new ArgumentException(!innerStream.CanRead ? SR.NotReadableStream : SR.NotWriteableStream, nameof(innerStream));
            }

            if (subProtocol != null)
            {
                WebSocketValidate.ValidateSubprotocol(subProtocol);
            }

            if (keepAliveInterval != Timeout.InfiniteTimeSpan && keepAliveInterval < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(keepAliveInterval), keepAliveInterval,
                                                      SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall,
                                                                0));
            }

            if (receiveBufferSize <= 0 || sendBufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          receiveBufferSize <= 0 ? nameof(receiveBufferSize) : nameof(sendBufferSize),
                          receiveBufferSize <= 0 ? receiveBufferSize : sendBufferSize,
                          SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 0));
            }

            return(ManagedWebSocket.CreateFromConnectedStream(
                       innerStream, false, subProtocol, keepAliveInterval,
                       receiveBufferSize, internalBuffer));
        }
Exemple #2
0
        public void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment <byte> buffer)
        {
            ThrowIfReadOnly();

            if (receiveBufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(receiveBufferSize), receiveBufferSize, SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 1));
            }
            if (sendBufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(sendBufferSize), sendBufferSize, SR.Format(SR.net_WebSockets_ArgumentOutOfRange_TooSmall, 1));
            }

            WebSocketValidate.ValidateArraySegment(buffer, nameof(buffer));
            if (buffer.Count == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(buffer));
            }

            _receiveBufferSize = receiveBufferSize;
            _sendBufferSize    = sendBufferSize;
            _buffer            = buffer;
        }
Exemple #3
0
 public Task <HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol, int receiveBufferSize, TimeSpan keepAliveInterval, ArraySegment <byte> internalBuffer)
 {
     WebSocketValidate.ValidateArraySegment(internalBuffer, nameof(internalBuffer));
     return(HttpWebSocket.AcceptWebSocketAsyncCore(this, subProtocol, receiveBufferSize, keepAliveInterval, internalBuffer));
 }