private void OnAcceptted(ListeningContext context)
        {
            if (context.AcceptSocket == null || context.AcceptSocket.RemoteEndPoint == null)
            {
                // Canceled due to shutdown.
                return;
            }

#if !API_SIGNATURE_TEST
            MsgPackRpcServerProtocolsTrace.TraceEvent(
                MsgPackRpcServerProtocolsTrace.EndAccept,
                "Accept. {{ \"Socket\" : 0x{0:X}, \"RemoteEndPoint\" : \"{1}\", \"LocalEndPoint\" : \"{2}\" }}",
                ServerTransport.GetHandle(context.AcceptSocket),
                ServerTransport.GetRemoteEndPoint(context.AcceptSocket, context),
                ServerTransport.GetLocalEndPoint(context.AcceptSocket)
                );
#endif

            Contract.Assert(context.BytesTransferred == 0, context.BytesTransferred.ToString());

            var transport = this.GetTransport(context.AcceptSocket);
            context.AcceptSocket = null;
            this.Accept(context);
            transport.Receive(this.GetRequestContext(transport));
        }
Example #2
0
		public void TestConstructorListeningContext()
		{
			using ( var target = new ListeningContext() )
			{
				// OK
			}
		}
 public void TestConstructorListeningContext()
 {
     using (var target = new ListeningContext())
     {
         // OK
     }
 }
        private void Accept(ListeningContext context)
        {
            // Ensure buffers are cleared to avoid unepxected data feeding on Accept
            context.SetBuffer(null, 0, 0);
            context.BufferList = null;

            try
            {
                if (this.IsInShutdown)
                {
                    return;
                }

#if !API_SIGNATURE_TEST
                MsgPackRpcServerProtocolsTrace.TraceEvent(
                    MsgPackRpcServerProtocolsTrace.BeginAccept,
                    "Wait for connection. {{ \"Socket\" : 0x{0:X}, \"LocalEndPoint\" : \"{1}\" }}",
                    this._listeningSocket.Handle,
                    this._listeningSocket.LocalEndPoint
                    );
#endif

                if (!this._listeningSocket.AcceptAsync(context))
                {
                    // Avoid recursive acceptance and the subsequent request delay.
                    // Task is bit heavy here.
                    ThreadPool.QueueUserWorkItem(_ => this.OnAcceptted(context));
                }
            }
            catch (ObjectDisposedException)
            {
                if (!this.IsDisposed)
                {
                    throw;
                }
            }
        }