From: Arran Cudbard-Bell Date: Thu, 8 Dec 2022 17:08:06 +0000 (-0600) Subject: curl: Deal with socket closures in a more libcurl friendly way X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0cad4ec86f2199f1fe431d592126cb6ebb88d58;p=thirdparty%2Ffreeradius-server.git curl: Deal with socket closures in a more libcurl friendly way --- diff --git a/src/lib/curl/io.c b/src/lib/curl/io.c index b92e965e4a9..0486326ab32 100644 --- a/src/lib/curl/io.c +++ b/src/lib/curl/io.c @@ -165,6 +165,10 @@ static inline void _fr_curl_io_service(fr_curl_handle_t *mhandle, int fd, int ev event_str = "socket-readable"; break; + case 0: + event_str = "closed"; /* Not really closed, more do your own eval! */ + break; + default: event_str = ""; break; @@ -187,12 +191,26 @@ static inline void _fr_curl_io_service(fr_curl_handle_t *mhandle, int fd, int ev * @param[in] fd_errno from kevent. * @param[in] uctx The rlm_fr_curl_thread_t specific to this thread. */ -static void _fr_curl_io_service_errored(UNUSED fr_event_list_t *el, int fd, UNUSED int flags, int fd_errno, void *uctx) +static void _fr_curl_io_service_errored(UNUSED fr_event_list_t *el, int fd, int flags, int fd_errno, void *uctx) { fr_curl_handle_t *mhandle = talloc_get_type_abort(uctx, fr_curl_handle_t); DEBUG4("multi-handle %p - fd %i errored: %s", mhandle->mandle, fd, fr_syserror(fd_errno)); + /* + * The remote server closed the socket + * + * Instead of signalling curl with CURL_CSELECT_ERR + * which always results in spurious errors being + * printed, pass in '0', which causes libcurl to do + * its own evaluation on the socket state, and hopefully + * run the right code for socket closure. + */ + if (flags & EV_EOF) { + _fr_curl_io_service(mhandle, fd, 0); + return; + } + _fr_curl_io_service(mhandle, fd, CURL_CSELECT_ERR); }