TransportListener(IPEndPoint endPoint) { if (TD.TcpTransportListenerListeningStartIsEnabled()) { TD.TcpTransportListenerListeningStart(this.EventTraceActivity, GetRemoteEndpointAddressPort(endPoint)); } transportType = TransportType.Tcp; SocketSettings socketSettings = new SocketSettings(); IConnectionListener connectionListener = null; if (endPoint.Address.Equals(IPAddress.Broadcast)) { if (Socket.OSSupportsIPv4) { connectionListener = new SocketConnectionListener(new IPEndPoint(IPAddress.Any, endPoint.Port), socketSettings, true); demuxer = Go(connectionListener); } if (Socket.OSSupportsIPv6) { connectionListener = new SocketConnectionListener(new IPEndPoint(IPAddress.IPv6Any, endPoint.Port), socketSettings, true); demuxerV6 = Go(connectionListener); } } else { connectionListener = new SocketConnectionListener(endPoint, socketSettings, true); demuxer = Go(connectionListener); } if (TD.TcpTransportListenerListeningStopIsEnabled()) { TD.TcpTransportListenerListeningStop(this.EventTraceActivity); } }
private Socket ListenAndBind(IPEndPoint localEndpoint) { Socket socket = new Socket(localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.Bind(localEndpoint); } catch (SocketException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(SocketConnectionListener.ConvertListenException(exception, localEndpoint)); } return(socket); }
internal override void OnOpen() { SocketConnectionListener socketListener = null; if (this.listenSocket != null) { socketListener = new SocketConnectionListener(this.listenSocket, this, false); this.listenSocket = null; } else { int port = this.registration.ListenUri.Port; if (port == -1) { port = TcpUri.DefaultPort; } socketListener = new SocketConnectionListener(new IPEndPoint(ipAddress, port), this, false); } connectionListener = new BufferedConnectionListener(socketListener, MaxOutputDelay, ConnectionBufferSize); if (DiagnosticUtility.ShouldUseActivity) { connectionListener = new TracingConnectionListener(connectionListener, this.registration.ListenUri.ToString(), false); } connectionDemuxer = new ConnectionDemuxer(connectionListener, MaxPendingAccepts, MaxPendingConnections, ChannelInitializationTimeout, IdleTimeout, MaxPooledConnections, OnGetTransportFactorySettings, OnGetSingletonMessageHandler, OnHandleServerSessionPreamble, OnDemuxerError); bool startedDemuxing = false; try { connectionDemuxer.StartDemuxing(); startedDemuxing = true; } finally { if (!startedDemuxing) { connectionDemuxer.Dispose(); } } }
internal override void OnOpen() { SocketConnectionListener socketListener = null; if (this.listenSocket != null) { socketListener = new SocketConnectionListener(this.listenSocket, this, false); this.listenSocket = null; } else { int port = this.registration.ListenUri.Port; if (port == -1) port = TcpUri.DefaultPort; socketListener = new SocketConnectionListener(new IPEndPoint(ipAddress, port), this, false); } connectionListener = new BufferedConnectionListener(socketListener, MaxOutputDelay, ConnectionBufferSize); if (DiagnosticUtility.ShouldUseActivity) { connectionListener = new TracingConnectionListener(connectionListener, this.registration.ListenUri.ToString(), false); } connectionDemuxer = new ConnectionDemuxer(connectionListener, MaxPendingAccepts, MaxPendingConnections, ChannelInitializationTimeout, IdleTimeout, MaxPooledConnections, OnGetTransportFactorySettings, OnGetSingletonMessageHandler, OnHandleServerSessionPreamble, OnDemuxerError); bool startedDemuxing = false; try { connectionDemuxer.StartDemuxing(); startedDemuxing = true; } finally { if (!startedDemuxing) { connectionDemuxer.Dispose(); } } }
internal override void OnOpen() { SocketConnectionListener connectionListener = null; if (this.listenSocket != null) { connectionListener = new SocketConnectionListener(this.listenSocket, this, false); this.listenSocket = null; } else { int port = this.registration.ListenUri.Port; if (port == -1) { port = 0x328; } connectionListener = new SocketConnectionListener(new IPEndPoint(this.ipAddress, port), this, false); } this.connectionListener = new BufferedConnectionListener(connectionListener, base.MaxOutputDelay, base.ConnectionBufferSize); if (DiagnosticUtility.ShouldUseActivity) { this.connectionListener = new TracingConnectionListener(this.connectionListener, this.registration.ListenUri.ToString(), false); } this.connectionDemuxer = new ConnectionDemuxer(this.connectionListener, base.MaxPendingAccepts, base.MaxPendingConnections, base.ChannelInitializationTimeout, base.IdleTimeout, base.MaxPooledConnections, new TransportSettingsCallback(this.OnGetTransportFactorySettings), new SingletonPreambleDemuxCallback(this.OnGetSingletonMessageHandler), new ServerSessionPreambleDemuxCallback(this.OnHandleServerSessionPreamble), new System.ServiceModel.Channels.ErrorCallback(this.OnDemuxerError)); bool flag = false; try { this.connectionDemuxer.StartDemuxing(); flag = true; } finally { if (!flag) { this.connectionDemuxer.Dispose(); } } }
public AcceptAsyncResult(SocketConnectionListener listener, AsyncCallback callback, object state) : base(callback, state) { this.listener = listener; this.socketAsyncEventArgs = listener.TakeSocketAsyncEventArgs(); this.socketAsyncEventArgs.UserToken = this; this.socketAsyncEventArgs.Completed += acceptAsyncCompleted; base.OnCompleting = onCompleting; if (!Thread.CurrentThread.IsThreadPoolThread) { if (startAccept == null) { startAccept = new Action <object>(SocketConnectionListener.AcceptAsyncResult.StartAccept); } ActionItem.Schedule(startAccept, this); } else { bool flag; bool flag2 = false; try { flag = this.StartAccept(); flag2 = true; } finally { if (!flag2) { this.ReturnSocketAsyncEventArgs(); } } if (flag) { base.Complete(true); } } }
public AcceptAsyncResult(SocketConnectionListener listener, AsyncCallback callback, object state) : base(callback, state) { if (TD.SocketAcceptEnqueuedIsEnabled()) { TD.SocketAcceptEnqueued(this.EventTraceActivity); } Fx.Assert(listener != null, "listener should not be null"); this.listener = listener; this.socketAsyncEventArgs = listener.TakeSocketAsyncEventArgs(); this.socketAsyncEventArgs.UserToken = this; this.socketAsyncEventArgs.Completed += acceptAsyncCompleted; this.OnCompleting = onCompleting; // If we're going to start up the thread pool eventually anyway, avoid using RegisterWaitForSingleObject if (!Thread.CurrentThread.IsThreadPoolThread) { if (startAccept == null) { startAccept = new Action<object>(StartAccept); } ActionItem.Schedule(startAccept, this); } else { bool completeSelf; bool success = false; try { completeSelf = StartAccept(); success = true; } finally { if (!success) { // Return the args when an exception is thrown ReturnSocketAsyncEventArgs(); } } if (completeSelf) { base.Complete(true); } } }
public AcceptAsyncResult(SocketConnectionListener listener, AsyncCallback callback, object state) : base(callback, state) { this.listener = listener; this.socketAsyncEventArgs = listener.TakeSocketAsyncEventArgs(); this.socketAsyncEventArgs.UserToken = this; this.socketAsyncEventArgs.Completed += acceptAsyncCompleted; base.OnCompleting = onCompleting; if (!Thread.CurrentThread.IsThreadPoolThread) { if (startAccept == null) { startAccept = new Action<object>(SocketConnectionListener.AcceptAsyncResult.StartAccept); } ActionItem.Schedule(startAccept, this); } else { bool flag; bool flag2 = false; try { flag = this.StartAccept(); flag2 = true; } finally { if (!flag2) { this.ReturnSocketAsyncEventArgs(); } } if (flag) { base.Complete(true); } } }