static int SignalChecker_tp_init(SignalChecker *self, PyObject *args, PyObject *kwargs) { int err; long fd; Loop *loop; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!l:__init__", &LoopType, &loop, &fd)) { return -1; } err = uv_poll_init_socket(loop->uv_loop, &self->poll_h, (uv_os_sock_t)fd); if (err < 0) { RAISE_UV_EXCEPTION(err, PyExc_UVError); return -1; } self->fd = fd; initialize_handle(HANDLE(self), loop); return 0; }
static int Pipe_tp_init(Pipe *self, PyObject *args, PyObject *kwargs) { int err; Loop *loop; PyObject *ipc = Py_False; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!|O!:__init__", &LoopType, &loop, &PyBool_Type, &ipc)) { return -1; } err = uv_pipe_init(loop->uv_loop, &self->pipe_h, (ipc == Py_True) ? 1 : 0); if (err < 0) { RAISE_UV_EXCEPTION(err, PyExc_PipeError); return -1; } initialize_handle(HANDLE(self), loop); return 0; }
static int Async_tp_init(Async *self, PyObject *args, PyObject *kwargs) { int r; Loop *loop; PyObject *callback, *tmp; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!O:__init__", &LoopType, &loop, &callback)) { return -1; } if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "a callable is required"); return -1; } r = uv_async_init(loop->uv_loop, (uv_async_t *)UV_HANDLE(self), on_async_callback); if (r != 0) { RAISE_UV_EXCEPTION(loop->uv_loop, PyExc_AsyncError); return -1; } tmp = self->callback; Py_INCREF(callback); self->callback = callback; Py_XDECREF(tmp); initialize_handle(HANDLE(self), loop); return 0; }
static int Process_tp_init(Process *self, PyObject *args, PyObject *kwargs) { Loop *loop; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) { return -1; } initialize_handle(HANDLE(self), loop); /* uv_process_t handles are not initialized explicitly, so workaround it. See tp_dealloc for the rest */ HANDLE(self)->initialized = False; return 0; }
static int UDP_tp_init(UDP *self, PyObject *args, PyObject *kwargs) { int r; Loop *loop; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) { return -1; } r = uv_udp_init(loop->uv_loop, (uv_udp_t *)UV_HANDLE(self)); if (r != 0) { RAISE_UV_EXCEPTION(loop->uv_loop, PyExc_UDPError); return -1; } initialize_handle(HANDLE(self), loop); return 0; }
static int Timer_tp_init(Timer *self, PyObject *args, PyObject *kwargs) { int err; Loop *loop; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!:__init__", &LoopType, &loop)) { return -1; } err = uv_timer_init(loop->uv_loop, &self->timer_h); if (err < 0) { RAISE_UV_EXCEPTION(err, PyExc_TimerError); return -1; } initialize_handle(HANDLE(self), loop); return 0; }
static PyObject * Pipe_func_write2(Pipe *self, PyObject *args) { uv_buf_t buf; Py_buffer *view; PyObject *callback, *send_handle; callback = Py_None; RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL); RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL); view = PyMem_Malloc(sizeof *view); if (!view) { PyErr_NoMemory(); return NULL; } #ifdef PYUV_PYTHON3 if (!PyArg_ParseTuple(args, "y*O|O:write", view, &send_handle, &callback)) { #else if (!PyArg_ParseTuple(args, "s*O|O:write", view, &send_handle, &callback)) { #endif return NULL; } if (PyObject_IsSubclass((PyObject *)send_handle->ob_type, (PyObject *)&StreamType)) { if (UV_HANDLE(send_handle)->type != UV_TCP && UV_HANDLE(send_handle)->type != UV_NAMED_PIPE) { PyErr_SetString(PyExc_TypeError, "Only TCP and Pipe objects are supported for write2"); goto error; } } else if (PyObject_IsSubclass((PyObject *)send_handle->ob_type, (PyObject *)&UDPType)) { /* empty */ } else { PyErr_SetString(PyExc_TypeError, "Only Stream and UDP objects are supported"); goto error; } if (callback != Py_None && !PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "a callable or None is required"); goto error; } buf = uv_buf_init(view->buf, view->len); return pyuv_stream_write((Stream *)self, view, &buf, 1, callback, send_handle); error: PyBuffer_Release(view); PyMem_Free(view); return NULL; } static int Pipe_tp_init(Pipe *self, PyObject *args, PyObject *kwargs) { int r; Loop *loop; PyObject *ipc = Py_False; UNUSED_ARG(kwargs); RAISE_IF_HANDLE_INITIALIZED(self, -1); if (!PyArg_ParseTuple(args, "O!|O!:__init__", &LoopType, &loop, &PyBool_Type, &ipc)) { return -1; } r = uv_pipe_init(loop->uv_loop, (uv_pipe_t *)UV_HANDLE(self), (ipc == Py_True) ? 1 : 0); if (r != 0) { RAISE_UV_EXCEPTION(loop->uv_loop, PyExc_PipeError); return -1; } initialize_handle(HANDLE(self), loop); return 0; }