| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Diagnostics; |
| | | 4 | | using System.Net; |
| | | 5 | | using System.Net.Sockets; |
| | | 6 | | |
| | | 7 | | namespace Ice.Internal; |
| | | 8 | | |
| | | 9 | | internal sealed class TcpTransceiver : Transceiver |
| | | 10 | | { |
| | 1 | 11 | | public Socket fd() => _stream.fd(); |
| | | 12 | | |
| | | 13 | | public int initialize(Buffer readBuffer, Buffer writeBuffer, ref bool hasMoreData) => |
| | 1 | 14 | | _stream.connect(readBuffer, writeBuffer, ref hasMoreData); |
| | | 15 | | |
| | | 16 | | public int closing(bool initiator, Ice.LocalException ex) => |
| | | 17 | | // If we are initiating the connection closure, wait for the peer |
| | | 18 | | // to close the TCP/IP connection. Otherwise, close immediately. |
| | 1 | 19 | | initiator ? SocketOperation.Read : SocketOperation.None; |
| | | 20 | | |
| | 1 | 21 | | public void close() => _stream.close(); |
| | | 22 | | |
| | | 23 | | public EndpointI bind() |
| | | 24 | | { |
| | | 25 | | Debug.Assert(false); |
| | 0 | 26 | | return null; |
| | | 27 | | } |
| | | 28 | | |
| | 1 | 29 | | public void destroy() => _stream.destroy(); |
| | | 30 | | |
| | 1 | 31 | | public int write(Buffer buf) => _stream.write(buf); |
| | | 32 | | |
| | 1 | 33 | | public int read(Buffer buf, ref bool hasMoreData) => _stream.read(buf); |
| | | 34 | | |
| | 1 | 35 | | public bool startRead(Buffer buf, AsyncCallback callback, object state) => _stream.startRead(buf, callback, state); |
| | | 36 | | |
| | 1 | 37 | | public void finishRead(Buffer buf) => _stream.finishRead(buf); |
| | | 38 | | |
| | | 39 | | public bool startWrite(Buffer buf, AsyncCallback callback, object state, out bool messageWritten) => |
| | 1 | 40 | | _stream.startWrite(buf, callback, state, out messageWritten); |
| | | 41 | | |
| | 1 | 42 | | public void finishWrite(Buffer buf) => _stream.finishWrite(buf); |
| | | 43 | | |
| | 1 | 44 | | public string protocol() => _instance.protocol(); |
| | | 45 | | |
| | | 46 | | public ConnectionInfo getInfo(bool incoming, string adapterName, string connectionId) |
| | | 47 | | { |
| | 1 | 48 | | if (_stream.fd() is null) |
| | | 49 | | { |
| | 1 | 50 | | return new TCPConnectionInfo(incoming, adapterName, connectionId); |
| | | 51 | | } |
| | | 52 | | else |
| | | 53 | | { |
| | 1 | 54 | | EndPoint localEndpoint = Network.getLocalAddress(_stream.fd()); |
| | 1 | 55 | | EndPoint remoteEndpoint = Network.getRemoteAddress(_stream.fd()); |
| | | 56 | | |
| | 1 | 57 | | return new TCPConnectionInfo( |
| | 1 | 58 | | incoming, |
| | 1 | 59 | | adapterName, |
| | 1 | 60 | | connectionId, |
| | 1 | 61 | | Network.endpointAddressToString(localEndpoint), |
| | 1 | 62 | | Network.endpointPort(localEndpoint), |
| | 1 | 63 | | Network.endpointAddressToString(remoteEndpoint), |
| | 1 | 64 | | Network.endpointPort(remoteEndpoint), |
| | 1 | 65 | | Network.getRecvBufferSize(_stream.fd()), |
| | 1 | 66 | | Network.getSendBufferSize(_stream.fd())); |
| | | 67 | | } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public void checkSendSize(Buffer buf) |
| | | 71 | | { |
| | 1 | 72 | | } |
| | | 73 | | |
| | 1 | 74 | | public void setBufferSize(int rcvSize, int sndSize) => _stream.setBufferSize(rcvSize, sndSize); |
| | | 75 | | |
| | 1 | 76 | | public override string ToString() => _stream.ToString(); |
| | | 77 | | |
| | 0 | 78 | | public string toDetailedString() => ToString(); |
| | | 79 | | |
| | | 80 | | // |
| | | 81 | | // Only for use by TcpConnector, TcpAcceptor |
| | | 82 | | // |
| | 1 | 83 | | internal TcpTransceiver(ProtocolInstance instance, StreamSocket stream) |
| | | 84 | | { |
| | 1 | 85 | | _instance = instance; |
| | 1 | 86 | | _stream = stream; |
| | 1 | 87 | | } |
| | | 88 | | |
| | | 89 | | private readonly ProtocolInstance _instance; |
| | | 90 | | private readonly StreamSocket _stream; |
| | | 91 | | } |