0
|
1 ???using System; |
|
2 using System.IO; |
|
3 using System.Net.Sockets; |
|
4 using UCIS.Net; |
|
5 |
|
6 namespace UCIS.Pml { |
|
7 public class TCPPmlChannel : PassivePmlChannel { |
|
8 private TCPStream _socket; |
|
9 private IPmlRW _rw; |
|
10 private bool _open = false; |
|
11 |
|
12 public TCPPmlChannel(Socket socket) : this(new TCPStream(socket)) { } |
|
13 public TCPPmlChannel(TCPStream socket) { |
|
14 if (socket == null) throw new ArgumentNullException("socket"); |
|
15 _socket = socket; |
|
16 _rw = new PmlBinaryRW(_socket); |
|
17 _open = true; |
|
18 } |
|
19 |
|
20 public override void WriteMessage(PmlElement message) { |
|
21 if (!_open) throw new InvalidOperationException("The channel is not open"); |
|
22 lock (_rw) _rw.WriteMessage(message); |
|
23 } |
|
24 |
|
25 public override void Close() { |
|
26 if (!_open) return; |
|
27 _open = false; |
|
28 if (_socket != null) try { _socket.Close(); } catch { } |
|
29 base.Close(); |
|
30 } |
|
31 |
|
32 public override PmlElement ReadMessage() { |
|
33 return _rw.ReadMessage(); |
|
34 } |
|
35 } |
|
36 } |