diff options
-rw-r--r-- | pjlib/include/pj/config.h | 11 | ||||
-rw-r--r-- | pjlib/src/pj/sock_bsd.c | 30 |
2 files changed, 39 insertions, 2 deletions
diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h index 6d5e17bc..bf05cbae 100644 --- a/pjlib/include/pj/config.h +++ b/pjlib/include/pj/config.h @@ -801,6 +801,17 @@ #endif +/** + * Disable WSAECONNRESET error for UDP sockets on Win32 platforms. See + * https://trac.pjsip.org/repos/ticket/1197. + * + * Default: 1 + */ +#ifndef PJ_SOCK_DISABLE_WSAECONNRESET +# define PJ_SOCK_DISABLE_WSAECONNRESET 1 +#endif + + /** @} */ /******************************************************************** diff --git a/pjlib/src/pj/sock_bsd.c b/pjlib/src/pj/sock_bsd.c index aef2ff8a..47e3fd14 100644 --- a/pjlib/src/pj/sock_bsd.c +++ b/pjlib/src/pj/sock_bsd.c @@ -493,8 +493,34 @@ PJ_DEF(pj_status_t) pj_sock_socket(int af, if (*sock == PJ_INVALID_SOCKET) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else - return PJ_SUCCESS; + +#if PJ_SOCK_DISABLE_WSAECONNRESET && \ + (!defined(PJ_WIN32_WINCE) || PJ_WIN32_WINCE==0) + +#ifndef SIO_UDP_CONNRESET + #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12) +#endif + + /* Disable WSAECONNRESET for UDP. + * See https://trac.pjsip.org/repos/ticket/1197 + */ + if (type==PJ_SOCK_DGRAM) { + DWORD dwBytesReturned = 0; + BOOL bNewBehavior = FALSE; + DWORD rc; + + rc = WSAIoctl(*sock, SIO_UDP_CONNRESET, + &bNewBehavior, sizeof(bNewBehavior), + NULL, 0, &dwBytesReturned, + NULL, NULL); + + if (rc==SOCKET_ERROR) { + // Ignored.. + } + } +#endif + + return PJ_SUCCESS; } #else |