Skip to content
Prev Previous commit
Next Next commit
Support a timeout arg.
  • Loading branch information
ericsnowcurrently committed Oct 17, 2023
commit 21d85dd7af6908b65e909a1c0afd371d8d1c4da8
33 changes: 20 additions & 13 deletions Modules/_xxinterpchannelsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2816,21 +2816,24 @@ receive end.");
static PyObject *
channel_send(PyObject *self, PyObject *args, PyObject *kwds)
{
// XXX Add a timeout arg.
static char *kwlist[] = {"cid", "obj", "blocking", NULL};
int64_t cid;
static char *kwlist[] = {"cid", "obj", "blocking", "timeout", NULL};
struct channel_id_converter_data cid_data = {
.module = self,
};
PyObject *obj;
int blocking = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|$p:channel_send", kwlist,
PyObject *timeout_obj = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&O|$pO:channel_send", kwlist,
channel_id_converter, &cid_data, &obj,
&blocking)) {
&blocking, &timeout_obj)) {
return NULL;
}

int64_t cid = cid_data.cid;
PY_TIMEOUT_T timeout;
if (PyThread_ParseTimeoutArg(timeout_obj, blocking, &timeout) < 0) {
return NULL;
}
cid = cid_data.cid;
PY_TIMEOUT_T timeout = PyThread_UNSET_TIMEOUT;

/* Queue up the object. */
int err = 0;
Expand All @@ -2856,21 +2859,25 @@ By default this waits for the object to be received.");
static PyObject *
channel_send_buffer(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"cid", "obj", "blocking", NULL};
int64_t cid;
static char *kwlist[] = {"cid", "obj", "blocking", "timeout", NULL};
struct channel_id_converter_data cid_data = {
.module = self,
};
PyObject *obj;
int blocking = 1;
PyObject *timeout_obj = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O&O|$p:channel_send_buffer", kwlist,
"O&O|$pO:channel_send_buffer", kwlist,
channel_id_converter, &cid_data, &obj,
&blocking)) {
&blocking, &timeout_obj)) {
return NULL;
}

int64_t cid = cid_data.cid;
PY_TIMEOUT_T timeout;
if (PyThread_ParseTimeoutArg(timeout_obj, blocking, &timeout) < 0) {
return NULL;
}
cid = cid_data.cid;
PY_TIMEOUT_T timeout = PyThread_UNSET_TIMEOUT;

PyObject *tempobj = PyMemoryView_FromObject(obj);
if (tempobj == NULL) {
Expand Down