Exemplo n.º 1
0
 internal void ProcessRequestMessage(Stream requestStream, MessageReceiveTask receiveTask)
 {
     // invariant: only one thread processing the first 3 statments at one instance in time
     // (statement nr 3 can lead to a next read allowing another i/o completion thread
     // to call this method)
     try {
         // call is serialised, no need for a lock; at most one thread is reading messages from transport.
         Interlocked.Increment(ref m_requestsInProgress);
         m_msgReceiveTask = receiveTask;
         m_receiver.ProcessRequest(requestStream, m_serverCon);
         // in the mean time, deserialise request notification may have been sent.
         // -> multiple requests are possible in progress and execute the following code
         int receivePending = Interlocked.Exchange(ref m_receivePending, NO_RECEIVE_PENDING);
         Interlocked.Decrement(ref m_requestsInProgress);
         // ReceivePending will be again set to true, when a request has been deserialised
         // and too many requests are processing
         if (receivePending == RECEIVE_PENDING)
         {
             // too many requests in parallel last time when trying to start receive
             // in NotifyDeserialiseRequestComplete -> do it now
             StartReadNextMessage();
         }
     } catch (Exception ex) {
         HandleUnexpectedProcessingException();
         Trace.WriteLine("stopped processing on server connection after unexpected exception: " + ex);
     }
 }