MCPcopy Create free account
hub / github.com/Barracuda09/SATPI / acceptConnection

Method acceptConnection

src/socket/SocketAttr.cpp:116–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114 }
115
116 bool SocketAttr::acceptConnection(SocketClient &client, bool showLogInfo) {
117 // check if we have a client?
118 socklen_t addrlen = sizeof(client._addr);
119 const int fdAccept = ::accept(_fd, reinterpret_cast<sockaddr *>(&client._addr), &addrlen);
120 if (fdAccept >= 0) {
121
122// @todo should 'client' handle this himself?
123
124 // save connected file descriptor
125 client.setFD(fdAccept);
126
127 client.setSocketTimeoutInSec(2);
128
129 client.setKeepAlive();
130
131 // save client ip address
132 client.setIPAddressOfSocket(inet_ntoa(client._addr.sin_addr));
133
134 // Show who is connected
135 if (showLogInfo) {
136 SI_LOG_INFO("%s Connection from %s Port %d with fd: %d", client.getProtocolString().c_str(),
137 client.getIPAddressOfSocket().c_str(), ntohs(client._addr.sin_port), fdAccept);
138 }
139 return true;
140 }
141 return false;
142 }
143
144 int SocketAttr::getSocketPort() const {
145 return ntohs(_addr.sin_port);

Callers

nothing calls this directly

Calls 6

setFDMethod · 0.80
setSocketTimeoutInSecMethod · 0.80
setKeepAliveMethod · 0.80
setIPAddressOfSocketMethod · 0.80
getProtocolStringMethod · 0.80
getIPAddressOfSocketMethod · 0.80

Tested by

no test coverage detected