TcpServerTransportSink.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // System.Runtime.Remoting.Channels.Tcp.TcpServerTransportSink.cs
  3. //
  4. // Author: Rodrigo Moya ([email protected])
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // 2002 (C) Copyright, Ximian, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.Runtime.Remoting.Messaging;
  32. using System.IO;
  33. namespace System.Runtime.Remoting.Channels.Tcp
  34. {
  35. internal class TcpServerTransportSink : IServerChannelSink, IChannelSinkBase
  36. {
  37. IServerChannelSink next_sink;
  38. public TcpServerTransportSink (IServerChannelSink next)
  39. {
  40. next_sink = next;
  41. }
  42. public IServerChannelSink NextChannelSink
  43. {
  44. get
  45. {
  46. return next_sink;
  47. }
  48. }
  49. public IDictionary Properties
  50. {
  51. get
  52. {
  53. if (next_sink != null) return next_sink.Properties;
  54. else return null;
  55. }
  56. }
  57. public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
  58. IMessage msg, ITransportHeaders headers, Stream responseStream)
  59. {
  60. ClientConnection connection = (ClientConnection)state;
  61. TcpMessageIO.SendMessageStream (connection.Stream, responseStream, headers, connection.Buffer);
  62. }
  63. public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack, object state,
  64. IMessage msg, ITransportHeaders headers)
  65. {
  66. return null;
  67. }
  68. public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
  69. IMessage requestMsg,
  70. ITransportHeaders requestHeaders,
  71. Stream requestStream,
  72. out IMessage responseMsg,
  73. out ITransportHeaders responseHeaders,
  74. out Stream responseStream)
  75. {
  76. // this is the first sink, and TcpServerChannel does not call it.
  77. throw new NotSupportedException ();
  78. }
  79. internal void InternalProcessMessage (ClientConnection connection)
  80. {
  81. // Reads the headers and the request stream
  82. Stream requestStream;
  83. ITransportHeaders requestHeaders;
  84. requestStream = TcpMessageIO.ReceiveMessageStream (connection.Stream, out requestHeaders, connection.Buffer);
  85. // Pushes the connection object together with the sink. This information
  86. // will be used for sending the response in an async call.
  87. ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();
  88. sinkStack.Push(this, connection);
  89. ITransportHeaders responseHeaders;
  90. Stream responseStream;
  91. IMessage responseMsg;
  92. ServerProcessing proc = next_sink.ProcessMessage(sinkStack, null, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);
  93. switch (proc)
  94. {
  95. case ServerProcessing.Complete:
  96. TcpMessageIO.SendMessageStream (connection.Stream, responseStream, responseHeaders, connection.Buffer);
  97. break;
  98. case ServerProcessing.Async:
  99. case ServerProcessing.OneWay:
  100. break;
  101. }
  102. }
  103. }
  104. }