MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Accept

Method Accept

lib/base/socket.cpp:337–365  ·  view source on GitHub ↗

* Accepts a new client and creates a new client object for it. */

Source from the content-addressed store, hash-verified

335 * Accepts a new client and creates a new client object for it.
336 */
337Socket::Ptr Socket::Accept()
338{
339 sockaddr_storage addr;
340 socklen_t addrlen = sizeof(addr);
341
342 SOCKET fd = accept(GetFD(), (sockaddr *)&addr, &addrlen);
343
344#ifndef _WIN32
345 if (fd < 0) {
346 Log(LogCritical, "Socket")
347 << "accept() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
348
349 BOOST_THROW_EXCEPTION(socket_error()
350 << boost::errinfo_api_function("accept")
351 << boost::errinfo_errno(errno));
352 }
353#else /* _WIN32 */
354 if (fd == INVALID_SOCKET) {
355 Log(LogCritical, "Socket")
356 << "accept() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
357
358 BOOST_THROW_EXCEPTION(socket_error()
359 << boost::errinfo_api_function("accept")
360 << errinfo_win32_error(WSAGetLastError()));
361 }
362#endif /* _WIN32 */
363
364 return new Socket(fd);
365}
366
367bool Socket::Poll(bool read, bool write, struct timeval *timeout)
368{

Callers 1

ServerThreadProcMethod · 0.80

Calls 3

acceptFunction · 0.85
LogClass · 0.85
socket_errorClass · 0.85

Tested by

no test coverage detected