Esempio n. 1
0
        // Functionality:
        //    Remove the UDT instance from the list.
        // Parameters:
        //    1) [in] u: pointer to the UDT instance
        // Returned value:
        //    None.

        public void remove(CUDT u)
        {
            CRNode n = u.m_pRNode;

            if (!n.m_bOnList)
                return;

            if (null == n.m_pPrev)
            {
                // n is the first node
                m_pUList = n.m_pNext;
                if (null == m_pUList)
                    m_pLast = null;
                else
                    m_pUList.m_pPrev = null;
            }
            else
            {
                n.m_pPrev.m_pNext = n.m_pNext;
                if (null == n.m_pNext)
                {
                    // n is the last node
                    m_pLast = n.m_pPrev;
                }
                else
                    n.m_pNext.m_pPrev = n.m_pPrev;
            }

            n.m_pNext = n.m_pPrev = null;

            n.m_bOnList = false;
        }
Esempio n. 2
0
        private CRNode m_pLast = null;		// the last node


        // Functionality:
        //    Insert a new UDT instance to the list.
        // Parameters:
        //    1) [in] u: pointer to the UDT instance
        // Returned value:
        //    None.

        public void insert(CUDT u)
        {
            CRNode n = u.m_pRNode;
            CClock.rdtsc(n.m_llTimeStamp);

            n.m_bOnList = true;

            if (null == m_pUList)
            {
                // empty list, insert as the single node
                n.m_pPrev = n.m_pNext = null;
                m_pLast = m_pUList = n;

                return;
            }

            // always insert at the end for RcvUList
            n.m_pPrev = m_pLast;
            n.m_pNext = null;
            m_pLast.m_pNext = n;
            m_pLast = n;
        }
Esempio n. 3
0
        public void updateMux(CUDT u, UdtSocket ls)
        {
            CGuard cg = new CGuard(m_ControlLock);

            //int port = (AF_INET == ls.m_iIPversion) ? ntohs(((sockaddr_in*)ls.m_pSelfAddr).sin_port) : ntohs(((sockaddr_in6*)ls.m_pSelfAddr).sin6_port);
            int port = ls.m_pSelfAddr.Port;

            // find the listener's address
            foreach (CMultiplexer i in m_vMultiplexer)
            {
                if (i.m_iPort == port)
                {
                    // reuse the existing multiplexer
                    ++i.m_iRefCount;
                    u.m_pSndQueue = i.m_pSndQueue;
                    u.m_pRcvQueue = i.m_pRcvQueue;
                    return;
                }
            }
        }
Esempio n. 4
0
        void updateMux(CUDT u, IPEndPoint addr, Socket udpsock)
        {
            CGuard cg = new CGuard(m_ControlLock);

            if ((u.m_bReuseAddr) && (null != addr))
            {
                //int port = (AF_INET == u.m_iIPversion) ? ntohs(((sockaddr_in*)addr).sin_port) : ntohs(((sockaddr_in6*)addr).sin6_port);
                int port = addr.Port;

                // find a reusable address
                //for (vector<CMultiplexer>::iterator i = m_vMultiplexer.begin(); i != m_vMultiplexer.end(); ++ i)
                foreach (CMultiplexer i in m_vMultiplexer)
                {
                    if ((i.m_iIPversion == u.m_iIPversion) && (i.m_iMSS == u.m_iMSS) && i.m_bReusable)
                    {
                        if (i.m_iPort == port)
                        {
                            // reuse the existing multiplexer
                            ++i.m_iRefCount;
                            u.m_pSndQueue = i.m_pSndQueue;
                            u.m_pRcvQueue = i.m_pRcvQueue;
                            return;
                        }
                    }
                }
            }

            // a new multiplexer is needed
            CMultiplexer m;
            m.m_iMSS = u.m_iMSS;
            m.m_iIPversion = u.m_iIPversion;
            m.m_iRefCount = 1;
            m.m_bReusable = u.m_bReuseAddr;

            m.m_pChannel = new CChannel(u.m_iIPversion);
            m.m_pChannel.setSndBufSize(u.m_iUDPSndBufSize);
            m.m_pChannel.setRcvBufSize(u.m_iUDPRcvBufSize);

            try
            {
                if (null != udpsock)
                    m.m_pChannel.open(udpsock);
                else
                    m.m_pChannel.open(addr);
            }
            catch (CUDTException e)
            {
                m.m_pChannel.close();
                //delete m.m_pChannel;
                throw e;
            }

            IPEndPoint sa = (AddressFamily.InterNetwork == u.m_iIPversion) ? new IPEndPoint(IPAddress.Any, 0) : new IPEndPoint(IPAddress.IPv6Any, 0);
            m.m_pChannel.getSockAddr(out sa);
            m.m_iPort = sa.Port;
            //         (AF_INET == u.m_iIPversion) ? ntohs(((sockaddr_in*)sa).sin_port) : ntohs(((sockaddr_in6*)sa).sin6_port);
            //if (AddressFamily.InterNetwork == u.m_iIPversion) 
            //    delete (sockaddr_in*)sa; 
            // else 
            //     delete (sockaddr_in6*)sa;

            m.m_pTimer = new CClock();

            m.m_pSndQueue = new CSndQueue(m.m_pChannel, m.m_pTimer);
            m.m_pRcvQueue = new CRcvQueue();
            m.m_pRcvQueue.init(32, u.m_iPayloadSize, m.m_iIPversion, 1024, m.m_pChannel, m.m_pTimer);

            m_vMultiplexer.insert(m_vMultiplexer.end(), m);

            u.m_pSndQueue = m.m_pSndQueue;
            u.m_pRcvQueue = m.m_pRcvQueue;
        }
