예제 #1
0
파일: UDP.cs 프로젝트: Paul1nh0/Singularity
 public void PushPacket(Bytes packet)
 {
     DebugPrint("Pushing packet\n");
     using (thisLock.Lock()) {
         byteCount += packet.Length;
         VectorQueueByte incomingPacketQueue = packetContainer.Acquire();
         incomingPacketQueue.AddTail(packet);
         packetContainer.Release(incomingPacketQueue);
     }
 }
예제 #2
0
파일: UDP.cs 프로젝트: Paul1nh0/Singularity
 private static UDP GetUDPSession(ushort port)
 {
     if (UDPInitialized == false)
     {
         return(null);
     }
     using (udpSessionsMtx.Lock()) {
         return(udpSessions[port]);
     }
 }
예제 #3
0
 // Must be balanced with a call to ReleaseIPConnection()!
 internal static IPContract /*.Imp*/ GetIPConnection()
 {
     using (IPSlotLock.Lock()) {
         if (IPSlot == null)
         {
             IPSlot = new TRef(new IPContract());
         }
     }
     return((IPContract)(IPSlot.Acquire()));
 }
예제 #4
0
 // Must be balanced with a call to ReleaseDnsConnection()!
 internal static DNSContract /*.Imp*/ GetDnsConnection()
 {
     using (DnsSlotLock.Lock()) {
         if (DnsSlot == null)
         {
             DnsSlot = new TRef(new DNSContract());
         }
     }
     return((DNSContract)(DnsSlot.Acquire()));
 }
예제 #5
0
        public bool Start()
        {
            using (thisLock.Lock()) {
                if (udp != null)
                {
                    return(false);
                }
                udp = new UDP();
                udp.Bind(IPv4.Any, DhcpFormat.ClientPort);
                udp.Connect(IPv4.Broadcast, DhcpFormat.ServerPort);

                ResetAdapterIPInfo();

                workerDone   = false;
                workerThread = new Thread(this);
                workerThread.Start();
                return(true);
            }
        }
예제 #6
0
 public IDisposable ReadLock()
 {
     return(_monitorLock.Lock());
 }
예제 #7
0
        private void ARPManageThread()
        {
            DebugPrint("ARP managment thread spinning up\n");
            //the pending requests list is ordered by deadline...
            //finding a requests when we rceive a reply is in the worst case O(n)...
            //Hopefully we won't have many oustanding requests, and the first request out
            //will often return first...

            //track two different timeouts here...ARP requests and ARP table aging.
            SchedulerTime ageTableTimeout;
            SchedulerTime now;
            SchedulerTime nextTimer;


            ageTableTimeout = SchedulerTime.Now;
            ageTableTimeout = ageTableTimeout.AddMinutes(5);
            while (true)
            {
                now = SchedulerTime.Now;
                if (now > ageTableTimeout)
                {
                    arpTable.AgeTable();
                    ageTableTimeout = SchedulerTime.Now;
                    ageTableTimeout = ageTableTimeout.AddMinutes(5);
                }
                using (pendingRequestsLock.Lock()) {
                    nextTimer = SchedulerTime.MaxValue;
                    bool done = false;
                    while (!done)
                    {
                        if (pendingRequests.Count == 0)
                        {
                            done = true;
                            continue;
                        }
                        PendingArpRequest pendingArpRequest = (PendingArpRequest)pendingRequests.Peek();
                        if (pendingArpRequest == null)
                        {
                            done = true;
                            continue;
                        }
                        if (pendingArpRequest.requestExpiration > now)
                        {
                            nextTimer = pendingArpRequest.requestExpiration;
                            done      = true;
                            continue;
                        }
                        else
                        {
                            pendingArpRequest = (PendingArpRequest)pendingRequests.Dequeue();
                            if (pendingArpRequest.active == true)
                            {
                                //We need error propagation here...
                                pendingArpRequest.active = false;
                                DebugStub.Assert(false);
                            }
                            pendingRequestsFreelist.Enqueue(pendingArpRequest);
                        }
                    }
                }
                if (ageTableTimeout < nextTimer)
                {
                    DebugPrint("setting nextTimer ageTableTimeout\n");
                    nextTimer = ageTableTimeout;
                }
                bool rc;
                rc = arpHandle.WaitOne(nextTimer);
            }
        }