| 1378 | } |
| 1379 | |
| 1380 | SIPpSocket* SIPpSocket::accept() { |
| 1381 | SIPpSocket *ret; |
| 1382 | struct sockaddr_storage remote_sockaddr; |
| 1383 | int fd; |
| 1384 | sipp_socklen_t addrlen = sizeof(remote_sockaddr); |
| 1385 | |
| 1386 | if ((fd = ::accept(ss_fd, (struct sockaddr *)&remote_sockaddr, &addrlen))== -1) { |
| 1387 | ERROR("Unable to accept on a %s socket: %s", TRANSPORT_TO_STRING(transport), strerror(errno)); |
| 1388 | } |
| 1389 | |
| 1390 | #if defined(__SUNOS) |
| 1391 | if (fd < 256) { |
| 1392 | int newfd = fcntl(fd, F_DUPFD, 256); |
| 1393 | if (newfd <= 0) { |
| 1394 | // Typically, (24)(Too many open files) is the error here |
| 1395 | WARNING("Unable to get a different %s socket, errno=%d(%s)", |
| 1396 | TRANSPORT_TO_STRING(transport), errno, strerror(errno)); |
| 1397 | |
| 1398 | // Keep the original socket fd. |
| 1399 | newfd = fd; |
| 1400 | } else { |
| 1401 | ::close(fd); |
| 1402 | } |
| 1403 | fd = newfd; |
| 1404 | } |
| 1405 | #endif |
| 1406 | |
| 1407 | ret = new SIPpSocket(ss_ipv6, ss_transport, fd, 1); |
| 1408 | |
| 1409 | /* We should connect back to the address which connected to us if we |
| 1410 | * experience a TCP failure. */ |
| 1411 | memcpy(&ret->ss_dest, &remote_sockaddr, sizeof(ret->ss_dest)); |
| 1412 | |
| 1413 | if (ret->ss_transport == T_TLS) { |
| 1414 | #if defined(USE_OPENSSL) || defined(USE_WOLFSSL) |
| 1415 | int rc; |
| 1416 | int i = 0; |
| 1417 | while ((rc = SSL_accept(ret->ss_ssl)) < 0) { |
| 1418 | int err = SSL_get_error(ret->ss_ssl, rc); |
| 1419 | if ((err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) && |
| 1420 | i < SIPP_SSL_MAX_RETRIES) { |
| 1421 | /* These errors are benign we just need to wait for the socket |
| 1422 | * to be readable/writable again. */ |
| 1423 | WARNING("SSL_accept failed with error: %s. Attempt %d. " |
| 1424 | "Retrying...", SSL_error_string(err, rc), ++i); |
| 1425 | sipp_usleep(SIPP_SSL_RETRY_TIMEOUT); |
| 1426 | continue; |
| 1427 | } |
| 1428 | ERROR("Error in SSL_accept: %s", |
| 1429 | SSL_error_string(err, rc)); |
| 1430 | break; |
| 1431 | } |
| 1432 | #else |
| 1433 | ERROR("You need to compile SIPp with TLS support"); |
| 1434 | #endif |
| 1435 | } |
| 1436 | return ret; |
| 1437 | } |
no test coverage detected