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;
 }
        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;
        }
 public WebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool)
     : base(channelFactory, channelFactory, EndpointAddress.AnonymousAddress, channelFactory.MessageVersion.Addressing.AnonymousUri, remoteAddresss, via)
 {
     Fx.Assert(channelFactory.WebSocketSettings != null, "channelFactory.WebSocketTransportSettings should not be null.");
     _webSocketSettings = channelFactory.WebSocketSettings;
     _transferMode = channelFactory.TransferMode;
     _maxBufferSize = channelFactory.MaxBufferSize;
     _bufferPool = bufferPool;
     _transportFactorySettings = channelFactory;
 }
        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;
        }
Example #5
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();
        }
        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);
        }
        public SocketConnection(Socket socket, ConnectionBufferPool connectionBufferPool, bool autoBindToCompletionPort)
        {
            if (socket == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("socket");
            }

            Fx.Assert(connectionBufferPool != null, "Argument connectionBufferPool cannot be null");

            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.remoteEndpoint = null;

            if (autoBindToCompletionPort)
            {
                this.socket.UseOnlyOverlappedIO = false;
            }

            // In SMSvcHost, sockets must be duplicated to the target process. Binding a handle to a completion port
            // prevents any duplicated handle from ever binding to a completion port. The target process is where we
            // want to use completion ports for performance. This means that in SMSvcHost, socket.UseOnlyOverlappedIO
            // must be set to true to prevent completion port use.
            if (this.socket.UseOnlyOverlappedIO)
            {
                // Init BeginRead state
                if (onReceiveCompleted == null)
                {
                    onReceiveCompleted = Fx.ThunkCallback(new AsyncCallback(OnReceiveCompleted));
                }
            }

            this.TraceSocketInfo(socket, TraceCode.SocketConnectionCreate, SR.TraceCodeSocketConnectionCreate, null);
        }
 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 ClientWebSocketTransportDuplexSessionChannel(HttpChannelFactory<IDuplexSessionChannel> channelFactory, ClientWebSocketFactory connectionFactory, EndpointAddress remoteAddresss, Uri via, ConnectionBufferPool bufferPool)
     : base(channelFactory, remoteAddresss, via, bufferPool)
 {
     this.channelFactory = channelFactory;
     this.connectionFactory = connectionFactory;
 }
 public SocketConnectionInitiator(int bufferSize)
 {
     _bufferSize = bufferSize;
     _connectionBufferPool = new ConnectionBufferPool(bufferSize);
 }
 SocketConnectionListener(ISocketListenerSettings settings, bool useOnlyOverlappedIO)
 {
     Fx.Assert(settings != null, "Input settings should not be null");
     this.settings = settings;
     this.useOnlyOverlappedIO = useOnlyOverlappedIO;
     this.connectionBufferPool = new ConnectionBufferPool(settings.BufferSize);
 }
 private SocketConnectionListener(ISocketListenerSettings settings, bool useOnlyOverlappedIO)
 {
     this.settings = settings;
     this.useOnlyOverlappedIO = useOnlyOverlappedIO;
     this.connectionBufferPool = new ConnectionBufferPool(settings.BufferSize);
 }
 private ConnectionBufferPool EnsureConnectionBufferPool(int connectionBufferSize)
 {
     lock (this.ThisLock)
     {
         if ((this.connectionBufferPool == null) || (connectionBufferSize != this.connectionBufferPool.BufferSize))
         {
             this.connectionBufferPool = new ConnectionBufferPool(connectionBufferSize);
         }
         return this.connectionBufferPool;
     }
 }