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; } } } }
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); }
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); } }
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); }
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); }
private AutoResetEvent AddPendingRequest(IPv4 address, TimeSpan timeout, EthernetAddress localMac, Bytes header, Bytes buffer, IAdapter adapter ) { PendingArpRequest pendingRequest = (PendingArpRequest)pendingRequestsFreelist.Dequeue(); VTable.Assert(pendingRequest != null); pendingRequest.address = address; pendingRequest.active = true; pendingRequest.localMac = localMac; pendingRequest.adapter = adapter; VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire(); txBuffer.AddTail(header); txBuffer.AddTail(buffer); pendingRequest.txContainer.Release(txBuffer); using (pendingRequestsLock.Lock()) { pendingRequests.Enqueue(pendingRequest); } SchedulerTime expiration = SchedulerTime.Now; expiration = expiration.Add(timeout); pendingRequest.requestExpiration = expiration; //poke the wait thread if (pendingRequests.Count == 1) { arpHandle.Set(); } return(pendingRequest.requestEvent); }
public void Release(VectorQueueByte v) { o = v; thisLock.Release(); }
public TContainerVectorQueueByte(VectorQueueByte o) { VTable.Assert(o != null); this.o = o; }