MCPcopy Create free account
hub / github.com/Haivision/srt / createSocket

Method createSocket

srtcore/channel.cpp:162–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160srt::CChannel::~CChannel() {}
161
162void srt::CChannel::createSocket(int family)
163{
164#if ENABLE_SOCK_CLOEXEC
165 bool cloexec_flag = false;
166 // construct an socket
167#if defined(SOCK_CLOEXEC)
168 m_iSocket = ::socket(family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP);
169 if (m_iSocket == INVALID_SOCKET)
170 {
171 m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP);
172 cloexec_flag = true;
173 }
174#else
175 m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP);
176 cloexec_flag = true;
177#endif
178
179#else // ENABLE_SOCK_CLOEXEC
180 m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP);
181#endif // ENABLE_SOCK_CLOEXEC
182
183 if (m_iSocket == INVALID_SOCKET)
184 throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);
185
186#if ENABLE_SOCK_CLOEXEC
187
188 if (cloexec_flag)
189 {
190#ifdef _WIN32
191 // XXX ::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0)
192#else
193 if (0 != set_cloexec(m_iSocket, 1))
194 {
195 throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);
196 }
197#endif //_WIN32
198 }
199#endif // ENABLE_SOCK_CLOEXEC
200
201 if ((m_mcfg.iIpV6Only != -1) && (family == AF_INET6)) // (not an error if it fails)
202 {
203 const int res SRT_ATR_UNUSED =
204 ::setsockopt(m_iSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&m_mcfg.iIpV6Only, sizeof m_mcfg.iIpV6Only);
205#if ENABLE_LOGGING
206 if (res == -1)
207 {
208 int err = errno;
209 char msg[160];
210 LOGC(kmlog.Error,
211 log << "::setsockopt: failed to set IPPROTO_IPV6/IPV6_V6ONLY = " << m_mcfg.iIpV6Only << ": "
212 << SysStrError(err, msg, 159));
213 }
214#endif // ENABLE_LOGGING
215 }
216}
217
218void srt::CChannel::open(const sockaddr_any& addr)
219{

Callers

nothing calls this directly

Calls 5

socketFunction · 0.85
set_cloexecFunction · 0.85
setsockoptFunction · 0.85
CUDTExceptionClass · 0.70
SysStrErrorFunction · 0.70

Tested by

no test coverage detected