MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / bindServer

Method bindServer

src/main/fdtransferServer_linux.cpp:31–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29int FdTransferServer::_peer;
30
31bool FdTransferServer::bindServer(struct sockaddr_un *sun, socklen_t addrlen, int accept_timeout) {
32 _server = socket(AF_UNIX, SOCK_SEQPACKET, 0);
33 if (_server == -1) {
34 perror("FdTransfer socket()");
35 return false;
36 }
37
38 // Arbitrary timeout, to prevent it from listening forever.
39 if (accept_timeout > 0) {
40 const struct timeval timeout = {accept_timeout, 0};
41 if (setsockopt(_server, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
42 perror("FdTransfer setsockopt(SO_RCVTIMEO)");
43 close(_server);
44 return false;
45 }
46 }
47
48 if (bind(_server, (const struct sockaddr*)sun, addrlen) < 0) {
49 perror("FdTransfer bind()");
50 close(_server);
51 return false;
52 }
53
54 if (listen(_server, 1) < 0) {
55 perror("FdTransfer listen()");
56 close(_server);
57 return false;
58 }
59
60 return true;
61}
62
63bool FdTransferServer::acceptPeer(int *peer_pid) {
64 _peer = accept(_server, NULL, NULL);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected