Ejemplo n.º 1
0
        public SocketConnection(ConnectionBufferPool connectionBufferPool)
        {
            Contract.Assert(connectionBufferPool != null, "Argument connectionBufferPool cannot be null");

            _closeState           = CloseState.Open;
            _connectionBufferPool = connectionBufferPool;
            _readBuffer           = _connectionBufferPool.Take();
            _asyncReadBufferSize  = _readBuffer.Length;
            _sendTimeout          = _receiveTimeout = TimeSpan.MaxValue;
        }
 private ConnectionBufferPool EnsureConnectionBufferPool(int connectionBufferSize)
 {
     lock (this.ThisLock)
     {
         if ((this.connectionBufferPool == null) || (connectionBufferSize != this.connectionBufferPool.BufferSize))
         {
             this.connectionBufferPool = new ConnectionBufferPool(connectionBufferSize);
         }
         return(this.connectionBufferPool);
     }
 }
Ejemplo n.º 3
0
        public CoreClrSocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool)
            : base(connectionBufferPool)
        {
            if (socket == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
            }

            _closeState            = CloseState.Open;
            _socket                = socket;
            _socket.SendBufferSize = _socket.ReceiveBufferSize = _asyncReadBufferSize;
            _sendTimeout           = _receiveTimeout = TimeSpan.MaxValue;
        }
Ejemplo n.º 4
0
        public RTSocketConnection(StreamSocket socket, ConnectionBufferPool connectionBufferPool) : base(connectionBufferPool)
        {
            if (socket == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
            }

            _socket = socket;
            // Not using a buffer wrapped output stream as bytes will sit in the buffer
            // unsent unless the immediate flag is specified.
            _outputStream = _socket.OutputStream.AsStreamForWrite();
            _inputStream  = _socket.InputStream.AsStreamForRead(_asyncReadBufferSize);
            _receiveCts   = new CancellationTokenSource();
            _sendCts      = new CancellationTokenSource();
        }
 public ServerWebSocketTransportDuplexSessionChannel(
     HttpChannelListener channelListener,
     EndpointAddress localAddress,
     Uri localVia,
     ConnectionBufferPool bufferPool,
     HttpRequestContext httpRequestContext,
     HttpPipeline httpPipeline,
     HttpResponseMessage httpResponseMessage,
     string subProtocol)
     : base(channelListener, localAddress, localVia, bufferPool)
 {
     this.httpRequestContext  = httpRequestContext;
     this.httpPipeline        = httpPipeline;
     this.httpResponseMessage = httpResponseMessage;
     this.subProtocol         = subProtocol;
 }
Ejemplo n.º 6
0
        internal UdpSocketReceiveManager(UdpSocket[] receiveSockets, int maxPendingReceivesPerSocket, BufferManager bufferManager, IUdpReceiveHandler receiveHandler)
        {
            Fx.Assert(receiveSockets != null, "receiveSockets parameter is null");
            Fx.Assert(receiveSockets.Length > 0, "receiveSockets parameter is empty");
            Fx.Assert(maxPendingReceivesPerSocket > 0, "maxPendingReceivesPerSocket can't be <= 0");
            Fx.Assert(receiveHandler.MaxReceivedMessageSize > 0, "maxReceivedMessageSize must be > 0");
            Fx.Assert(bufferManager != null, "bufferManager argument should not be null");
            Fx.Assert(receiveHandler != null, "receiveHandler should not be null");

            this.receiveHandler = receiveHandler;
            this.thisLock       = new object();
            this.bufferManager  = bufferManager;
            this.receiveSockets = receiveSockets;
            this.maxPendingReceivesPerSocket = maxPendingReceivesPerSocket;
            this.messageBufferSize           = UdpUtility.ComputeMessageBufferSize(receiveHandler.MaxReceivedMessageSize);

            int maxPendingReceives = maxPendingReceivesPerSocket * receiveSockets.Length;

            this.receiveBufferPool = new ConnectionBufferPool(this.messageBufferSize, maxPendingReceives);
        }
Ejemplo n.º 7
0
 public SocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool, bool autoBindToCompletionPort)
 {
     if (socket == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
     }
     this.closeState            = CloseState.Open;
     this.exceptionEventType    = TraceEventType.Error;
     this.socket                = socket;
     this.connectionBufferPool  = connectionBufferPool;
     this.readBuffer            = this.connectionBufferPool.Take();
     this.asyncReadBufferSize   = this.readBuffer.Length;
     this.socket.SendBufferSize = this.socket.ReceiveBufferSize = this.asyncReadBufferSize;
     this.sendTimeout           = this.receiveTimeout = TimeSpan.MaxValue;
     this.onReceive             = Fx.ThunkCallback(new AsyncCallback(this.OnReceive));
     this.asyncReadOverlapped   = new OverlappedContext();
     if (autoBindToCompletionPort)
     {
         this.socket.UseOnlyOverlappedIO = false;
     }
     this.TraceSocketInfo(socket, 0x40019, "TraceCodeSocketConnectionCreate", null);
 }
 public SocketConnectionInitiator(int bufferSize)
 {
     this.bufferSize           = bufferSize;
     this.connectionBufferPool = new ConnectionBufferPool(bufferSize);
 }
Ejemplo n.º 9
0
        internal HttpChannelFactory(HttpTransportBindingElement bindingElement, BindingContext context)
            : base(bindingElement, context, HttpTransportDefaults.GetDefaultMessageEncoderFactory())
        {
            // validate setting interactions
            if (bindingElement.TransferMode == TransferMode.Buffered)
            {
                if (bindingElement.MaxReceivedMessageSize > int.MaxValue)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new ArgumentOutOfRangeException("bindingElement.MaxReceivedMessageSize",
                                                              SR.MaxReceivedMessageSizeMustBeInIntegerRange));
                }

                if (bindingElement.MaxBufferSize != bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustMatchMaxReceivedMessageSize);
                }
            }
            else
            {
                if (bindingElement.MaxBufferSize > bindingElement.MaxReceivedMessageSize)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                                 SR.MaxBufferSizeMustNotExceedMaxReceivedMessageSize);
                }
            }

            if (TransferModeHelper.IsRequestStreamed(bindingElement.TransferMode) &&
                bindingElement.AuthenticationScheme != AuthenticationSchemes.Anonymous)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("bindingElement",
                                                                             SR.HttpAuthDoesNotSupportRequestStreaming);
            }

            _allowCookies = bindingElement.AllowCookies;

            if (_allowCookies)
            {
                _httpCookieContainerManager = new HttpCookieContainerManager();
            }

            if (!bindingElement.AuthenticationScheme.IsSingleton())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("value", SR.Format(SR.HttpRequiresSingleAuthScheme,
                                                                                                bindingElement.AuthenticationScheme));
            }
            _authenticationScheme = bindingElement.AuthenticationScheme;
            _maxBufferSize        = bindingElement.MaxBufferSize;
            _transferMode         = bindingElement.TransferMode;
            _useDefaultWebProxy   = bindingElement.UseDefaultWebProxy;

            _channelCredentials   = context.BindingParameters.Find <SecurityCredentialsManager>();
            _securityCapabilities = bindingElement.GetProperty <ISecurityCapabilities>(context);

            _webSocketSettings = WebSocketHelper.GetRuntimeWebSocketSettings(bindingElement.WebSocketSettings);
            int webSocketBufferSize = WebSocketHelper.ComputeClientBufferSize(MaxReceivedMessageSize);

            _bufferPool               = new ConnectionBufferPool(webSocketBufferSize);
            _clientWebSocketFactory   = ClientWebSocketFactory.GetFactory();
            _webSocketSoapContentType = new Lazy <string>(() => MessageEncoderFactory.CreateSessionEncoder().ContentType, LazyThreadSafetyMode.ExecutionAndPublication);
        }
Ejemplo n.º 10
0
 public ClientWebSocketTransportDuplexSessionChannel(HttpChannelFactory <IDuplexSessionChannel> channelFactory, ClientWebSocketFactory connectionFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool)
     : base(channelFactory, remoteAddresss, via, bufferPool)
 {
     Contract.Assert(channelFactory != null, "connection factory must be set");
     _channelFactory    = channelFactory;
     _connectionFactory = connectionFactory;
 }
Ejemplo n.º 11
0
 public ClientWebSocketTransportDuplexSessionChannel(HttpChannelFactory <IDuplexSessionChannel> channelFactory, ClientWebSocketFactory connectionFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool)
     : base(channelFactory, remoteAddresss, via, bufferPool)
 {
     this.channelFactory    = channelFactory;
     this.connectionFactory = connectionFactory;
 }
 private SocketConnectionListener(ISocketListenerSettings settings, bool useOnlyOverlappedIO)
 {
     this.settings             = settings;
     this.useOnlyOverlappedIO  = useOnlyOverlappedIO;
     this.connectionBufferPool = new ConnectionBufferPool(settings.BufferSize);
 }