コード例 #1
0
        // 处理插入和更新请求
        public static void RecvInsertAndUpdate(SocketAsyncEventArgs e, Packet fp, ref bool IsSend)
        {
            AsyncUserToken      token = (AsyncUserToken)e.UserToken;
            QueryPacketProParam param = new QueryPacketProParam();

            token.Param      = param;
            param.ActionCode = fp.ActionCode;
            int nResult = DBMgr.Instance.QueryNoRet(((PacketInsertORUpdate)fp).strSql);

            PacketInsertORUpdateAck ack = new PacketInsertORUpdateAck();

            ack.CreatePIUAckPacket(nResult);
            fp.PacketToBuf(e.Buffer, e.Offset);
            e.SetBuffer(e.Offset, ack.GetPacketLen());
        }
コード例 #2
0
        // 处理查询请求
        public static void RecvLocation(SocketAsyncEventArgs e, Packet fp, ref bool IsSend)
        {
            AsyncUserToken      token = (AsyncUserToken)e.UserToken;
            QueryPacketProParam param = new QueryPacketProParam();

            token.Param      = param;
            param.ActionCode = fp.ActionCode;
            param.dt         = DBMgr.Instance.Query(((PacketQuery)fp).strSql);

            PacketQueryAck ack = new PacketQueryAck();

            ack.CreatePQAckPacket(param.dt.ColCount, param.dt.RowCount, param.dt.ColNames);
            fp.PacketToBuf(e.Buffer, e.Offset);
            param.SendType = 0;
            e.SetBuffer(e.Offset, ack.GetPacketLen());
        }
コード例 #3
0
        private void CloseClientSocket(SocketAsyncEventArgs e)
        {
            AsyncUserToken token = e.UserToken as AsyncUserToken;

            token.Param = null;

            // close the socket associated with the client
            try
            {
                token.Socket.Shutdown(SocketShutdown.Send);
            }
            // throws if client process has already closed
            catch (Exception) { }
            token.Socket.Close();

            // decrement the counter keeping track of the total number of clients connected to the server
            Interlocked.Decrement(ref m_numConnectedSockets);
            m_maxNumberAcceptedClients.Release();
            //Console.WriteLine("A client has been disconnected from the server. There are {0} clients connected to the server", m_numConnectedSockets);

            // Free the SocketAsyncEventArg so they can be reused by another client
            m_readWritePool.Push(e);
        }