SimpleClientChannel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // System.Runtime.Remoting.Channels.Simple.SimpleClientChannel.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.IO;
  30. using System.Net.Sockets;
  31. using System.Runtime.Remoting.Messaging;
  32. using System.Runtime.Remoting.Channels;
  33. namespace System.Runtime.Remoting.Channels.Simple
  34. {
  35. public class SimpleClientChannel : IChannelSender, IChannel
  36. {
  37. int priority = 1;
  38. string name = "simple";
  39. IClientChannelSinkProvider sink_provider;
  40. public SimpleClientChannel ()
  41. {
  42. sink_provider = new SimpleClientFormatterSinkProvider ();
  43. sink_provider.Next = new SimpleClientTransportSinkProvider ();
  44. }
  45. public SimpleClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
  46. {
  47. priority = 1;
  48. sink_provider = sinkProvider;
  49. // add the tcp provider at the end of the chain
  50. IClientChannelSinkProvider prov = sinkProvider;
  51. while (prov.Next != null) prov = prov.Next;
  52. prov.Next = new SimpleClientTransportSinkProvider ();
  53. }
  54. public SimpleClientChannel (string name, IClientChannelSinkProvider sinkProvider)
  55. {
  56. priority = 1;
  57. this.name = name;
  58. sink_provider = sinkProvider;
  59. // add the tcp provider at the end of the chain
  60. IClientChannelSinkProvider prov = sinkProvider;
  61. while (prov.Next != null) prov = prov.Next;
  62. prov.Next = new SimpleClientTransportSinkProvider ();
  63. }
  64. public string ChannelName
  65. {
  66. get {
  67. return name;
  68. }
  69. }
  70. public int ChannelPriority
  71. {
  72. get {
  73. return priority;
  74. }
  75. }
  76. public IMessageSink CreateMessageSink (string url,
  77. object remoteChannelData,
  78. out string objectURI)
  79. {
  80. objectURI = null;
  81. if (url != null) {
  82. if (Parse (url, out objectURI) != null)
  83. return (IMessageSink) sink_provider.CreateSink (this, url,
  84. remoteChannelData);
  85. }
  86. if (remoteChannelData != null) {
  87. IChannelDataStore ds = remoteChannelData as IChannelDataStore;
  88. if (ds != null) {
  89. foreach (string chnl_uri in ds.ChannelUris) {
  90. if (Parse (chnl_uri, out objectURI) == null)
  91. continue;
  92. return (IMessageSink) sink_provider.CreateSink (this, chnl_uri,
  93. remoteChannelData);
  94. }
  95. }
  96. }
  97. return null;
  98. }
  99. public string Parse (string url, out string objectURI)
  100. {
  101. int port;
  102. string host = SimpleChannel.ParseSimpleURL (url, out objectURI, out port);
  103. return "simple://" + host + ":" + port;
  104. }
  105. }
  106. }