Exemplo n.º 1
0
        public void ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            UnixConnection connection = null;

            try
            {
                if (requestHeaders == null)
                {
                    requestHeaders = new TransportHeaders();
                }
                requestHeaders["__RequestUri"] = ((IMethodMessage)msg).Uri;
                connection = UnixConnectionPool.GetConnection(this._path);
                UnixMessageIO.SendMessageStream(connection.Stream, requestStream, requestHeaders, connection.Buffer);
                connection.Stream.Flush();
                if (UnixMessageIO.ReceiveMessageStatus(connection.Stream, connection.Buffer) != MessageStatus.MethodMessage)
                {
                    throw new RemotingException("Unknown response message from server");
                }
                responseStream = UnixMessageIO.ReceiveMessageStream(connection.Stream, out responseHeaders, connection.Buffer);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Release();
                }
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        private void ReadAsyncUnixMessage(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 UnixConnection used to send
            // the request
            UnixConnection connection = (UnixConnection)stack.Pop(this);

            try
            {
                ITransportHeaders responseHeaders;

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

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

                Stream responseStream = UnixMessageIO.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;
            }
        }
        internal void InternalProcessMessage(ClientConnection connection, Stream stream)
        {
            ITransportHeaders      transportHeader;
            ITransportHeaders      transportHeader1;
            Stream                 stream1;
            IMessage               message;
            Stream                 stream2 = UnixMessageIO.ReceiveMessageStream(stream, out transportHeader, connection.Buffer);
            ServerChannelSinkStack serverChannelSinkStack = new ServerChannelSinkStack();

            serverChannelSinkStack.Push(this, connection);
            switch (this.next_sink.ProcessMessage(serverChannelSinkStack, null, transportHeader, stream2, out message, out transportHeader1, out stream1))
            {
            case ServerProcessing.Complete:
            {
                UnixMessageIO.SendMessageStream(stream, stream1, transportHeader1, connection.Buffer);
                stream.Flush();
                break;
            }
            }
        }
Exemplo n.º 5
0
        internal void InternalProcessMessage(ClientConnection connection, Stream stream)
        {
            // Reads the headers and the request stream

            Stream            requestStream;
            ITransportHeaders requestHeaders;

            requestStream = UnixMessageIO.ReceiveMessageStream(stream, out requestHeaders, connection.Buffer);

/*            try {
 *            PeerCred cred = connection.Client.PeerCredential;
 *            requestHeaders["__uid"] = cred.UserID;
 *            } catch (Exception e) {
 *            Console.WriteLine ("Couldn't get the peer cred: " + e);
 *            }
 */
            // Pushes the connection object together with the sink. This information
            // will be used for sending the response in an async call.

            ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();

            sinkStack.Push(this, connection);

            ITransportHeaders responseHeaders;
            Stream            responseStream;
            IMessage          responseMsg;

            ServerProcessing proc = next_sink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);

            switch (proc)
            {
            case ServerProcessing.Complete:
                UnixMessageIO.SendMessageStream(stream, responseStream, responseHeaders, connection.Buffer);
                stream.Flush();
                break;

            case ServerProcessing.Async:
            case ServerProcessing.OneWay:
                break;
            }
        }