2007-04-02 Chris Toshok <toshok@ximian.com>
[mcs.git] / class / Mono.Posix / Mono.Remoting.Channels.Unix / UnixServerTransportSink.cs
blob5a709ec8645884fccf8bde65d9059eff6f5a81e2
1 //
2 // Mono.Remoting.Channels.Unix.UnixServerTransportSink.cs
3 //
4 // Author: Rodrigo Moya (rodrigo@ximian.com)
5 // Lluis Sanchez Gual (lsg@ctv.es)
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Net.Sockets;
33 using System.Collections;
34 using System.Runtime.Remoting.Messaging;
35 using System.IO;
36 using System.Runtime.Remoting.Channels;
37 using Mono.Posix;
39 namespace Mono.Remoting.Channels.Unix
41 internal class UnixServerTransportSink : IServerChannelSink, IChannelSinkBase
43 IServerChannelSink next_sink;
45 public UnixServerTransportSink (IServerChannelSink next)
47 next_sink = next;
50 public IServerChannelSink NextChannelSink
52 get
54 return next_sink;
58 public IDictionary Properties
60 get
62 if (next_sink != null) return next_sink.Properties;
63 else return null;
67 public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
68 IMessage msg, ITransportHeaders headers, Stream responseStream)
70 ClientConnection connection = (ClientConnection)state;
71 NetworkStream stream = new NetworkStream (connection.Client);
72 UnixMessageIO.SendMessageStream (stream, responseStream, headers, connection.Buffer);
73 stream.Flush ();
74 stream.Close ();
77 public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack, object state,
78 IMessage msg, ITransportHeaders headers)
80 return null;
83 public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
84 IMessage requestMsg,
85 ITransportHeaders requestHeaders,
86 Stream requestStream,
87 out IMessage responseMsg,
88 out ITransportHeaders responseHeaders,
89 out Stream responseStream)
91 // this is the first sink, and UnixServerChannel does not call it.
92 throw new NotSupportedException ();
95 internal void InternalProcessMessage (ClientConnection connection, Stream stream)
97 // Reads the headers and the request stream
99 Stream requestStream;
100 ITransportHeaders requestHeaders;
102 requestStream = UnixMessageIO.ReceiveMessageStream (stream, out requestHeaders, connection.Buffer);
104 /* try {
105 PeerCred cred = connection.Client.PeerCredential;
106 requestHeaders["__uid"] = cred.UserID;
107 } catch (Exception e) {
108 Console.WriteLine ("Couldn't get the peer cred: " + e);
111 // Pushes the connection object together with the sink. This information
112 // will be used for sending the response in an async call.
114 ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();
115 sinkStack.Push(this, connection);
117 ITransportHeaders responseHeaders;
118 Stream responseStream;
119 IMessage responseMsg;
121 ServerProcessing proc = next_sink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);
123 switch (proc)
125 case ServerProcessing.Complete:
126 UnixMessageIO.SendMessageStream (stream, responseStream, responseHeaders, connection.Buffer);
127 stream.Flush ();
128 break;
130 case ServerProcessing.Async:
131 case ServerProcessing.OneWay:
132 break;