Ejemplo n.º 1
0
 private void UpdatePendingRequests(IPv4 ipAddress,
                                    EthernetAddress macAddress)
 {
     using (pendingRequestsLock.Lock()) {
         //Sigh...we're missing a linked list in the current Singularity C# runtime
         foreach (PendingArpRequest pendingRequest in pendingRequests)
         {
             VTable.Assert(pendingRequest != null);
             if (pendingRequest.address == ipAddress)
             {
                 pendingRequest.active = false;
                 DebugStub.WriteLine("found waiting arp request...sending on out");
                 VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire();
                 Bytes           header   = txBuffer.ExtractHead();
                 Bytes           buffer   = txBuffer.ExtractHead();
                 VTable.Assert(header != null);
                 VTable.Assert(buffer != null);
                 pendingRequest.txContainer.Release(txBuffer);
                 //Format ethernet header
                 EthernetHeader.Write(header, pendingRequest.localMac, macAddress, EthernetHeader.PROTOCOL_IP);
                 //send it!
                 VTable.Assert(pendingRequest.adapter != null);
                 pendingRequest.adapter.PopulateTxRing(header, buffer);
                 continue;
             }
         }
     }
 }
Ejemplo n.º 2
0
        public Bytes PopAllPackets()
        {
            Bytes packet;
            int   sizeOfData;
            Bytes buffer;

            if (byteCount <= 0)
            {
                DebugStub.WriteLine("UDP PopAllPackets: no data???\n");
                DebugStub.Break();
                return(null);
            }
            using (thisLock.Lock()) {
                DebugPrint("Popping {0} bytes of data to client\n", byteCount);
                buffer = new Bytes(new byte[byteCount]);

                VectorQueueByte incomingPacketQueue = packetContainer.Acquire();
                int             offset = 0;
                while ((packet = incomingPacketQueue.ExtractHead()) != null)
                {
                    VTable.Assert(packet != null);
                    Bitter.Copy(buffer, offset, packet.Length, packet, 0);
                    offset    += packet.Length;
                    byteCount -= packet.Length;
                    //delete packet;
                }
                packetContainer.Release(incomingPacketQueue);
                DebugStub.Assert(byteCount == 0);
            }
            return(buffer);
        }
Ejemplo n.º 3
0
        public Bytes PopSinglePacket()
        {
            Bytes packet = null;

            using (thisLock.Lock()) {
                VectorQueueByte incomingPacketQueue = packetContainer.Acquire();
                packet = incomingPacketQueue.ExtractHead();
                if (packet != null)
                {
                    byteCount -= packet.Length;
                }
                packetContainer.Release(incomingPacketQueue);
            }
            return(packet);
        }
Ejemplo n.º 4
0
        public void Close()
        {
            //free any remaining messages in the queue
            DebugPrint("Closing udp instance freeing port {0}\n", this.localPort);
            bool rc = this.UpdatePort(0);

            VTable.Assert(rc == true);
            //cleanup any remaining data
            Bytes           packet;
            VectorQueueByte incomingPacketQueue = packetContainer.Acquire();

            while ((packet = incomingPacketQueue.ExtractHead()) != null)
            {
                //delete packet;
            }
            packetContainer.Release(incomingPacketQueue);
        }