Blame SOURCES/587.patch

8e5576
From 83ae19d273bed781e653cdcfe55b9127ef2fbb58 Mon Sep 17 00:00:00 2001
8e5576
From: Alan Brooks <12380017+alan-brooks@users.noreply.github.com>
8e5576
Date: Thu, 28 Dec 2023 12:18:15 +0000
8e5576
Subject: [PATCH 1/4] Updates for Cython3 Remove SSL depreciation warnings
8e5576
 buillt on debian 12.6 python-3.22 Cython-3.0.7 libuv-1.46.0
8e5576
8e5576
---
8e5576
 Makefile                         |  2 +-
8e5576
 setup.py                         |  6 ++++--
8e5576
 tests/test_process.py            |  4 ++--
8e5576
 tests/test_tcp.py                | 19 ++++++++++++-------
8e5576
 uvloop/_testbase.py              |  4 +++-
8e5576
 uvloop/cbhandles.pyx             |  4 ++--
8e5576
 uvloop/dns.pyx                   |  4 ++--
8e5576
 uvloop/handles/basetransport.pxd |  4 ++--
8e5576
 uvloop/handles/basetransport.pyx |  4 ++--
8e5576
 uvloop/handles/handle.pyx        |  2 +-
8e5576
 uvloop/handles/pipe.pyx          |  2 +-
8e5576
 uvloop/handles/poll.pxd          |  2 +-
8e5576
 uvloop/handles/poll.pyx          |  2 +-
8e5576
 uvloop/handles/stream.pyx        | 16 ++++++++++------
8e5576
 uvloop/handles/udp.pyx           |  4 ++--
8e5576
 uvloop/includes/consts.pxi       | 25 -------------------------
8e5576
 uvloop/includes/fork_handler.h   |  6 +++++-
8e5576
 uvloop/includes/system.h         | 16 ++++++++++++++++
8e5576
 uvloop/includes/system.pxd       | 12 ++++--------
8e5576
 uvloop/includes/uv.pxd           |  6 +++---
8e5576
 uvloop/loop.pxd                  | 28 ++++++++++++++++++++++++----
8e5576
 uvloop/loop.pyx                  | 10 +++++-----
8e5576
 uvloop/sslproto.pxd              |  4 ++--
8e5576
 uvloop/sslproto.pyx              |  4 ++--
8e5576
 24 files changed, 107 insertions(+), 83 deletions(-)
8e5576
 delete mode 100644 uvloop/includes/consts.pxi
8e5576
 create mode 100755 uvloop/includes/system.h
8e5576
8e5576
diff --git a/Makefile b/Makefile
8e5576
index 4375e5d2..6a0475a9 100644
8e5576
--- a/Makefile
8e5576
+++ b/Makefile
8e5576
@@ -9,7 +9,7 @@ _default: compile
8e5576
 
8e5576
 
8e5576
 clean:
