public void Add(AsyncSocketUserToken userToken) { lock(m_list) { m_list.Add(userToken); } }
public void Remove(AsyncSocketUserToken userToken) { lock (m_list) { m_list.Remove(userToken); } }
public BaseSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_userName = ""; m_logined = false; m_socketFlag = ""; }
public void CopyList(ref AsyncSocketUserToken[] array) { lock (m_list) { array = new AsyncSocketUserToken[m_list.Count]; m_list.CopyTo(array); } }
public UploadSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "Upload"; m_fileName = ""; m_fileStream = null; lock (m_asyncSocketServer.UploadSocketProtocolMgr) { m_asyncSocketServer.UploadSocketProtocolMgr.Add(this); } }
public void Push(AsyncSocketUserToken item) { if (item == null) { throw new ArgumentException("Items added to a AsyncSocketUserToken cannot be null"); } lock (m_pool) { m_pool.Push(item); } }
public void Init() { AsyncSocketUserToken userToken; for (int i = 0; i < m_numConnections; i++) //按照连接数建立读写对象 { userToken = new AsyncSocketUserToken(m_receiveBufferSize); userToken.ReceiveEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(IO_Completed); userToken.SendEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(IO_Completed); m_asyncSocketUserTokenPool.Push(userToken); } }
public LogOutputSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "LogOutput"; m_logFixedBuffer = new LogFixedBuffer(); lock (Program.AsyncSocketSvr.LogOutputSocketProtocolMgr) { Program.AsyncSocketSvr.LogOutputSocketProtocolMgr.Add(this); } SendResponse(); }
public DownloadSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "Download"; m_fileName = ""; m_fileStream = null; m_sendFile = false; m_packetSize = 64 * 1024; lock (m_asyncSocketServer.DownloadSocketProtocolMgr) { m_asyncSocketServer.DownloadSocketProtocolMgr.Add(this); } }
public AsyncSocketInvokeElement(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) { m_asyncSocketServer = asyncSocketServer; m_asyncSocketUserToken = asyncSocketUserToken; m_netByteOrder = false; m_incomingDataParser = new IncomingDataParser(); m_outgoingDataAssembler = new OutgoingDataAssembler(); m_sendAsync = false; m_connectDT = DateTime.UtcNow; m_activeDT = DateTime.UtcNow; }
public RemoteStreamSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "RemoteStream"; m_fileStream = null; }
public ThroughputSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "Throughput"; }
public void CloseClientSocket(AsyncSocketUserToken userToken) { if (userToken.ConnectSocket == null) return; string socketInfo = string.Format("Local Address: {0} Remote Address: {1}", userToken.ConnectSocket.LocalEndPoint, userToken.ConnectSocket.RemoteEndPoint); Program.Logger.InfoFormat("Client connection disconnected. {0}", socketInfo); try { userToken.ConnectSocket.Shutdown(SocketShutdown.Both); } catch (Exception E) { Program.Logger.ErrorFormat("CloseClientSocket Disconnect client {0} error, message: {1}", socketInfo, E.Message); } userToken.ConnectSocket.Close(); userToken.ConnectSocket = null; //释放引用,并清理缓存,包括释放协议对象等资源 m_maxNumberAcceptedClients.Release(); m_asyncSocketUserTokenPool.Push(userToken); m_asyncSocketUserTokenList.Remove(userToken); }
private void BuildingSocketInvokeElement(AsyncSocketUserToken userToken) { byte flag = userToken.ReceiveEventArgs.Buffer[userToken.ReceiveEventArgs.Offset]; if (flag == (byte)SocketFlag.Upload) userToken.AsyncSocketInvokeElement = new UploadSocketProtocol(this, userToken); else if (flag == (byte)SocketFlag.Download) userToken.AsyncSocketInvokeElement = new DownloadSocketProtocol(this, userToken); else if (flag == (byte)SocketFlag.RemoteStream) userToken.AsyncSocketInvokeElement = new RemoteStreamSocketProtocol(this, userToken); else if (flag == (byte)SocketFlag.Throughput) userToken.AsyncSocketInvokeElement = new ThroughputSocketProtocol(this, userToken); else if (flag == (byte)SocketFlag.Control) userToken.AsyncSocketInvokeElement = new ControlSocketProtocol(this, userToken); else if (flag == (byte)SocketFlag.LogOutput) userToken.AsyncSocketInvokeElement = new LogOutputSocketProtocol(this, userToken); if (userToken.AsyncSocketInvokeElement != null) { Program.Logger.InfoFormat("Building socket invoke element {0}.Local Address: {1}, Remote Address: {2}", userToken.AsyncSocketInvokeElement, userToken.ConnectSocket.LocalEndPoint, userToken.ConnectSocket.RemoteEndPoint); } }
public ControlSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken) : base(asyncSocketServer, asyncSocketUserToken) { m_socketFlag = "Control"; }