ClientChannelSinkStack.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // System.Runtime.Remoting.Channels.ClientChannelSinkStack.cs
  3. //
  4. // Author: Rodrigo Moya ([email protected])
  5. // Lluis Sanchez ([email protected])
  6. //
  7. // 2002 (C) Copyright, Ximian, Inc.
  8. //
  9. using System.IO;
  10. using System.Runtime.Remoting.Messaging;
  11. namespace System.Runtime.Remoting.Channels
  12. {
  13. public class ClientChannelSinkStack : IClientChannelSinkStack, IClientResponseChannelSinkStack
  14. {
  15. // The sink where to send the result of the async call
  16. private IMessageSink _replySink = null;
  17. // The stack. It is a chain of ChanelSinkStackEntry.
  18. ChanelSinkStackEntry _sinkStack = null;
  19. public ClientChannelSinkStack (IMessageSink sink)
  20. {
  21. _replySink = sink;
  22. }
  23. public void AsyncProcessResponse (ITransportHeaders headers, Stream stream)
  24. {
  25. if (_sinkStack == null) throw new RemotingException ("The current sink stack is empty");
  26. ChanelSinkStackEntry stackEntry = _sinkStack;
  27. _sinkStack = _sinkStack.Next;
  28. ((IClientChannelSink)stackEntry.Sink).AsyncProcessResponse (this, stackEntry.State, headers, stream);
  29. // Do not call AsyncProcessResponse for each sink in the stack.
  30. // The sink must recursively call IClientChannelSinkStack.AsyncProcessResponse
  31. // after its own processing
  32. }
  33. [MonoTODO]
  34. public void DispatchException (Exception e)
  35. {
  36. throw new NotImplementedException ();
  37. }
  38. public void DispatchReplyMessage (IMessage msg)
  39. {
  40. if (_replySink != null) _replySink.SyncProcessMessage(msg);
  41. }
  42. public object Pop (IClientChannelSink sink)
  43. {
  44. // Pops until the sink is found
  45. while (_sinkStack != null)
  46. {
  47. ChanelSinkStackEntry stackEntry = _sinkStack;
  48. _sinkStack = _sinkStack.Next;
  49. if (stackEntry.Sink == sink) return stackEntry.State;
  50. }
  51. throw new RemotingException ("The current sink stack is empty, or the specified sink was never pushed onto the current stack");
  52. }
  53. public void Push (IClientChannelSink sink, object state)
  54. {
  55. _sinkStack = new ChanelSinkStackEntry (sink, state, _sinkStack);
  56. }
  57. }
  58. }