SimpleServerTransportSink.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // System.Runtime.Remoting.Channels.Simple.SimpleServerTransportSink.cs
  3. //
  4. // Author: Dietmar Maurer ([email protected])
  5. //
  6. // 2002 (C) Copyright, Ximian, Inc.
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections;
  29. using System.Runtime.Remoting.Messaging;
  30. using System.Text.RegularExpressions;
  31. using System.Net.Sockets;
  32. using System.Net;
  33. using System.Threading;
  34. using System.IO;
  35. namespace System.Runtime.Remoting.Channels.Simple
  36. {
  37. internal class SimpleServerTransportSink : IServerChannelSink, IChannelSinkBase
  38. {
  39. IServerChannelSink next_sink;
  40. public SimpleServerTransportSink (IServerChannelSink next)
  41. {
  42. next_sink = next;
  43. }
  44. public IServerChannelSink NextChannelSink {
  45. get {
  46. return next_sink;
  47. }
  48. }
  49. [MonoTODO]
  50. public IDictionary Properties {
  51. get {
  52. throw new NotImplementedException ();
  53. }
  54. }
  55. [MonoTODO]
  56. public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
  57. IMessage msg, ITransportHeaders headers, Stream stream)
  58. {
  59. throw new NotImplementedException ();
  60. }
  61. [MonoTODO]
  62. public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack, object state,
  63. IMessage msg, ITransportHeaders headers)
  64. {
  65. throw new NotImplementedException ();
  66. }
  67. public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
  68. IMessage requestMsg,
  69. ITransportHeaders requestHeaders,
  70. Stream requestStream,
  71. out IMessage responseMsg,
  72. out ITransportHeaders responseHeaders,
  73. out Stream responseStream)
  74. {
  75. // this is the first sink, and SimpleServerChannel does not call it.
  76. throw new NotSupportedException ();
  77. }
  78. internal void InternalProcessMessage (Stream network_stream)
  79. {
  80. try {
  81. string uri;
  82. SimpleMessageFormat.MessageType msg_type;
  83. MemoryStream msg_stream;
  84. msg_stream = SimpleMessageFormat.ReceiveMessageStream (network_stream,
  85. out msg_type, out uri);
  86. if (msg_type != SimpleMessageFormat.MessageType.Request)
  87. throw new RemotingException ("received wrong message type");
  88. TransportHeaders headers = new TransportHeaders ();
  89. headers ["_requestUri"] = uri;
  90. IMessage resp_message;
  91. ITransportHeaders resp_headers;
  92. Stream resp_stream;
  93. ServerProcessing res = next_sink.ProcessMessage (null, null, headers, msg_stream,
  94. out resp_message, out resp_headers,
  95. out resp_stream);
  96. switch (res) {
  97. case ServerProcessing.Complete:
  98. Exception e = ((IMethodReturnMessage)resp_message).Exception;
  99. if (e != null) {
  100. // we handle exceptions in the transport channel
  101. SimpleMessageFormat.SendExceptionMessage (network_stream, e.ToString ());
  102. } else {
  103. // send the response
  104. SimpleMessageFormat.SendMessageStream (network_stream,
  105. (MemoryStream)resp_stream,
  106. SimpleMessageFormat.MessageType.Response,
  107. null);
  108. }
  109. break;
  110. case ServerProcessing.Async:
  111. case ServerProcessing.OneWay:
  112. throw new NotImplementedException ();
  113. }
  114. } catch (Exception e) {
  115. SimpleMessageFormat.SendExceptionMessage (network_stream, e.ToString ());
  116. }
  117. }
  118. }
  119. }