Ejemplo n.º 1
0
 // Returns the channel or throws a BAD_SOCKET_STATE_ERR error
 private TcpConnectionContract /*.Imp*/ GetChannelOrThrow()
 {
     if (m_Conn == null)
     {
         throw new SocketException(BAD_SOCKET_STATE_ERR);
     }
     else
     {
         return((TcpConnectionContract)m_Conn.Acquire());
     }
 }
Ejemplo n.º 2
0
        private void RxExchange()
        {
            NicDeviceContract /*.Imp*/ imp = (NicDeviceContract)nicChannel.Acquire();

            try {
                RxExchangeInternal(imp);
            }
            finally {
                this.nicChannel.Release(imp);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
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()));
 }
Ejemplo n.º 5
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()));
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
            }
        }