/// <summary> /// /// </summary> /// <param name="af"></param> /// <param name="type"></param> /// <param name="protocol"></param> /// <returns></returns> //public static UDTSOCKET socket(int af, int type = SOCK_STREAM, int protocol = 0); public static UDTSOCKET socket(AddressFamily af, UDTSockType type, int protocol) { if (!s_UDTUnited.m_bGCStatus) s_UDTUnited.startup(); try { return s_UDTUnited.newSocket(af, type); } catch (CUDTException e) { s_UDTUnited.setError(new CUDTException(e)); return INVALID_SOCK; } catch (bad_alloc) { s_UDTUnited.setError(new CUDTException(3, 2, 0)); return INVALID_SOCK; } catch (Exception e) { s_UDTUnited.setError(new CUDTException(-1, 0, 0)); return INVALID_SOCK; } }
// Functionality: // Create a new UDT socket. // Parameters: // 0) [in] af: IP version, IPv4 (AF_INET) or IPv6 (AF_INET6). // 1) [in] type: socket type, SOCK_STREAM or SOCK_DGRAM // Returned value: // The new UDT socket ID, or INVALID_SOCK. UDTSOCKET newSocket(AddressFamily af, UDTSockType type) { //if ((type != UDTSockType.SOCK_STREAM) && (type != UDTSockType.SOCK_DGRAM)) // throw new CUDTException(5, 3, 0); UdtSocket ns = null; try { ns = new UdtSocket(); ns.m_pUDT = new CUDT(); ns.m_pSelfAddr = new IPAddress(); if (AddressFamily.InterNetwork == af) { ns.m_pSelfAddr = new IPEndPoint(IPAddress.Any, 0); } else { ns.m_pSelfAddr = new IPEndPoint(IPAddress.IPv6Any, 0); } } catch (Exception e) { //delete ns; throw new CUDTException(3, 2, 0); } lock (m_IDLock) { ns.m_SocketID = --m_SocketID; } ns.m_Status = UDTSTATUS.INIT; ns.m_ListenSocket = 0; ns.m_pUDT.m_SocketID = ns.m_SocketID; ns.m_pUDT.m_iSockType = (UDTSockType.SOCK_STREAM == type) ? UDTSockType.UDT_STREAM : UDTSockType.UDT_DGRAM; ns.m_pUDT.m_iIPversion = ns.m_iIPversion = af; ns.m_pUDT.m_pCache = m_pCache; // protect the m_Sockets structure. lock (m_ControlLock) { try { m_Sockets[ns.m_SocketID] = ns; } catch (Exception e) { //failure and rollback //delete ns; ns = null; } } if (null == ns) throw new CUDTException(3, 2, 0); return ns.m_SocketID; }
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; }