Example #1
0
 public static void AddCommand(Command cmd)
 {
     try
     {
         if (cmd is AddSocketCommand)
         {
             AddSocketCommand addSocketCommand  = cmd as AddSocketCommand;
             long             theUniqueSocketId = addSocketCommand.theUniqueSocketId;
             TCPSocketContext tCPSocketContext  = new TCPSocketContext(addSocketCommand.theUniqueSocketId, addSocketCommand.theHandler);
             if (!NetLib.dictSocketContext.ContainsKey(theUniqueSocketId))
             {
                 Logger.DEBUG(theUniqueSocketId.ToString() + " added");
                 NetLib.dictSocketContext.Add(theUniqueSocketId, tCPSocketContext);
             }
             else
             {
                 TCPSocketContext tCPSocketContext2 = NetLib.dictSocketContext.get_Item(theUniqueSocketId);
                 Logger.ERROR("NetThread::ProcessCommands socket handle conflict " + tCPSocketContext.GetUniqueSocketId().ToString() + " VS " + tCPSocketContext2.GetUniqueSocketId().ToString());
             }
         }
         else if (cmd is SendPacketCommand)
         {
             SendPacketCommand sendPacketCommand = cmd as SendPacketCommand;
             long theUniqueSocketId2             = sendPacketCommand.theUniqueSocketId;
             if (NetLib.dictSocketContext.ContainsKey(theUniqueSocketId2))
             {
                 TCPSocketContext tCPSocketContext3 = NetLib.dictSocketContext.get_Item(theUniqueSocketId2);
                 Packet           packet            = new Packet();
                 packet.theCreateTimeMS = sendPacketCommand.theCreateTimeMS;
                 packet.theContent      = (sendPacketCommand.theContent.Clone() as byte[]);
                 tCPSocketContext3.Enqueue(packet);
                 NetLib.pendingPacketsLength += (long)packet.theContent.Length;
             }
         }
         else
         {
             CloseSocketCommand closeSocketCommand = cmd as CloseSocketCommand;
             long theUniqueSocketId3 = closeSocketCommand.theUniqueSocketId;
             if (NetLib.dictSocketContext.ContainsKey(theUniqueSocketId3))
             {
                 TCPSocketContext tCPSocketContext4 = NetLib.dictSocketContext.get_Item(theUniqueSocketId3);
                 Logger.DEBUG(theUniqueSocketId3.ToString() + " removed");
                 int num = 0;
                 tCPSocketContext4.HandleClose(out num);
                 NetLib.pendingPacketsLength -= (long)num;
                 NetLib.dictSocketContext.Remove(theUniqueSocketId3);
                 NetLib.PandoraNet_Close(theUniqueSocketId3);
             }
             else
             {
                 Logger.WARN("uniqueSocketId=" + theUniqueSocketId3.ToString() + " alreay missing");
             }
         }
     }
     catch (Exception ex)
     {
         Logger.ERROR(ex.get_StackTrace());
     }
 }
Example #2
0
        public static void Drive()
        {
            List <long> list  = new List <long>();
            List <long> list2 = new List <long>();

            using (Dictionary <long, TCPSocketContext> .Enumerator enumerator = NetLib.dictSocketContext.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    KeyValuePair <long, TCPSocketContext> current = enumerator.get_Current();
                    list.Add(current.get_Key());
                }
            }
            using (List <long> .Enumerator enumerator2 = list.GetEnumerator())
            {
                while (enumerator2.MoveNext())
                {
                    long current2 = enumerator2.get_Current();
                    if (NetLib.dictSocketContext.ContainsKey(current2))
                    {
                        long             num = current2;
                        TCPSocketContext tCPSocketContext = NetLib.dictSocketContext.get_Item(num);
                        int num2 = NetLib.PandoraNet_DoSelect(num);
                        if (num2 != 0)
                        {
                            if (num2 == 1)
                            {
                                int num3 = tCPSocketContext.HandleInputEvent();
                                if (num3 < 0)
                                {
                                    int num4 = 0;
                                    tCPSocketContext.HandleClose(out num4);
                                    NetLib.pendingPacketsLength -= (long)num4;
                                    list2.Add(num);
                                }
                            }
                            else if (num2 == 2)
                            {
                                int num5 = 0;
                                int num6 = tCPSocketContext.HandleOutputEvent(out num5);
                                NetLib.pendingPacketsLength -= (long)num5;
                                if (num6 < 0)
                                {
                                    int num7 = 0;
                                    tCPSocketContext.HandleClose(out num7);
                                    NetLib.pendingPacketsLength -= (long)num7;
                                    list2.Add(num);
                                }
                            }
                            else
                            {
                                int num8 = 0;
                                tCPSocketContext.HandleClose(out num8);
                                NetLib.pendingPacketsLength -= (long)num8;
                                list2.Add(num);
                            }
                        }
                    }
                }
            }
            using (List <long> .Enumerator enumerator3 = list2.GetEnumerator())
            {
                while (enumerator3.MoveNext())
                {
                    long current3 = enumerator3.get_Current();
                    NetLib.dictSocketContext.Remove(current3);
                    NetLib.PandoraNet_Close(current3);
                }
            }
        }