public void Add(AsyncSocketUserToken userToken)
 {
     lock(m_list)
     {
         m_list.Add(userToken);
     }
 }
 public void Remove(AsyncSocketUserToken userToken)
 {
     lock (m_list)
     {
         m_list.Remove(userToken);
     }
 }
예제 #3
0
 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);
     }
 }
예제 #5
0
 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);
     }
 }
예제 #7
0
 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);
     }
 }
예제 #8
0
        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();
        }
예제 #9
0
 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);
     }
 }
예제 #10
0
        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;
 }
예제 #12
0
 public ThroughputSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken)
     : base(asyncSocketServer, asyncSocketUserToken)
 {
     m_socketFlag = "Throughput";
 }
예제 #13
0
        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);
        }
예제 #14
0
 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);
     } 
 }
예제 #15
0
 public ControlSocketProtocol(AsyncSocketServer asyncSocketServer, AsyncSocketUserToken asyncSocketUserToken)
     : base(asyncSocketServer, asyncSocketUserToken)
 {
     m_socketFlag = "Control";
 }