]> 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:06:58 +0000 (09:06 +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.

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

index 104ba5118efe07662547c1b8c4261f2ddf9acfa6..b7c0f7b0e29250297a8d52f56f0e093e9ba10232 100644 (file)
@@ -42,6 +42,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) */