Esempio n. 5
0
 public void setNewEntry(CUDT u)
 {
     CGuard listguard = new CGuard(m_IDLock);
     m_vNewEntry.insert(m_vNewEntry.end(), u);
 }
Esempio n. 6
0
 public void removeListener(CUDT u)
 {
     lock (m_LSLock)
     {
         if (u == m_pListener)
             m_pListener = null;
     }
 }
Esempio n. 7
0
        public int setListener(CUDT u)
        {
            lock (m_LSLock)
            {
                if (null != m_pListener)
                    return -1;

                m_pListener = u;
            }

            return 1;
        }
Esempio n. 8
0
        // Functionality:
        //    Move the UDT instance to the end of the list, if it already exists; otherwise, do nothing.
        // Parameters:
        //    1) [in] u: pointer to the UDT instance
        // Returned value:
        //    None.

        public void update(CUDT u)
        {
            CRNode n = u.m_pRNode;

            if (!n.m_bOnList)
                return;

            CClock.rdtsc(n.m_llTimeStamp);

            // if n is the last node, do not need to change
            if (null == n.m_pNext)
                return;

            if (null == n.m_pPrev)
            {
                m_pUList = n.m_pNext;
                m_pUList.m_pPrev = null;
            }
            else
            {
                n.m_pPrev.m_pNext = n.m_pNext;
                n.m_pNext.m_pPrev = n.m_pPrev;
            }

            n.m_pPrev = m_pLast;
            n.m_pNext = null;
            m_pLast.m_pNext = n;
            m_pLast = n;
        }
Esempio n. 9
0
   internal CRNode m_pRNode;                    // node information for UDT list used in rcv queue
#endregion

#region constructor and desctructor
        CUDT(CUDT ancestor)
{
   m_pSndBuffer = null;
   m_pRcvBuffer = null;
   m_pSndLossList = null;
   m_pRcvLossList = null;
   m_pACKWindow = null;
   m_pSndTimeWindow = null;
   m_pRcvTimeWindow = null;

   m_pSndQueue = null;
   m_pRcvQueue = null;
   m_pPeerAddr = null;
   m_pSNode = null;
   m_pRNode = null;

   // Initilize mutex and condition variables
   initSynch();

   // Default UDT configurations
   m_iMSS = ancestor.m_iMSS;
   m_bSynSending = ancestor.m_bSynSending;
   m_bSynRecving = ancestor.m_bSynRecving;
   m_iFlightFlagSize = ancestor.m_iFlightFlagSize;
   m_iSndBufSize = ancestor.m_iSndBufSize;
   m_iRcvBufSize = ancestor.m_iRcvBufSize;
   m_Linger = ancestor.m_Linger;
   m_iUDPSndBufSize = ancestor.m_iUDPSndBufSize;
   m_iUDPRcvBufSize = ancestor.m_iUDPRcvBufSize;
   m_iSockType = ancestor.m_iSockType;
   m_iIPversion = ancestor.m_iIPversion;
   m_bRendezvous = ancestor.m_bRendezvous;
   m_iSndTimeOut = ancestor.m_iSndTimeOut;
   m_iRcvTimeOut = ancestor.m_iRcvTimeOut;
   m_bReuseAddr = true;	// this must be true, because all accepted sockets shared the same port with the listener
   m_llMaxBW = ancestor.m_llMaxBW;

   m_pCCFactory = ancestor.m_pCCFactory.clone();
   m_pCC = null;
   m_pCache = ancestor.m_pCache;

   // Initial status
   m_bOpened = false;
   m_bListening = false;
   m_bConnected = false;
   m_bClosing = false;
   m_bShutdown = false;
   m_bBroken = false;
}
Esempio n. 10
0
        // Functionality:
        //    Insert an entry to the hash table.
        // Parameters:
        //    1) [in] id: socket ID
        //    2) [in] u: pointer to the UDT instance
        // Returned value:
        //    None.

        public void Insert(Int32 id, CUDT u)
        {
            fDictionary.Add(id, u);
        }