public ClientSocket(string name, EndPoint serverEndPoint, FregataOptions fregataOptions, IBufferPool receivedBufferPool, IBufferPool sendBufferPool, ITcpConnectionHandler tcpConnectionHandler) { Id = SnowflakeId.Default().NextId(); Name = name ?? throw new ArgumentNullException(nameof(name)); ServerEndPoint = serverEndPoint ?? throw new ArgumentNullException(nameof(serverEndPoint)); Setting = fregataOptions ?? throw new ArgumentNullException(nameof(fregataOptions)); _receivedBufferPool = receivedBufferPool ?? throw new ArgumentNullException(nameof(receivedBufferPool)); _sendBufferPool = sendBufferPool ?? throw new ArgumentNullException(nameof(sendBufferPool)); _waitConnectHandle = new ManualResetEvent(false); Socket = SocketUtil.CreateSocket(serverEndPoint, fregataOptions.SendMaxSize, fregataOptions.ReceiveMaxSize); _tcpConnectionHandler = tcpConnectionHandler; _tcpConnectionEventListeners = new List <ITcpConnectionEventListener>(); }
public TcpConnection(string name, Socket socket, FregataOptions fregataOptions, IBufferPool receivedBufferPool, IBufferPool sendBufferPool, ITcpConnectionHandler tcpConnectionHandler) { Id = SnowflakeId.Default().NextId(); Name = name; Socket = socket; LocalEndPoint = socket.LocalEndPoint; RemotingEndPoint = socket.RemoteEndPoint; Setting = fregataOptions; _tcpConnectionEventListeners = new List <ITcpConnectionEventListener>(); _tcpConnectionHandler = tcpConnectionHandler; _messageFramer = new LengthPrefixMessageFramer(Setting); _messageFramer.RegisterMessageArrivedCallback(OnMessageArrived); _receiveBuufferPipeline = new BufferPipeline(bufferPool: receivedBufferPool, littelEndian: fregataOptions.LittleEndian, coding: fregataOptions.Encode, writerFlushCompleted: null); _sendBuufferPipeline = new BufferPipeline(bufferPool: sendBufferPool, littelEndian: fregataOptions.LittleEndian, coding: fregataOptions.Encode, writerFlushCompleted: null); Task.Run(() => TryReceiveAsync()); }