1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 namespace IceInternal
6 {
7     using System.Net;
8 
9     sealed class TcpConnector : Connector
10     {
connect()11         public Transceiver connect()
12         {
13             return new TcpTransceiver(_instance, new StreamSocket(_instance, _proxy, _addr, _sourceAddr));
14         }
15 
type()16         public short type()
17         {
18             return _instance.type();
19         }
20 
21         //
22         // Only for use by TcpEndpoint
23         //
TcpConnector(ProtocolInstance instance, EndPoint addr, NetworkProxy proxy, EndPoint sourceAddr, int timeout, string connectionId)24         internal TcpConnector(ProtocolInstance instance, EndPoint addr, NetworkProxy proxy, EndPoint sourceAddr,
25                               int timeout, string connectionId)
26         {
27             _instance = instance;
28             _addr = addr;
29             _proxy = proxy;
30             _sourceAddr = sourceAddr;
31             _timeout = timeout;
32             _connectionId = connectionId;
33 
34             _hashCode = 5381;
35             HashUtil.hashAdd(ref _hashCode, _addr);
36             if(_sourceAddr != null)
37             {
38                 HashUtil.hashAdd(ref _hashCode, _sourceAddr);
39             }
40             HashUtil.hashAdd(ref _hashCode, _timeout);
41             HashUtil.hashAdd(ref _hashCode, _connectionId);
42         }
43 
Equals(object obj)44         public override bool Equals(object obj)
45         {
46             if(!(obj is TcpConnector))
47             {
48                 return false;
49             }
50 
51             if(this == obj)
52             {
53                 return true;
54             }
55 
56             TcpConnector p = (TcpConnector)obj;
57             if(_timeout != p._timeout)
58             {
59                 return false;
60             }
61 
62             if(!Network.addressEquals(_sourceAddr, p._sourceAddr))
63             {
64                 return false;
65             }
66 
67             if(!_connectionId.Equals(p._connectionId))
68             {
69                 return false;
70             }
71 
72             return _addr.Equals(p._addr);
73         }
74 
ToString()75         public override string ToString()
76         {
77             return Network.addrToString(_proxy == null ? _addr : _proxy.getAddress());
78         }
79 
GetHashCode()80         public override int GetHashCode()
81         {
82             return _hashCode;
83         }
84 
85         private ProtocolInstance _instance;
86         private EndPoint _addr;
87         private NetworkProxy _proxy;
88         private EndPoint _sourceAddr;
89         private int _timeout;
90         private string _connectionId;
91         private int _hashCode;
92     }
93 }
94