private void ReceiveCallback(object state)
        {
            TcpClientSocketHandler  handler = null;
            IClientChannelSinkStack dataArrivedCallbackState = null;

            try
            {
                handler = (TcpClientSocketHandler)state;
                dataArrivedCallbackState = (IClientChannelSinkStack)handler.DataArrivedCallbackState;
                ITransportHeaders headers        = handler.ReadHeaders();
                Stream            responseStream = handler.GetResponseStream();
                dataArrivedCallbackState.AsyncProcessResponse(headers, responseStream);
            }
            catch (Exception exception)
            {
                try
                {
                    if (dataArrivedCallbackState != null)
                    {
                        dataArrivedCallbackState.DispatchException(exception);
                    }
                }
                catch
                {
                }
            }
        }
        private void AsyncFinishedCallback(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = null;

            try
            {
                ITransportHeaders responseHeaders = null;
                Stream            responseStream  = null;
                sinkStack = ((AsyncMessageDelegate)((AsyncResult)ar).AsyncDelegate).EndInvoke(out responseHeaders, out responseStream, ar);
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch (Exception ex)
            {
                try
                {
                    if (sinkStack != null)
                    {
                        sinkStack.DispatchException(ex);
                    }
                    return;
                }
                catch (Exception ex2)
                {
                    Trace.WriteLine(ex2);
                    return;
                }
            }
        }
Exemple #3
0
        /// <summary>call back to call, when the async response has arrived.</summary>
        private void AsyncResponseArrived(IClientChannelSinkStack sinkStack, GiopClientConnection con,
                                          Stream responseStream, Exception resultException)
        {
            ITransportHeaders responseHeaders = new TransportHeaders();

            responseHeaders[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY] = con.Desc; // add to response headers

            // forward the response
            if ((resultException == null) && (responseStream != null))
            {
                #if DEBUG
                OutputHelper.LogStream(responseStream);
                #endif
                responseStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            else
            {
                Exception toThrow = resultException;
                if (toThrow == null)
                {
                    toThrow = new omg.org.CORBA.INTERNAL(79, omg.org.CORBA.CompletionStatus.Completed_MayBe);
                }
                sinkStack.DispatchException(toThrow);
            }
        }
Exemple #4
0
        private void ReadAsyncUnixMessage(object data)
        {
            ITransportHeaders       transportHeader;
            IClientChannelSinkStack clientChannelSinkStack = (IClientChannelSinkStack)data;
            UnixConnection          unixConnection         = (UnixConnection)clientChannelSinkStack.Pop(this);

            try
            {
                if (UnixMessageIO.ReceiveMessageStatus(unixConnection.Stream, unixConnection.Buffer) != MessageStatus.MethodMessage)
                {
                    throw new RemotingException("Unknown response message from server");
                }
                Stream stream = UnixMessageIO.ReceiveMessageStream(unixConnection.Stream, out transportHeader, unixConnection.Buffer);
                unixConnection.Release();
                unixConnection = null;
                clientChannelSinkStack.AsyncProcessResponse(transportHeader, stream);
            }
            catch
            {
                if (unixConnection != null)
                {
                    unixConnection.Release();
                }
                throw;
            }
        }
Exemple #5
0
        } // AsyncProcessRequest

        private void AsyncFinishedCallback(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = null;

            try
            {
                AsyncMessageDelegate d = (AsyncMessageDelegate)(((AsyncResult)ar).AsyncDelegate);
                ITransportHeaders    responseHeaders;
                Stream responseStream;
                sinkStack = d.EndInvoke(out responseHeaders, out responseStream, ar);
                // call down the sink chain
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch (Exception e)
            {
                try
                {
                    if (sinkStack != null)
                    {
                        sinkStack.DispatchException(e);
                    }
                }
                catch
                {
                    // Fatal Error.. ignore
                }
            }
        }
Exemple #6
0
        } // AsyncProcessRequest

        private void OnHttpMessageReturn(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState;

            HttpWebResponse response = null;

            HttpWebRequest httpWebRequest = (HttpWebRequest)sinkStack.Pop(this);

            try
            {
                response = (HttpWebResponse)httpWebRequest.EndGetResponse(ar);
            }
            catch (WebException webException)
            {
                ProcessResponseException(webException, out response);
            }

            // process incoming response
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            ReceiveAndProcess(response, out responseHeaders, out responseStream);

            // call down the sink chain
            sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
        } // OnHttpMessageReturn
Exemple #7
0
        void AsyncProcessResponseCallback(IAsyncResult ar)
        {
            IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState;
            HttpWebRequest          request   = (HttpWebRequest)sinkStack.Pop(this);

            WebResponse response;

            try {
                response = request.EndGetResponse(ar);
            } catch (WebException ex) {
                response = ex.Response;
                //only error 500 is handled by the remoting stack
                HttpWebResponse httpResponse = response as HttpWebResponse;
                if (httpResponse == null || httpResponse.StatusCode != HttpStatusCode.InternalServerError)
                {
                    sinkStack.DispatchException(ex);
                    return;
                }
            }

            //this is only valid after the response is fetched
            SetConnectionLimit(request);

            using (response) {
                Stream            responseStream  = response.GetResponseStream();
                ITransportHeaders responseHeaders = GetHeaders(response);
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
        }
Exemple #8
0
        private void AsyncFinishedCallback(IAsyncResult ar)
        {
            IClientChannelSinkStack stack = null;

            try
            {
                ITransportHeaders headers;
                Stream            stream;
                stack = ((AsyncMessageDelegate)((AsyncResult)ar).AsyncDelegate).EndInvoke(out headers, out stream, ar);
                stack.AsyncProcessResponse(headers, stream);
            }
            catch (Exception exception)
            {
                try
                {
                    if (stack != null)
                    {
                        stack.DispatchException(exception);
                    }
                }
                catch
                {
                }
            }
        }
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
        {
            // add message Uri to headers
            var mcm = (IMethodCallMessage)msg;

            requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri;

            // send data (FIXME: 1) add reliability, 2) handle exceptions)
            var transport = new UdpTransport(UdpClient);

            transport.Write(requestHeaders, requestStream, ServerEndpoint);

            // if the call is not one-way, schedule an async call
            if (!RemotingServices.IsOneWay(mcm.MethodBase))
            {
                ThreadPool.QueueUserWorkItem((s) =>
                {
                    try
                    {
                        ITransportHeaders responseHeaders;
                        Stream responseStream;
                        IPEndPoint remote;
                        transport.Read(out responseHeaders, out responseStream, out remote);
                        sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
                    }
                    catch (Exception ex)
                    {
                        sinkStack.DispatchException(ex);
                    }
                });
            }
        }
Exemple #10
0
        } // SendRequestWithRetry

        private void ReceiveCallback(Object state)
        {
            TcpClientSocketHandler  clientSocket = null;
            IClientChannelSinkStack sinkStack    = null;

            try
            {
                clientSocket = (TcpClientSocketHandler)state;
                sinkStack    = (IClientChannelSinkStack)clientSocket.DataArrivedCallbackState;

                ITransportHeaders responseHeaders = clientSocket.ReadHeaders();
                Stream            responseStream  = clientSocket.GetResponseStream();

                // call down the sink chain
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch (Exception e)
            {
                try
                {
                    if (sinkStack != null)
                    {
                        sinkStack.DispatchException(e);
                    }
                }
                catch (Exception)
                {
                    // Fatal Error.. ignore
                }
            }

            // The client socket will be returned to the cache
            //   when the response stream is closed.
        } // ReceiveCallback
Exemple #11
0
        public void ProcessResponse(IAsyncResult ar)
        {
            Connection connection;
            Exception  exception;
            Message    reply = Manager.EndReadMessage(out connection, out exception, ar);

            IClientChannelSinkStack sinkStack = (IClientChannelSinkStack)ar.AsyncState;

            if (exception != null)
            {
                sinkStack.DispatchException(exception);
            }

            sinkStack.AsyncProcessResponse(reply.Headers, reply.MessageBody);
        }
Exemple #12
0
 void AsyncHandler(IClientChannelSinkStack sinkStack, IpcTransport transport)
 {
     try
     {
         // get the response headers and the response stream from the server
         ITransportHeaders responseHeaders;
         Stream            responseStream;
         transport.Read(out responseHeaders, out responseStream);
         transport.Close();
         sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
     }
     catch (Exception ex)
     {
         sinkStack.DispatchException(ex);
     }
 }
Exemple #13
0
        private void ReceiveCallback(Object state)
        {
            //Console.WriteLine("ReceiveCallback TID {0}", Thread.CurrentThread.GetHashCode());

            PipeConnectionCookie cookie = (PipeConnectionCookie)state;

            PipeConnection          _pipe     = cookie.pipe;
            IClientChannelSinkStack sinkStack = cookie.sinkStack;

            try
            {
                // Read response
                //
                _pipe.BeginReadMessage();

                ITransportHeaders responseHeaders = _pipe.ReadHeaders();
                responseHeaders["__CustomErrorsEnabled"] = false;

                Stream responseStream = _pipe.ReadStream();
                _pipe.EndReadMessage();

                if (_pipeConnectionPool != null)
                {
                    _pipeConnectionPool.ReturnToPool(_pipe);
                }

                _pipe = null;

                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch (Exception e)
            {
                try
                {
                    if (sinkStack != null)
                    {
                        sinkStack.DispatchException(e);
                    }
                }
                catch (Exception)
                {
                    // Fatal Error.. ignore
                }
            }
        } // ReceiveCallback
        private void ReadAsyncTcpMessage(object data)
        {
            // This method is called by a new thread to asynchronously
            // read the response to a request

            // The stack was provided as state data in QueueUserWorkItem
            IClientChannelSinkStack stack = (IClientChannelSinkStack)data;

            // The first sink in the stack is this sink. Pop it and
            // get the status data, which is the TcpConnection used to send
            // the request
            TcpConnection connection = (TcpConnection)stack.Pop(this);

            try
            {
                ITransportHeaders responseHeaders;

                // Read the response, blocking if necessary
                MessageStatus status = TcpMessageIO.ReceiveMessageStatus(connection.Stream, connection.Buffer);

                if (status != MessageStatus.MethodMessage)
                {
                    throw new RemotingException("Unknown response message from server");
                }

                Stream responseStream = TcpMessageIO.ReceiveMessageStream(connection.Stream, out responseHeaders, connection.Buffer);

                // Free the connection, so it can be reused
                connection.Release();
                connection = null;

                // Ok, proceed with the other sinks
                stack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch
            {
                if (connection != null)
                {
                    connection.Release();
                }
                throw;
            }
        }
        private void AsyncSendMessageStream(IClientChannelSinkStack sinkStack,
                                            IMessage msg,
                                            ITransportHeaders requestHeaders,
                                            Stream requestStream)
        {
            IMethodCallMessage mcall = msg as IMethodCallMessage;

            if (_rd == null)
            {
                _rd = _e.ReceiverDispatcher;
            }

            int requestId        = (int)mcall.LogicalCallContext.GetData("__iceRequestId");
            ManualResetEvent mre = null;

            if (requestId != 0)
            {
                mre = _rd.RegisterReplyNotification(requestId);
            }

            lock (_e.Stream) {
                ((MemoryStream)requestStream).WriteTo(_e.Stream);
            }

            // oneway invocation, no response
            if (requestId == 0)
            {
                return;
            }

            mre.WaitOne();
            MemoryStream     responseStream  = _rd.GetMessageStream(requestId);
            TransportHeaders responseHeaders = new TransportHeaders();

            sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
        }
        /// <summary>call back to call, when the async response has arrived.</summary>
        private void AsyncResponseArrived(IClientChannelSinkStack sinkStack, GiopClientConnection con,
                                          Stream responseStream, Exception resultException) {
            ITransportHeaders responseHeaders = new TransportHeaders();
            responseHeaders[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY]= con.Desc; // add to response headers            

            // forward the response
            if ((resultException == null) && (responseStream != null)) {
                #if DEBUG
                OutputHelper.LogStream(responseStream);
                #endif                            
                responseStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter
                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            } else {
                Exception toThrow = resultException;
                if (toThrow == null) {
                    toThrow = new omg.org.CORBA.INTERNAL(79, omg.org.CORBA.CompletionStatus.Completed_MayBe);
                }
                sinkStack.DispatchException(toThrow);
            }                        
        }
Exemple #17
0
        public void AsyncProcessRequest(IClientChannelSinkStack sinkStack, IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
        {
            // add message Uri to headers
            var mcm = (IMethodCallMessage)msg;
            requestHeaders[CommonTransportKeys.RequestUri] = mcm.Uri;

            // send data (FIXME: 1) add reliability, 2) handle exceptions)
            var transport = new UdpTransport(UdpClient);
            transport.Write(requestHeaders, requestStream, ServerEndpoint);

            // if the call is not one-way, schedule an async call
            if (!RemotingServices.IsOneWay(mcm.MethodBase))
            {
                ThreadPool.QueueUserWorkItem((s) =>
                {
                    try
                    {
                        ITransportHeaders responseHeaders;
                        Stream responseStream;
                        IPEndPoint remote;
                        transport.Read(out responseHeaders, out responseStream, out remote);
                        sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
                    }
                    catch (Exception ex)
                    {
                        sinkStack.DispatchException(ex);
                    }
                });
            }
        }
    private void AsyncSendMessageStream (IClientChannelSinkStack sinkStack,
                                         IMessage msg,
                                         ITransportHeaders requestHeaders,
                                         Stream requestStream)
    {
      IMethodCallMessage mcall = msg as IMethodCallMessage;

      if (_rd == null) {
        _rd = _e.ReceiverDispatcher;
      }

      int requestId = (int) mcall.LogicalCallContext.GetData("__iceRequestId");
      ManualResetEvent mre = null;

      if (requestId != 0)
        mre = _rd.RegisterReplyNotification (requestId);

      lock (_e.Stream) {
        ((MemoryStream) requestStream).WriteTo (_e.Stream);
      }

      // oneway invocation, no response
      if (requestId == 0) {
        return;
      }

      mre.WaitOne();
      MemoryStream responseStream = _rd.GetMessageStream (requestId);
      TransportHeaders responseHeaders = new TransportHeaders();

      sinkStack.AsyncProcessResponse (responseHeaders, responseStream);
    }
Exemple #19
0
 void AsyncHandler(IClientChannelSinkStack sinkStack, IpcTransport transport) 
 {
     try 
     {
         // get the response headers and the response stream from the server
         ITransportHeaders responseHeaders;
         Stream responseStream;
         transport.Read(out responseHeaders, out responseStream);
         transport.Close();
         sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
     }
     catch (Exception ex) 
     {
         sinkStack.DispatchException(ex);
     }
 }
Exemple #20
0
 internal void HandleAsyncResponseMsg(ChannelMessage msg)
 {
     _sinkStack.AsyncProcessResponse(msg.Headers, msg.Body);
 }