public TcpConnection(Socket socket, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[]> messageArrivedHandler, Action <ITcpConnection, SocketError> connectionClosedHandler) { socket.CheckNotNull("socket"); setting.CheckNotNull("setting"); receiveDataBufferPool.CheckNotNull("receiveDataBufferPool"); messageArrivedHandler.CheckNotNull("messageArrivedHandler"); connectionClosedHandler.CheckNotNull("connectionClosedHandler"); _socket = socket; _setting = setting; _receiveDataBufferPool = receiveDataBufferPool; _localEndPoint = socket.LocalEndPoint; _remotingEndPoint = socket.RemoteEndPoint; _messageArrivedHandler = messageArrivedHandler; _connectionClosedHandler = connectionClosedHandler; _sendSocketArgs = new SocketAsyncEventArgs(); _sendSocketArgs.AcceptSocket = _socket; _sendSocketArgs.Completed += OnSendAsyncCompleted; _receiveSocketArgs = new SocketAsyncEventArgs(); _receiveSocketArgs.AcceptSocket = socket; _receiveSocketArgs.Completed += OnReceiveAsyncCompleted; _logger = IocManager.Instance.Resolve <ILoggerFactory>().Create(GetType().FullName); _framer = IocManager.Instance.Resolve <IMessageFramer>(); _framer.RegisterMessageArrivedCallback(OnMessageArrived); TryReceive(); TrySend(); }
public ServerSocket(IPEndPoint listeningEndPoint, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[], Action <byte[]> > messageArrivedHandler) { listeningEndPoint.CheckNotNull("listeningEndPoint"); setting.CheckNotNull("setting"); receiveDataBufferPool.CheckNotNull("receiveDataBufferPool"); messageArrivedHandler.CheckNotNull("messageArrivedHandler"); _listeningEndPoint = listeningEndPoint; _setting = setting; _receiveDataBufferPool = receiveDataBufferPool; _connectionEventListeners = new List <IConnectionEventListener>(); _messageArrivedHandler = messageArrivedHandler; _socket = SocketUtils.CreateSocket(_setting.SendBufferSize, _setting.ReceiveBufferSize); _acceptSocketArgs = new SocketAsyncEventArgs(); _acceptSocketArgs.Completed += AcceptCompleted; _logger = IocManager.Instance.Resolve <ILoggerFactory>().Create(GetType().FullName); }
public ClientSocket(EndPoint serverEndPoint, EndPoint localEndPoint, SocketSetting setting, IBufferPool receiveDataBufferPool, Action <ITcpConnection, byte[]> messageArrivedHandler) { serverEndPoint.CheckNotNull("serverEndPoint"); setting.CheckNotNull("setting"); receiveDataBufferPool.CheckNotNull("receiveDataBufferPool"); messageArrivedHandler.CheckNotNull("messageArrivedHandler"); _connectionEventListeners = new List <IConnectionEventListener>(); _serverEndPoint = serverEndPoint; _localEndPoint = localEndPoint; _setting = setting; _receiveDataBufferPool = receiveDataBufferPool; _messageArrivedHandler = messageArrivedHandler; _waitConnectHandle = new ManualResetEvent(false); _socket = SocketUtils.CreateSocket(_setting.SendBufferSize, _setting.ReceiveBufferSize); _logger = IocManager.Instance.Resolve <ILoggerFactory>().Create(GetType().FullName); _flowControlThreshold = _setting.SendMessageFlowControlThreshold; }