8e5576
-	rm -fr dist/ doc/_build/ *.egg-info uvloop/loop.*.pyd
8e5576
+	rm -fr dist/ doc/_build/ *.egg-info uvloop/loop.*.pyd uvloop/loop_d.*.pyd
8e5576
 	rm -fr uvloop/*.c uvloop/*.html uvloop/*.so
8e5576
 	rm -fr uvloop/handles/*.html uvloop/includes/*.html
8e5576
 	find . -name '__pycache__' | xargs rm -rf
8e5576
diff --git a/setup.py b/setup.py
8e5576
index ba15af50..8fdf0e56 100644
8e5576
--- a/setup.py
8e5576
+++ b/setup.py
8e5576
@@ -21,7 +21,7 @@
8e5576
 from setuptools.command.sdist import sdist
8e5576
 
8e5576
 
8e5576
-CYTHON_DEPENDENCY = 'Cython(>=0.29.36,<0.30.0)'
8e5576
+CYTHON_DEPENDENCY = 'Cython(>=0.29.36)'
8e5576
 MACHINE = platform.machine()
8e5576
 MODULES_CFLAGS = [os.getenv('UVLOOP_OPT_CFLAGS', '-O2')]
8e5576
 _ROOT = pathlib.Path(__file__).parent
8e5576
@@ -144,7 +144,9 @@ def finalize_options(self):
8e5576
             self.distribution.ext_modules[:] = cythonize(
8e5576
                 self.distribution.ext_modules,
8e5576
                 compiler_directives=directives,
8e5576
-                annotate=self.cython_annotate)
8e5576
+                annotate=self.cython_annotate,
8e5576
+                compile_time_env=dict(DEFAULT_FREELIST_SIZE=250, SSL_READ_MAX_SIZE=256 * 1024),
8e5576
+                emit_linenums=True)
8e5576
 
8e5576
         super().finalize_options()
8e5576
 
8e5576
diff --git a/tests/test_process.py b/tests/test_process.py
8e5576
index bfcbba17..95e1c9e7 100644
8e5576
--- a/tests/test_process.py
8e5576
+++ b/tests/test_process.py
8e5576
@@ -912,7 +912,7 @@ def test_process_delayed_stdio__paused__stdin_pipe(self):
8e5576
                 stdin=subprocess.PIPE,
8e5576
                 stdout=subprocess.PIPE,
8e5576
                 stderr=subprocess.PIPE,
8e5576
-                __uvloop_sleep_after_fork=True))
8e5576
+                uvloop_sleep_after_fork=True))
8e5576
         self.assertIsNot(transport, None)
8e5576
         self.assertEqual(transport.get_returncode(), 0)
8e5576
         self.assertEqual(
8e5576
@@ -931,7 +931,7 @@ def test_process_delayed_stdio__paused__no_stdin(self):
8e5576
                 stdin=None,
8e5576
                 stdout=subprocess.PIPE,
8e5576
                 stderr=subprocess.PIPE,
8e5576
-                __uvloop_sleep_after_fork=True))
8e5576
+                uvloop_sleep_after_fork=True))
8e5576
         self.assertIsNot(transport, None)
8e5576
         self.assertEqual(transport.get_returncode(), 0)
8e5576
         self.assertEqual(
8e5576
diff --git a/tests/test_tcp.py b/tests/test_tcp.py
8e5576
index 812e62b8..213e2d9f 100644
8e5576
--- a/tests/test_tcp.py
8e5576
+++ b/tests/test_tcp.py
8e5576
@@ -1630,17 +1630,22 @@ async def client(addr):
8e5576
             self.fail("unexpected call to connection_made()")
8e5576
 
8e5576
     def test_ssl_connect_accepted_socket(self):
8e5576
-        if hasattr(ssl, 'PROTOCOL_TLS'):
8e5576
-            proto = ssl.PROTOCOL_TLS
8e5576
+        if hasattr(ssl, 'PROTOCOL_TLS_SERVER'):
8e5576
+            server_proto = ssl.PROTOCOL_TLS_SERVER
8e5576
+            client_proto = ssl.PROTOCOL_TLS_CLIENT
8e5576
         else:
8e5576
-            proto = ssl.PROTOCOL_SSLv23
8e5576
-        server_context = ssl.SSLContext(proto)
8e5576
+            if hasattr(ssl, 'PROTOCOL_TLS'):
8e5576
+                client_proto = server_proto = ssl.PROTOCOL_TLS
8e5576
+            else:
8e5576
+                client_proto = server_proto = ssl.PROTOCOL_SSLv23
8e5576
+
8e5576
+        server_context = ssl.SSLContext(server_proto)
8e5576
         server_context.load_cert_chain(self.ONLYCERT, self.ONLYKEY)
8e5576
         if hasattr(server_context, 'check_hostname'):
8e5576
             server_context.check_hostname = False
8e5576
         server_context.verify_mode = ssl.CERT_NONE
8e5576
 
8e5576
-        client_context = ssl.SSLContext(proto)
8e5576
+        client_context = ssl.SSLContext(client_proto)
8e5576
         if hasattr(server_context, 'check_hostname'):
8e5576
             client_context.check_hostname = False
8e5576
         client_context.verify_mode = ssl.CERT_NONE
8e5576
@@ -2233,7 +2238,7 @@ def test_renegotiation(self):
8e5576
         sslctx.use_privatekey_file(self.ONLYKEY)
8e5576
         sslctx.use_certificate_chain_file(self.ONLYCERT)
8e5576
         client_sslctx = self._create_client_ssl_context()
8e5576
-        if hasattr(ssl, 'OP_NO_TLSv1_3'):
8e5576
+        if sys.version_info < (3, 8) and hasattr(ssl, 'OP_NO_TLSv1_3'):
8e5576
             client_sslctx.options |= ssl.OP_NO_TLSv1_3
8e5576
 
8e5576
         def server(sock):
8e5576
@@ -2592,7 +2597,7 @@ def test_flush_before_shutdown(self):
8e5576
         sslctx_openssl.use_privatekey_file(self.ONLYKEY)
8e5576
         sslctx_openssl.use_certificate_chain_file(self.ONLYCERT)
8e5576
         client_sslctx = self._create_client_ssl_context()
8e5576
-        if hasattr(ssl, 'OP_NO_TLSv1_3'):
8e5576
+        if sys.version_info < (3, 8) and hasattr(ssl, 'OP_NO_TLSv1_3'):
8e5576
             client_sslctx.options |= ssl.OP_NO_TLSv1_3
8e5576
 
8e5576
         future = None
8e5576
diff --git a/uvloop/_testbase.py b/uvloop/_testbase.py
8e5576
index c4a7595b..e620e158 100644
8e5576
--- a/uvloop/_testbase.py
8e5576
+++ b/uvloop/_testbase.py
8e5576
@@ -269,7 +269,9 @@ def find_free_port(start_from=50000):
8e5576
 class SSLTestCase:
8e5576
 
8e5576
     def _create_server_ssl_context(self, certfile, keyfile=None):
8e5576
-        if hasattr(ssl, 'PROTOCOL_TLS'):
8e5576
+        if hasattr(ssl, 'PROTOCOL_TLS_SERVER'):
8e5576
+            sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
8e5576
+        elif hasattr(ssl, 'PROTOCOL_TLS'):
8e5576
             sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS)
8e5576
         else:
8e5576
             sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
8e5576
diff --git a/uvloop/cbhandles.pyx b/uvloop/cbhandles.pyx
8e5576
index 2914b42e..8bcc5aa6 100644
8e5576
--- a/uvloop/cbhandles.pyx
8e5576
+++ b/uvloop/cbhandles.pyx
8e5576
@@ -76,8 +76,8 @@ cdef class Handle:
8e5576
                     self.arg1, self.arg2, self.arg3, self.arg4)
8e5576
 
8e5576
             else:
8e5576
-                raise RuntimeError('invalid Handle.cb_type: {}'.format(
8e5576
-                    cb_type))
8e5576
+                raise RuntimeError('invalid Handle.cb_type: {} {!r}/{!r}'.format(
8e5576
+                    cb_type, self.args1, self.args2))
8e5576
 
8e5576
         except (KeyboardInterrupt, SystemExit):
8e5576
             raise
8e5576
diff --git a/uvloop/dns.pyx b/uvloop/dns.pyx
8e5576
index 7aad6319..09b92828 100644
8e5576
--- a/uvloop/dns.pyx
8e5576
+++ b/uvloop/dns.pyx
8e5576
@@ -298,7 +298,7 @@ cdef class AddrInfo:
8e5576
             uv.uv_freeaddrinfo(self.data)  # returns void
8e5576
             self.data = NULL
8e5576
 
8e5576
-    cdef void set_data(self, system.addrinfo *data):
8e5576
+    cdef void set_data(self, system.addrinfo *data) noexcept:
8e5576
         self.data = data
8e5576
 
8e5576
     cdef unpack(self):
8e5576
@@ -326,7 +326,7 @@ cdef class AddrInfo:
8e5576
         return result
8e5576
 
8e5576
     @staticmethod
8e5576
-    cdef int isinstance(object other):
8e5576
+    cdef int isinstance(object other) noexcept:
8e5576
         return type(other) is AddrInfo
8e5576
 
8e5576
 
8e5576
diff --git a/uvloop/handles/basetransport.pxd b/uvloop/handles/basetransport.pxd
8e5576
index ba356a78..8112622c 100644
8e5576
--- a/uvloop/handles/basetransport.pxd
8e5576
+++ b/uvloop/handles/basetransport.pxd
8e5576
@@ -47,8 +47,8 @@ cdef class UVBaseTransport(UVSocketHandle):
8e5576
     # === overloads ===
8e5576
 
8e5576
     cdef _new_socket(self)
8e5576
-    cdef size_t _get_write_buffer_size(self)
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept
8e5576
 
8e5576
-    cdef bint _is_reading(self)
8e5576
+    cdef bint _is_reading(self) noexcept
8e5576
     cdef _start_reading(self)
8e5576
     cdef _stop_reading(self)
8e5576
diff --git a/uvloop/handles/basetransport.pyx b/uvloop/handles/basetransport.pyx
8e5576
index 28b30794..a8592f2d 100644
8e5576
--- a/uvloop/handles/basetransport.pyx
8e5576
+++ b/uvloop/handles/basetransport.pyx
8e5576
@@ -18,7 +18,7 @@ cdef class UVBaseTransport(UVSocketHandle):
8e5576
 
8e5576
         self._closing = 0
8e5576
 
8e5576
-    cdef size_t _get_write_buffer_size(self):
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept:
8e5576
         return 0
8e5576
 
8e5576
     cdef inline _schedule_call_connection_made(self):
8e5576
@@ -211,7 +211,7 @@ cdef class UVBaseTransport(UVSocketHandle):
8e5576
             self._extra_info = {}
8e5576
         self._extra_info[name] = obj
8e5576
 
8e5576
-    cdef bint _is_reading(self):
8e5576
+    cdef bint _is_reading(self) noexcept:
8e5576
         raise NotImplementedError
8e5576
 
8e5576
     cdef _start_reading(self):
8e5576
diff --git a/uvloop/handles/handle.pyx b/uvloop/handles/handle.pyx
8e5576
index 6efe3755..2c96458b 100644
8e5576
--- a/uvloop/handles/handle.pyx
8e5576
+++ b/uvloop/handles/handle.pyx
8e5576
@@ -363,7 +363,7 @@ cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) noexcept with gil:
8e5576
             Py_DECREF(h)  # Was INCREFed in UVHandle._close
8e5576
 
8e5576
 
8e5576
-cdef void __close_all_handles(Loop loop):
8e5576
+cdef void __close_all_handles(Loop loop) noexcept:
8e5576
     uv.uv_walk(loop.uvloop,
8e5576
                __uv_walk_close_all_handles_cb,
8e5576
                <void*>loop)  # void
8e5576
diff --git a/uvloop/handles/pipe.pyx b/uvloop/handles/pipe.pyx
8e5576
index 195576c7..d30a7366 100644
8e5576
--- a/uvloop/handles/pipe.pyx
8e5576
+++ b/uvloop/handles/pipe.pyx
8e5576
@@ -25,7 +25,7 @@ cdef __pipe_init_uv_handle(UVStream handle, Loop loop):
8e5576
 cdef __pipe_open(UVStream handle, int fd):
8e5576
     cdef int err
8e5576
     err = uv.uv_pipe_open(<uv.uv_pipe_t *>handle._handle,
8e5576
-                          <uv.uv_file>fd)
8e5576
+                          <uv.uv_os_fd_t>fd)
8e5576
     if err < 0:
8e5576
         exc = convert_error(err)
8e5576
         raise exc
8e5576
diff --git a/uvloop/handles/poll.pxd b/uvloop/handles/poll.pxd
8e5576
index d07030b5..c2205402 100644
8e5576
--- a/uvloop/handles/poll.pxd
8e5576
+++ b/uvloop/handles/poll.pxd
8e5576
@@ -10,7 +10,7 @@ cdef class UVPoll(UVHandle):
8e5576
     cdef inline _poll_start(self, int flags)
8e5576
     cdef inline _poll_stop(self)
8e5576
 
8e5576
-    cdef int is_active(self)
8e5576
+    cdef int is_active(self) noexcept
8e5576
 
8e5576
     cdef is_reading(self)
8e5576
     cdef is_writing(self)
8e5576
diff --git a/uvloop/handles/poll.pyx b/uvloop/handles/poll.pyx
8e5576
index fca5981e..c905e9b0 100644
8e5576
--- a/uvloop/handles/poll.pyx
8e5576
+++ b/uvloop/handles/poll.pyx
8e5576
@@ -29,7 +29,7 @@ cdef class UVPoll(UVHandle):
8e5576
         handle._init(loop, fd)
8e5576
         return handle
8e5576
 
8e5576
-    cdef int is_active(self):
8e5576
+    cdef int is_active(self) noexcept:
8e5576
         return (self.reading_handle is not None or
8e5576
                 self.writing_handle is not None)
8e5576
 
8e5576
diff --git a/uvloop/handles/stream.pyx b/uvloop/handles/stream.pyx
8e5576
index d4e02e3e..09df8878 100644
8e5576
--- a/uvloop/handles/stream.pyx
8e5576
+++ b/uvloop/handles/stream.pyx
8e5576
@@ -1,4 +1,8 @@
8e5576
-DEF __PREALLOCED_BUFS = 4
8e5576
+cdef extern from *:
8e5576
+    '''
8e5576
+    enum {__PREALLOCED_BUFS = 4};
8e5576
+    '''
8e5576
+    const bint __PREALLOCED_BUFS
8e5576
 
8e5576
 
8e5576
 @cython.no_gc_clear
8e5576
@@ -279,7 +283,7 @@ cdef class UVStream(UVBaseTransport):
8e5576
     cdef inline _close_on_read_error(self):
8e5576
         self.__read_error_close = 1
8e5576
 
8e5576
-    cdef bint _is_reading(self):
8e5576
+    cdef bint _is_reading(self) noexcept:
8e5576
         return self.__reading
8e5576
 
8e5576
     cdef _start_reading(self):
8e5576
@@ -578,7 +582,7 @@ cdef class UVStream(UVBaseTransport):
8e5576
 
8e5576
         self._maybe_resume_protocol()
8e5576
 
8e5576
-    cdef size_t _get_write_buffer_size(self):
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept:
8e5576
         if self._handle is NULL:
8e5576
             return 0
8e5576
         return ((<uv.uv_stream_t*>self._handle).write_queue_size +
8e5576
@@ -755,7 +759,7 @@ cdef inline bint __uv_stream_on_read_common(
8e5576
     UVStream sc,
8e5576
     Loop loop,
8e5576
     ssize_t nread,
8e5576
-):
8e5576
+) noexcept:
8e5576
     if sc._closed:
8e5576
         # The stream was closed, there is no reason to
8e5576
         # do any work now.
8e5576
@@ -818,7 +822,7 @@ cdef inline void __uv_stream_on_read_impl(
8e5576
     uv.uv_stream_t* stream,
8e5576
     ssize_t nread,
8e5576
     const uv.uv_buf_t* buf,
8e5576
-):
8e5576
+) noexcept:
8e5576
     cdef:
8e5576
         UVStream sc = <UVStream>stream.data
8e5576
         Loop loop = sc._loop
8e5576
@@ -849,7 +853,7 @@ cdef inline void __uv_stream_on_read_impl(
8e5576
 cdef inline void __uv_stream_on_write_impl(
8e5576
     uv.uv_write_t* req,
8e5576
     int status,
8e5576
-):
8e5576
+) noexcept:
8e5576
     cdef:
8e5576
         _StreamWriteContext ctx = <_StreamWriteContext> req.data
8e5576
         UVStream stream = <UVStream>ctx.stream
8e5576
diff --git a/uvloop/handles/udp.pyx b/uvloop/handles/udp.pyx
8e5576
index bbe60d56..fdd1d8b2 100644
8e5576
--- a/uvloop/handles/udp.pyx
8e5576
+++ b/uvloop/handles/udp.pyx
8e5576
@@ -127,12 +127,12 @@ cdef class UDPTransport(UVBaseTransport):
8e5576
             exc = convert_error(err)
8e5576
             raise exc
8e5576
 
8e5576
-    cdef size_t _get_write_buffer_size(self):
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept:
8e5576
         if self._handle is NULL:
8e5576
             return 0
8e5576
         return (<uv.uv_udp_t*>self._handle).send_queue_size
8e5576
 
8e5576
-    cdef bint _is_reading(self):
8e5576
+    cdef bint _is_reading(self) noexcept:
8e5576
         return self.__receiving
8e5576
 
8e5576
     cdef _start_reading(self):
8e5576
diff --git a/uvloop/includes/consts.pxi b/uvloop/includes/consts.pxi
8e5576
deleted file mode 100644
8e5576
index f765053d..00000000
8e5576
--- a/uvloop/includes/consts.pxi
8e5576
+++ /dev/null
8e5576
@@ -1,25 +0,0 @@
8e5576
-DEF UV_STREAM_RECV_BUF_SIZE = 256000  # 250kb
8e5576
-
8e5576
-DEF FLOW_CONTROL_HIGH_WATER = 64  # KiB
8e5576
-DEF FLOW_CONTROL_HIGH_WATER_SSL_READ = 256  # KiB
8e5576
-DEF FLOW_CONTROL_HIGH_WATER_SSL_WRITE = 512  # KiB
8e5576
-
8e5576
-DEF DEFAULT_FREELIST_SIZE = 250
8e5576
-DEF DNS_PYADDR_TO_SOCKADDR_CACHE_SIZE = 2048
8e5576
-
8e5576
-DEF DEBUG_STACK_DEPTH = 10
8e5576
-
8e5576
-
8e5576
-DEF __PROCESS_DEBUG_SLEEP_AFTER_FORK = 1
8e5576
-
8e5576
-
8e5576
-DEF LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5
8e5576
-
8e5576
-
8e5576
-# Number of seconds to wait for SSL handshake to complete
8e5576
-# The default timeout matches that of Nginx.
8e5576
-DEF SSL_HANDSHAKE_TIMEOUT = 60.0
8e5576
-# Number of seconds to wait for SSL shutdown to complete
8e5576
-# The default timeout mimics lingering_time
8e5576
-DEF SSL_SHUTDOWN_TIMEOUT = 30.0
8e5576
-DEF SSL_READ_MAX_SIZE = 256 * 1024
8e5576
diff --git a/uvloop/includes/fork_handler.h b/uvloop/includes/fork_handler.h
8e5576
index 47bbe036..9d3573ae 100644
8e5576
--- a/uvloop/includes/fork_handler.h
8e5576
+++ b/uvloop/includes/fork_handler.h
8e5576
@@ -1,7 +1,10 @@
8e5576
+#ifndef UVLOOP_FORK_HANDLER_H_
8e5576
+#define UVLOOP_FORK_HANDLER_H_
8e5576
+
8e5576
 volatile uint64_t MAIN_THREAD_ID = 0;
8e5576
 volatile int8_t MAIN_THREAD_ID_SET = 0;
8e5576
 
8e5576
-typedef void (*OnForkHandler)();
8e5576
+typedef void (*OnForkHandler)(void);
8e5576
 
8e5576
 OnForkHandler __forkHandler = NULL;
8e5576
 
8e5576
@@ -36,3 +39,4 @@ void setMainThreadID(uint64_t id) {
8e5576
     MAIN_THREAD_ID = id;
8e5576
     MAIN_THREAD_ID_SET = 1;
8e5576
 }
8e5576
+#endif
8e5576
diff --git a/uvloop/includes/system.h b/uvloop/includes/system.h
8e5576
new file mode 100755
8e5576
index 00000000..e143bb5c
8e5576
--- /dev/null
8e5576
+++ b/uvloop/includes/system.h
8e5576
@@ -0,0 +1,16 @@
8e5576
+#ifndef UVLOOP_SYSTEM_H_
8e5576
+#define UVLOOP_SYSTEM_H_
8e5576
+#if defined(_WIN32) || defined(MS_WINDOWS) || defined(_MSC_VER)
8e5576
+#include "Winsock2.h"
8e5576
+#include "ws2def.h"
8e5576
+#include "includes/fork_handler.h"
8e5576
+#else
8e5576
+#include "arpa/inet.h"
8e5576
+#include "sys/socket.h"
8e5576
+#include "sys/un.h"
8e5576
+#include "unistd.h"
8e5576
+#include "pthread.h"
8e5576
+#endif
8e5576
+#endif
8e5576
+
8e5576
+
8e5576
diff --git a/uvloop/includes/system.pxd b/uvloop/includes/system.pxd
8e5576
index 367fedd1..d1da74ed 100644
8e5576
--- a/uvloop/includes/system.pxd
8e5576
+++ b/uvloop/includes/system.pxd
8e5576
@@ -1,13 +1,9 @@
8e5576
 from libc.stdint cimport int8_t, uint64_t
8e5576
 
8e5576
-cdef extern from "arpa/inet.h" nogil:
8e5576
-
8e5576
-    int ntohl(int)
8e5576
-    int htonl(int)
8e5576
-    int ntohs(int)
8e5576
-
8e5576
-
8e5576
-cdef extern from "sys/socket.h" nogil:
8e5576
+cdef extern from "includes/system.h":
8e5576
+    int ntohl(int) nogil
8e5576
+    int htonl(int) nogil
8e5576
+    int ntohs(int) nogil
8e5576
 
8e5576
     struct sockaddr:
8e5576
         unsigned short sa_family
8e5576
diff --git a/uvloop/includes/uv.pxd b/uvloop/includes/uv.pxd
8e5576
index 87651306..ddd9738c 100644
8e5576
--- a/uvloop/includes/uv.pxd
8e5576
+++ b/uvloop/includes/uv.pxd
8e5576
@@ -220,7 +220,7 @@ cdef extern from "uv.h" nogil:
8e5576
         UV_LEAVE_GROUP = 0,
8e5576
         UV_JOIN_GROUP
8e5576
 
8e5576
-    cpdef enum uv_fs_event:
8e5576
+    cdef enum uv_fs_event:
8e5576
         UV_RENAME = 1,
8e5576
         UV_CHANGE = 2
8e5576
 
8e5576
@@ -282,7 +282,7 @@ cdef extern from "uv.h" nogil:
8e5576
     int uv_loop_close(uv_loop_t* loop)
8e5576
     int uv_loop_alive(uv_loop_t* loop)
8e5576
     int uv_loop_fork(uv_loop_t* loop)
8e5576
-    int uv_backend_fd(uv_loop_t* loop)
8e5576
+    uv_os_fd_t uv_backend_fd(uv_loop_t* loop)
8e5576
 
8e5576
     void uv_update_time(uv_loop_t* loop)
8e5576
     uint64_t uv_now(const uv_loop_t*)
8e5576
@@ -378,7 +378,7 @@ cdef extern from "uv.h" nogil:
8e5576
     # Pipes
8e5576
 
8e5576
     int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc)
8e5576
-    int uv_pipe_open(uv_pipe_t* handle, uv_file file)
8e5576
+    int uv_pipe_open(uv_pipe_t* handle, uv_os_fd_t file)
8e5576
     int uv_pipe_bind(uv_pipe_t* handle, const char* name)
8e5576
 
8e5576
     void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
8e5576
diff --git a/uvloop/loop.pxd b/uvloop/loop.pxd
8e5576
index 56134733..f90c7041 100644
8e5576
--- a/uvloop/loop.pxd
8e5576
+++ b/uvloop/loop.pxd
8e5576
@@ -1,15 +1,35 @@
8e5576
 # cython: language_level=3
8e5576
 
8e5576
+cdef extern from *:
8e5576
+    '''
8e5576
+    enum { UV_STREAM_RECV_BUF_SIZE = 256000,
8e5576
+           SSL_READ_MAX_SIZE = 256 * 1024,  // 250kb
8e5576
+          };
8e5576
+    const float SSL_HANDSHAKE_TIMEOUT = 60.0; // Number of seconds to wait for SSL handshake to complete The default timeout matches that of Nginx.
8e5576
+    const float SSL_SHUTDOWN_TIMEOUT  = 30.0; // Number of seconds to wait for SSL shutdown to complete The default timeout mimics lingering_time
8e5576
+    '''
8e5576
+    const bint UV_STREAM_RECV_BUF_SIZE
8e5576
+    const bint SSL_READ_MAX_SIZE
8e5576
+
8e5576
+    const float SSL_HANDSHAKE_TIMEOUT
8e5576
+    const float SSL_SHUTDOWN_TIMEOUT
8e5576
+
8e5576
+cdef enum:
8e5576
+    FLOW_CONTROL_HIGH_WATER = 64  # KiB
8e5576
+    FLOW_CONTROL_HIGH_WATER_SSL_READ = 256  # KiB
8e5576
+    FLOW_CONTROL_HIGH_WATER_SSL_WRITE = 512  # KiB
8e5576
+
8e5576
+    DNS_PYADDR_TO_SOCKADDR_CACHE_SIZE = 2048
8e5576
+    DEBUG_STACK_DEPTH = 10
8e5576
+    __PROCESS_DEBUG_SLEEP_AFTER_FORK = 1
8e5576
+    LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5
8e5576
+
8e5576
 
8e5576
 from .includes cimport uv
8e5576
 from .includes cimport system
8e5576
 
8e5576
 from libc.stdint cimport uint64_t, uint32_t, int64_t
8e5576
 
8e5576
-
8e5576
-include "includes/consts.pxi"
8e5576
-
8e5576
-
8e5576
 cdef extern from *:
8e5576
     ctypedef int vint "volatile int"
8e5576
 
8e5576
diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx
8e5576
index 334d8d50..53e11600 100644
8e5576
--- a/uvloop/loop.pyx
8e5576
+++ b/uvloop/loop.pyx
8e5576
@@ -43,7 +43,7 @@ from cpython.pycapsule cimport PyCapsule_New, PyCapsule_GetPointer
8e5576
 from . import _noop
8e5576
 
8e5576
 
8e5576
-include "includes/consts.pxi"
8e5576
+
8e5576
 include "includes/stdlib.pxi"
8e5576
 
8e5576
 include "errors.pyx"
8e5576
@@ -1118,7 +1118,7 @@ cdef class Loop:
8e5576
 
8e5576
     cdef _sock_set_reuseport(self, int fd):
8e5576
         cdef:
8e5576
-            int err
8e5576
+            int err = 0
8e5576
             int reuseport_flag = 1
8e5576
 
8e5576
         err = system.setsockopt(
8e5576
@@ -1397,7 +1397,7 @@ cdef class Loop:
8e5576
         self._debug = bool(enabled)
8e5576
         if self.is_running():
8e5576
             self.call_soon_threadsafe(
8e5576
-                self._set_coroutine_debug, self, self._debug)
8e5576
+                self._set_coroutine_debug, self._debug)
8e5576
 
8e5576
     def is_running(self):
8e5576
         """Return whether the event loop is currently running."""
8e5576
@@ -2750,7 +2750,7 @@ cdef class Loop:
8e5576
                                executable=None,
8e5576
                                pass_fds=(),
8e5576
                                # For tests only! Do not use in your code. Ever.
8e5576
-                               __uvloop_sleep_after_fork=False):
8e5576
+                               uvloop_sleep_after_fork=False):
8e5576
 
8e5576
         # TODO: Implement close_fds (might not be very important in
8e5576
         # Python 3.5, since all FDs aren't inheritable by default.)
8e5576
@@ -2770,7 +2770,7 @@ cdef class Loop:
8e5576
         if executable is not None:
8e5576
             args[0] = executable
8e5576
 
8e5576
-        if __uvloop_sleep_after_fork:
8e5576
+        if uvloop_sleep_after_fork:
8e5576
             debug_flags |= __PROCESS_DEBUG_SLEEP_AFTER_FORK
8e5576
 
8e5576
         waiter = self._new_future()
8e5576
diff --git a/uvloop/sslproto.pxd b/uvloop/sslproto.pxd
8e5576
index 3da10f00..68e4d572 100644
8e5576
--- a/uvloop/sslproto.pxd
8e5576
+++ b/uvloop/sslproto.pxd
8e5576
@@ -122,7 +122,7 @@ cdef class SSLProtocol:
8e5576
     # Flow control for writes from APP socket
8e5576
 
8e5576
     cdef _control_app_writing(self, object context=*)
8e5576
-    cdef size_t _get_write_buffer_size(self)
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept
8e5576
     cdef _set_write_buffer_limits(self, high=*, low=*)
8e5576
 
8e5576
     # Flow control for reads to APP socket
8e5576
@@ -134,5 +134,5 @@ cdef class SSLProtocol:
8e5576
 
8e5576
     cdef _control_ssl_reading(self)
8e5576
     cdef _set_read_buffer_limits(self, high=*, low=*)
8e5576
-    cdef size_t _get_read_buffer_size(self)
8e5576
+    cdef size_t _get_read_buffer_size(self) noexcept
8e5576
     cdef _fatal_error(self, exc, message=*)
8e5576
diff --git a/uvloop/sslproto.pyx b/uvloop/sslproto.pyx
8e5576
index 42bb7644..0a437463 100644
8e5576
--- a/uvloop/sslproto.pyx
8e5576
+++ b/uvloop/sslproto.pyx
8e5576
@@ -861,7 +861,7 @@ cdef class SSLProtocol:
8e5576
                     'protocol': self,
8e5576
                 })
8e5576
 
8e5576
-    cdef size_t _get_write_buffer_size(self):
8e5576
+    cdef size_t _get_write_buffer_size(self) noexcept:
8e5576
         return self._outgoing.pending + self._write_buffer_size
8e5576
 
8e5576
     cdef _set_write_buffer_limits(self, high=None, low=None):
8e5576
@@ -903,7 +903,7 @@ cdef class SSLProtocol:
8e5576
         self._incoming_high_water = high
8e5576
         self._incoming_low_water = low
8e5576
 
8e5576
-    cdef size_t _get_read_buffer_size(self):
8e5576
+    cdef size_t _get_read_buffer_size(self) noexcept:
8e5576
         return self._incoming.pending
8e5576
 
8e5576
     # Flow control for writes to SSL socket
8e5576
8e5576
From 55bab4f7486d9b58ecc4f81120f8f8eaf1099cdd Mon Sep 17 00:00:00 2001
8e5576
From: Alan Brooks <12380017+alan-brooks@users.noreply.github.com>
8e5576
Date: Thu, 28 Dec 2023 16:17:49 +0000
8e5576
Subject: [PATCH 2/4] _set_coroutine_debug has args difference in python 3.11
8e5576
8e5576
---
8e5576
 uvloop/loop.pyx | 3 ++-
8e5576
 1 file changed, 2 insertions(+), 1 deletion(-)
8e5576
8e5576
diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx
8e5576
index 53e11600..5ca718e4 100644
8e5576
--- a/uvloop/loop.pyx
8e5576
+++ b/uvloop/loop.pyx
8e5576
@@ -1396,8 +1396,9 @@ cdef class Loop:
8e5576
     def set_debug(self, enabled):
8e5576
         self._debug = bool(enabled)
8e5576
         if self.is_running():
8e5576
+            args = (self, self._debug) if sys.version_info < (3, 11) else (self._debug,)
8e5576
             self.call_soon_threadsafe(
8e5576
-                self._set_coroutine_debug, self._debug)
8e5576
+                self._set_coroutine_debug, *args)
8e5576
 
8e5576
     def is_running(self):
8e5576
         """Return whether the event loop is currently running."""
8e5576
8e5576
From 95a147f79e1d3685b8f91ddae8a382f4668af27a Mon Sep 17 00:00:00 2001
8e5576
From: alan-brooks <12380017+alan-brooks@users.noreply.github.com>
8e5576
Date: Thu, 28 Dec 2023 19:58:11 +0000
8e5576
Subject: [PATCH 3/4] fix tests on python 3.8
8e5576
8e5576
---
8e5576
 uvloop/loop.pyx | 5 ++---
8e5576
 1 file changed, 2 insertions(+), 3 deletions(-)
8e5576
8e5576
diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx
8e5576
index 5ca718e4..75b915a9 100644
8e5576
--- a/uvloop/loop.pyx
8e5576
+++ b/uvloop/loop.pyx
8e5576
@@ -1396,9 +1396,8 @@ cdef class Loop:
8e5576
     def set_debug(self, enabled):
8e5576
         self._debug = bool(enabled)
8e5576
         if self.is_running():
8e5576
-            args = (self, self._debug) if sys.version_info < (3, 11) else (self._debug,)
8e5576
-            self.call_soon_threadsafe(
8e5576
-                self._set_coroutine_debug, *args)
8e5576
+            args = ((self, self._debug),) if sys.version_info < (3, 11) else (self._debug,)
8e5576
+            self.call_soon_threadsafe(self._set_coroutine_debug, *args)
8e5576
 
8e5576
     def is_running(self):
8e5576
         """Return whether the event loop is currently running."""
8e5576
8e5576
From ca06a743c4472c3629610664760d4538283aebf9 Mon Sep 17 00:00:00 2001
8e5576
From: alan-brooks <12380017+alan-brooks@users.noreply.github.com>
8e5576
Date: Fri, 29 Dec 2023 11:24:19 +0000
8e5576
Subject: [PATCH 4/4] fix arg count for wrap()
8e5576
8e5576
---
8e5576
 uvloop/loop.pxd | 2 +-
8e5576
 uvloop/loop.pyx | 5 ++---
8e5576
 2 files changed, 3 insertions(+), 4 deletions(-)
8e5576
8e5576
diff --git a/uvloop/loop.pxd b/uvloop/loop.pxd
8e5576
index f90c7041..d34ffeb8 100644
8e5576
--- a/uvloop/loop.pxd
8e5576
+++ b/uvloop/loop.pxd
8e5576
@@ -220,7 +220,7 @@ cdef class Loop:
8e5576
     cdef inline _ceval_process_signals(self)
8e5576
     cdef _invoke_signals(self, bytes data)
8e5576
 
8e5576
-    cdef _set_coroutine_debug(self, bint enabled)
8e5576
+    cpdef _set_coroutine_debug(self, bint enabled)
8e5576
 
8e5576
     cdef _print_debug_info(self)
8e5576
 
8e5576
diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx
8e5576
index 75b915a9..a3eeb605 100644
8e5576
--- a/uvloop/loop.pyx
8e5576
+++ b/uvloop/loop.pyx
8e5576
@@ -1131,7 +1131,7 @@ cdef class Loop:
8e5576
         if err < 0:
8e5576
             raise convert_error(-errno.errno)
8e5576
 
8e5576
-    cdef _set_coroutine_debug(self, bint enabled):
8e5576
+    cpdef _set_coroutine_debug(self, bint enabled):
8e5576
         enabled = bool(enabled)
8e5576
         if self._coroutine_debug_set == enabled:
8e5576
             return
8e5576
@@ -1396,8 +1396,7 @@ cdef class Loop:
8e5576
     def set_debug(self, enabled):
8e5576
         self._debug = bool(enabled)
8e5576
         if self.is_running():
8e5576
-            args = ((self, self._debug),) if sys.version_info < (3, 11) else (self._debug,)
8e5576
-            self.call_soon_threadsafe(self._set_coroutine_debug, *args)
8e5576
+             self.call_soon_threadsafe(self._set_coroutine_debug, self._debug)
8e5576
 
8e5576
     def is_running(self):
8e5576
         """Return whether the event loop is currently running."""