]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add uv_tcp_close_reset compat
authorOndřej Surý <ondrej@isc.org>
Wed, 9 Feb 2022 11:45:37 +0000 (12:45 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 17 Feb 2022 08:50:10 +0000 (09:50 +0100)
The uv_tcp_close_reset() function was added in libuv 1.32.0 and since we
support older libuv releases, we have to add a shim uv_tcp_close_reset()
implementation loosely based on libuv.

(cherry picked from commit cd3b58622c7401cd4150ea0a489596b1504b8869)

lib/isc/netmgr/uv-compat.c
lib/isc/netmgr/uv-compat.h

index 0c9a9559e99bf617cf2443ecdff3ac3b18847524..a1fc3097879281ec69ca74e46d77dfcd3cbf0587 100644 (file)
@@ -50,6 +50,24 @@ isc_uv_udp_connect(uv_udp_t *handle, const struct sockaddr *addr) {
 }
 #endif /* UV_VERSION_HEX < UV_VERSION(1, 27, 0) */
 
+#if UV_VERSION_HEX < UV_VERSION(1, 32, 0)
+int
+uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb) {
+       if (setsockopt(handle->io_watcher.fd, SOL_SOCKET, SO_LINGER,
+                      &(struct linger){ 1, 0 }, sizeof(struct linger)) == -1)
+       {
+#if UV_VERSION_HEX >= UV_VERSION(1, 10, 0)
+               return (uv_translate_sys_error(errno));
+#else
+               return (-errno);
+#endif /* UV_VERSION_HEX >= UV_VERSION(1, 10, 0) */
+       }
+
+       uv_close((uv_handle_t *)handle, close_cb);
+       return (0);
+}
+#endif /* UV_VERSION_HEX < UV_VERSION(1, 32, 0) */
+
 int
 isc_uv_udp_freebind(uv_udp_t *handle, const struct sockaddr *addr,
                    unsigned int flags) {
index 6797484a8a62aaff8c1b413e70153ce2bfad0b73..387d3c6940b12c463abad33938669a6963aac85d 100644 (file)
 
 #define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
 
+#if !defined(UV__ERR)
+#define UV__ERR(x) (-(x))
+#endif
+
 #if UV_VERSION_HEX < UV_VERSION(1, 19, 0)
 static inline void *
 uv_handle_get_data(const uv_handle_t *handle) {
@@ -45,6 +49,11 @@ uv_req_set_data(uv_req_t *req, void *data) {
 }
 #endif /* UV_VERSION_HEX < UV_VERSION(1, 19, 0) */
 
+#if UV_VERSION_HEX < UV_VERSION(1, 32, 0)
+int
+uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb);
+#endif
+
 #if UV_VERSION_HEX < UV_VERSION(1, 34, 0)
 #define uv_sleep(msec) usleep(msec * 1000)
 #endif /* UV_VERSION_HEX < UV_VERSION(1, 34, 0) */