2 // System.Runtime.Remoting.Channels.CORBA.CORBAServerChannel.cs
4 // Author: Dietmar Maurer (dietmar@ximian.com)
6 // 2002 (C) Copyright, Ximian, Inc.
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using System
.Collections
;
31 using System
.Runtime
.Remoting
.Messaging
;
32 using System
.Text
.RegularExpressions
;
33 using System
.Net
.Sockets
;
35 using System
.Threading
;
38 namespace System
.Runtime
.Remoting
.Channels
.CORBA
40 public class CORBAServerChannel
: IChannelReceiver
, IChannel
43 string name
= "simple";
46 Thread server_thread
= null;
48 CORBAServerTransportSink sink
;
49 ChannelDataStore channel_data
;
51 void Init (IServerChannelSinkProvider provider
) {
52 if (provider
== null) {
53 provider
= new CORBAServerFormatterSinkProvider ();
56 IServerChannelSink next_sink
= ChannelServices
.CreateServerChannelSinkChain (provider
, this);
58 host
= Dns
.GetHostByName(Dns
.GetHostName()).HostName
;
60 string [] uris
= null;
63 uris
= new String
[1];
64 uris
[0] = GetChannelUri ();
67 channel_data
= new ChannelDataStore (uris
);;
69 sink
= new CORBAServerTransportSink (next_sink
);
71 listener
= new TcpListener (port
);
72 StartListening (null);
75 public CORBAServerChannel (int port
)
81 public CORBAServerChannel (IDictionary properties
,
82 IServerChannelSinkProvider serverSinkProvider
)
84 port
= (int)properties
["port"];
85 Init (serverSinkProvider
);
88 public CORBAServerChannel (string name
, int port
,
89 IServerChannelSinkProvider serverSinkProvider
)
93 Init (serverSinkProvider
);
96 public CORBAServerChannel (string name
, int port
)
103 public object ChannelData
110 public string ChannelName
117 public int ChannelPriority
124 string GetChannelUri ()
126 return "corba://" + host
+ ":" + port
;
129 public string[] GetUrlsForUri (string uri
)
131 string [] chnl_uris
= channel_data
.ChannelUris
;
133 if (uri
.IndexOf ('/') != 0)
136 string [] result
= new String
[chnl_uris
.Length
];
138 for (int i
= 0; i
< chnl_uris
.Length
; i
++) {
139 result
[i
] = chnl_uris
[i
] + uri
;
145 public string Parse (string url
, out string objectURI
)
149 string host
= CORBAChannel
.ParseCORBAURL (url
, out objectURI
, out port
);
151 return GetChannelUri ();
154 void WaitForConnections ()
157 TcpClient client
= listener
.AcceptTcpClient ();
159 sink
.InternalProcessMessage (client
.GetStream ());
165 public void StartListening (object data
)
167 if (server_thread
== null) {
170 port
= ((IPEndPoint
)listener
.LocalEndpoint
).Port
;
171 channel_data
.ChannelUris
= new String
[1];
172 channel_data
.ChannelUris
[0] = GetChannelUri ();
175 server_thread
= new Thread (new ThreadStart (WaitForConnections
));
176 server_thread
.Start ();
180 public void StopListening (object data
)
182 if (server_thread
!= null) {
183 server_thread
.Abort ();
184 server_thread
= null;