cdef object WAIT_W = Wait.W
cdef object WAIT_R = Wait.R
cdef object WAIT_RW = Wait.RW
+cdef object PY_READY_R = Ready.R
+cdef object PY_READY_W = Ready.W
+cdef object PY_READY_RW = Ready.RW
cdef int READY_R = Ready.R
cdef int READY_W = Ready.W
+cdef int READY_RW = Ready.RW
def connect(conninfo: str) -> PQGenConn[abc.PGconn]:
"""
# Copyright (C) 2022 The Psycopg Team
+from cpython.object cimport PyObject_CallFunctionObjArgs
+
cdef extern from *:
"""
#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL)
}
"""
- const int SELECT_EV_READ
- const int SELECT_EV_WRITE
cdef int wait_c_impl(int fileno, int wait, float timeout) except -1
"""
cdef float ctimeout
cdef int wait, ready
+ cdef PyObject *pyready
- if timeout is None or timeout < 0:
+ if timeout is None:
ctimeout = -1.0
else:
ctimeout = float(timeout)
+ if ctimeout < 0.0:
+ ctimeout = -1.0
+
+ send = gen.send
try:
wait = next(gen)
ready = wait_c_impl(fileno, wait, ctimeout)
if ready == 0:
continue
-
- wait = gen.send(ready)
+ elif ready == READY_R:
+ pyready = <PyObject *>PY_READY_R
+ elif ready == READY_RW:
+ pyready = <PyObject *>PY_READY_RW
+ elif ready == READY_W:
+ pyready = <PyObject *>PY_READY_W
+ else:
+ raise AssertionError(f"unexpected ready value: {ready}")
+
+ wait = PyObject_CallFunctionObjArgs(send, pyready, NULL)
except StopIteration as ex:
rv: RV = ex.args[0] if ex.args else None