예제 #1
0
파일: Nic.cs 프로젝트: Paul1nh0/Singularity
        private void TxExchange()
        {
            int toCount   = 0;
            int fromCount = 0;

            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                PacketFifo src  = this.txFifo.Acquire();
                PacketFifo free = this.txFreeFifo.Acquire();

                toCount = src.Count;
                try {
                    src = imp.GiveTxPacketsToDevice(src);

                    fromCount = src.Count;
                    free.Push(src);
                }
                finally {
                    this.txFreeFifo.Release(free);
                    this.txFifo.Release(src);
                }
            }
            catch (Exception e) {
                DebugStub.Print("TxExchange FAILED arg {0}\n", DebugStub.ArgList(e.ToString()));
                DebugStub.Break();
            }
            finally {
                nicChannel.Release(imp);
            }
            DebugPrint("TxExchange out: {0} in: {1}\n",
                       toCount, fromCount);
        }
예제 #2
0
        // Copy data out into a supplied buffer. If fPeek is true, it means we
        // would copy out the exact same bytes if called again.
        public int CopyFromHead(byte[] buffer, int offset, int length, bool fPeek)
        {
            int bytesCopied = 0;

            while ((m_DataQueue.Count > 0) && (bytesCopied < length))
            {
                // Don't dequeue just yet, just peek
                TRef wrapper = (TRef)m_DataQueue.Peek();
                VTable.Assert(wrapper != null); // Because we checked the count
                BytesPlusCount topChunk = (BytesPlusCount)(wrapper.Acquire());

                int copied = topChunk.CopyOut(buffer, offset + bytesCopied,
                                              length - bytesCopied, fPeek);
                bytesCopied += copied;

                if ((!fPeek) && (topChunk.Empty))
                {
                    // We want to throw away the top chunk. To take pressure off
                    // the finalizer, we'll explicitly free the ExHeap data vector.
                    topChunk.Dispose();
                    m_DataQueue.Dequeue();
                }
                else if ((!fPeek) && (!topChunk.Empty))
                {
                    // This should only happen because we filled up the
                    // caller's buffer
                    Debug.Assert(bytesCopied == length);
                    // Put the data back into its wrapper
                    wrapper.Release(topChunk);
                }
                else
                {
                    // Release topChunk back
                    wrapper.Release(topChunk);
                }
            }

            if (!fPeek)
            {
                m_Count -= bytesCopied;
                Debug.Assert(m_Count >= 0);
            }

            return(bytesCopied);
        }
예제 #3
0
        internal override void Bind(EndPoint localEndPoint)
        {
            if (localEndPoint == null)
            {
                throw new ArgumentNullException("localEndPoint");
            }

            IPEndPoint ep = localEndPoint as IPEndPoint;

            if (ep == null)
            {
                // Illegal argument
                throw new SocketException(SocketErrors.WSAEINVAL);
            }

            // Make sure we're in the ReadyState
            UdpConnectionContract /*.Imp*/ conn = (UdpConnectionContract)m_Conn.Acquire();

            try {
                if (!conn.InState(UdpConnectionContract.State.ReadyState /*.Value*/))
                {
                    throw new SocketException(BAD_SOCKET_STATE_ERR);
                }

                conn.BindLocalEndPoint(ep.Address.m_addr,
                                       unchecked ((ushort)ep.Port));
                m_LocalEndPoint = new IPEndPoint(ep.Address, ep.Port);
            }
            finally {
                m_Conn.Release(conn);
            }
        }
예제 #4
0
        internal void ForwardEvent(NicEventType theEvent)
        {
            //            DebugStub.Print("EventRelay:ForwardEvent\n");
            if (channelClosed)
            {
                DebugStub.Print("unexpectedly closed\n");
                return;
            }

            NicDeviceEventContract /*.Exp*/ exp = (NicDeviceEventContract)channel.Acquire();

            try {
                exp.NicDeviceEvent(theEvent);
            }
            finally {
                channel.Release(exp);
            }
        }
예제 #5
0
 internal static void ReleaseIPConnection(IPContract /*.Imp*/ connection)
 {
     IPSlot.Release(connection);
 }
예제 #6
0
 internal static void ReleaseDnsConnection(DNSContract /*.Imp*/ connection)
 {
     DnsSlot.Release(connection);
 }
예제 #7
0
 // Release the previously-acquired channel
 private void ReleaseChannel(TcpConnectionContract /*.Imp*/ conn)
 {
     m_Conn.Release(conn);
 }