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