MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / bind

Method bind

MonaBase/sources/Socket.cpp:239–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237
238
239 bool bind(Exception& ex, const SocketAddress& address, bool reuseAddress) {
240 if (!_initialized && !init(ex, address.family()))
241 return false;
242
243 ioctl(ex,FIONBIO, 1); // set non blocking mode before bind
244
245 if (address.family() == IPAddress::IPv6)
246 setOption(ex, IPPROTO_IPV6, IPV6_V6ONLY, 1); // Used for OS like Linux which bind also IPV4 while binding IPV6
247
248 if (reuseAddress) {
249 setReuseAddress(ex,true);
250 setReusePort(true);
251 }
252 int rc = ::bind(_sockfd, address.addr(), address.size());
253 if (rc != 0) {
254 Net::SetException(ex, Net::LastError()," (address=",address.toString(),", reuseAddress=",reuseAddress,")");
255 return false;
256 }
257 managed(ex); // warning
258 return true;
259 }
260
261 bool bindWithListen(Exception& ex, const SocketAddress& address, bool reuseAddress,int backlog) {
262 if (!_initialized && !init(ex, address.family()))

Callers

nothing calls this directly

Calls 3

familyMethod · 0.45
addrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected