| 1879 | } |
| 1880 | |
| 1881 | int SIPpSocket::read_error(int ret) |
| 1882 | { |
| 1883 | const char *errstring = strerror(errno); |
| 1884 | #if defined(USE_OPENSSL) || defined(USE_WOLFSSL) |
| 1885 | if (ss_transport == T_TLS) { |
| 1886 | int err = SSL_get_error(ss_ssl, ret); |
| 1887 | if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) { |
| 1888 | /* This is benign - we just need to wait for the socket to be |
| 1889 | * readable/writable again, which will happen naturally as part |
| 1890 | * of the poll/epoll loop. */ |
| 1891 | WARNING("SSL_read failed with error: %s. Retrying...", |
| 1892 | SSL_error_string(err, ret)); |
| 1893 | return 1; |
| 1894 | } |
| 1895 | } |
| 1896 | #endif |
| 1897 | |
| 1898 | assert(ret <= 0); |
| 1899 | |
| 1900 | #ifdef EAGAIN |
| 1901 | /* Scrub away EAGAIN from the rest of the code. */ |
| 1902 | if (errno == EAGAIN) { |
| 1903 | errno = EWOULDBLOCK; |
| 1904 | } |
| 1905 | #endif |
| 1906 | |
| 1907 | /* We have only non-blocking reads, so this should not occur. The OpenSSL |
| 1908 | * functions don't set errno, though, so this check doesn't make sense |
| 1909 | * for TLS sockets. */ |
| 1910 | if (ret < 0 && ss_transport != T_TLS) { |
| 1911 | assert(errno != EAGAIN); |
| 1912 | } |
| 1913 | |
| 1914 | if (ss_transport == T_TCP || ss_transport == T_TLS) { |
| 1915 | if (ret == 0) { |
| 1916 | /* The remote side closed the connection. */ |
| 1917 | if (ss_control) { |
| 1918 | if (localTwinSippSocket) |
| 1919 | localTwinSippSocket->close(); |
| 1920 | if (extendedTwinSippMode) { |
| 1921 | close_peer_sockets(); |
| 1922 | close_local_sockets(); |
| 1923 | free_peer_addr_map(); |
| 1924 | WARNING("One of the twin instances has ended -> exiting"); |
| 1925 | quitting += 20; |
| 1926 | } else if (twinSippMode) { |
| 1927 | if (twinSippSocket) |
| 1928 | twinSippSocket->close(); |
| 1929 | if (thirdPartyMode == MODE_3PCC_CONTROLLER_B) { |
| 1930 | WARNING("3PCC controller A has ended -> exiting"); |
| 1931 | quitting += 20; |
| 1932 | } else if (!quitting) { |
| 1933 | quitting = 1; |
| 1934 | } |
| 1935 | } |
| 1936 | } else { |
| 1937 | /* The socket was closed "cleanly", but we may have calls that need to |
| 1938 | * be destroyed. Also, if these calls are not complete, and attempt to |
no test coverage detected