| 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); |
nothing calls this directly
no test coverage detected