Create a AsyncServerSocket from an existing socket file descriptor.

Synopsis

Declared in <folly/io/async/AsyncServerSocket.h>

void
useExistingSocket(NetworkSocket fd);

Description

useExistingSocket() will cause the AsyncServerSocket to take ownership of the specified file descriptor, and use it to listen for new connections. The AsyncServerSocket will close the file descriptor when it is destroyed.

useExistingSocket() must be called before bind() or listen().

The supplied file descriptor will automatically be put into non‐blocking mode. The caller may have already directly called bind() and possibly listen on the file descriptor. If so the caller should skip calling the corresponding AsyncServerSocket::bind() and listen() methods.

On error a AsyncSocketException will be thrown and the caller will retain ownership of the file descriptor.

Parameters

Name

Description

fd

existing socket's file descriptor

Created with MrDocs