| 1240 | } |
| 1241 | |
| 1242 | SIPpSocket::SIPpSocket(bool use_ipv6, int transport, int fd, int accepting): |
| 1243 | ss_ipv6(use_ipv6), |
| 1244 | ss_transport(transport), |
| 1245 | ss_fd(fd) |
| 1246 | { |
| 1247 | /* Initialize all sockets with our destination address. */ |
| 1248 | memcpy(&ss_dest, &remote_sockaddr, sizeof(ss_dest)); |
| 1249 | |
| 1250 | #if defined(USE_OPENSSL) || defined(USE_WOLFSSL) |
| 1251 | if (transport == T_TLS) { |
| 1252 | int flags = fcntl(fd, F_GETFL, 0); |
| 1253 | fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
| 1254 | |
| 1255 | if ((ss_bio = BIO_new_socket(fd, BIO_NOCLOSE)) == nullptr) { |
| 1256 | ERROR("Unable to create BIO object:Problem with BIO_new_socket()"); |
| 1257 | } |
| 1258 | |
| 1259 | if (!(ss_ssl = (accepting ? SSL_new_server() : SSL_new_client()))) { |
| 1260 | ERROR("Unable to create SSL object : Problem with SSL_new()"); |
| 1261 | } |
| 1262 | |
| 1263 | SSL_set_bio(ss_ssl, ss_bio, ss_bio); |
| 1264 | } |
| 1265 | #endif |
| 1266 | /* Store this socket in the tables. */ |
| 1267 | ss_pollidx = pollnfds++; |
| 1268 | sockets[ss_pollidx] = this; |
| 1269 | #ifdef HAVE_EPOLL |
| 1270 | epollfiles[ss_pollidx].data.u32 = ss_pollidx; |
| 1271 | epollfiles[ss_pollidx].events = EPOLLIN; |
| 1272 | int rc = epoll_ctl(epollfd, EPOLL_CTL_ADD, ss_fd, &epollfiles[ss_pollidx]); |
| 1273 | if (rc == -1) { |
| 1274 | if (errno == EPERM) { |
| 1275 | // Attempted to use epoll on a file that does not support |
| 1276 | // it - this may happen legitimately when stdin/stdout is |
| 1277 | // redirected to /dev/null, so don't warn |
| 1278 | } else { |
| 1279 | ERROR_NO("Failed to add FD to epoll"); |
| 1280 | } |
| 1281 | } |
| 1282 | #else |
| 1283 | pollfiles[ss_pollidx].fd = ss_fd; |
| 1284 | pollfiles[ss_pollidx].events = POLLIN | POLLERR; |
| 1285 | pollfiles[ss_pollidx].revents = 0; |
| 1286 | #endif |
| 1287 | } |
| 1288 | |
| 1289 | static SIPpSocket* sipp_allocate_socket(bool use_ipv6, int transport, int fd) { |
| 1290 | return new SIPpSocket(use_ipv6, transport, fd, 0); |
nothing calls this directly
no test coverage detected