当前位置: 首页>>代码示例>>C++>>正文


C++ UV_HANDLE函数代码示例

本文整理汇总了C++中UV_HANDLE函数的典型用法代码示例。如果您正苦于以下问题:C++ UV_HANDLE函数的具体用法?C++ UV_HANDLE怎么用?C++ UV_HANDLE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了UV_HANDLE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Pipe_func_accept

static PyObject *
Pipe_func_accept(Pipe *self, PyObject *args)
{
    int r;
    PyObject *client;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:accept", &client)) {
        return NULL;
    }

    if (PyObject_IsSubclass((PyObject *)client->ob_type, (PyObject *)&StreamType)) {
        if (UV_HANDLE(client)->type != UV_TCP && UV_HANDLE(client)->type != UV_NAMED_PIPE) {
            PyErr_SetString(PyExc_TypeError, "Only TCP and Pipe objects are supported for accept");
            return NULL;
        }
    } else if (PyObject_IsSubclass((PyObject *)client->ob_type, (PyObject *)&UDPType)) {
        /* empty */
    } else {
        PyErr_SetString(PyExc_TypeError, "Only Stream and UDP objects are supported for accept");
        return NULL;
    }

    r = uv_accept((uv_stream_t *)UV_HANDLE(self), (uv_stream_t *)UV_HANDLE(client));
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_PipeError);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:ayanamist,项目名称:pyuv,代码行数:33,代码来源:pipe.c

示例2: UDP_func_bind

static PyObject *
UDP_func_bind(UDP *self, PyObject *args)
{
    int r, bind_port, address_type;
    char *bind_ip;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "(si):bind", &bind_ip, &bind_port)) {
        return NULL;
    }

    if (bind_port < 0 || bind_port > 65535) {
        PyErr_SetString(PyExc_ValueError, "port must be between 0 and 65535");
        return NULL;
    }

    if (pyuv_guess_ip_family(bind_ip, &address_type)) {
        PyErr_SetString(PyExc_ValueError, "invalid IP address");
        return NULL;
    }

    if (address_type == AF_INET) {
        r = uv_udp_bind((uv_udp_t *)UV_HANDLE(self), uv_ip4_addr(bind_ip, bind_port), 0);
    } else {
        r = uv_udp_bind6((uv_udp_t *)UV_HANDLE(self), uv_ip6_addr(bind_ip, bind_port), UV_UDP_IPV6ONLY);
    }

    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_UDPError);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:jppommet,项目名称:pyuv,代码行数:35,代码来源:udp.c

示例3: Stream_func_start_read

static PyObject *
Stream_func_start_read(Stream *self, PyObject *args)
{
    int err;
    PyObject *tmp, *callback;

    tmp = NULL;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:start_read", &callback)) {
        return NULL;
    }

    if (!PyCallable_Check(callback)) {
        PyErr_SetString(PyExc_TypeError, "a callable is required");
        return NULL;
    }

    err = uv_read_start((uv_stream_t *)UV_HANDLE(self), (uv_alloc_cb)pyuv__alloc_cb, (uv_read_cb)pyuv__stream_read_cb);
    if (err < 0) {
        RAISE_STREAM_EXCEPTION(err, UV_HANDLE(self));
        return NULL;
    }

    tmp = self->on_read_cb;
    Py_INCREF(callback);
    self->on_read_cb = callback;
    Py_XDECREF(tmp);

    PYUV_HANDLE_INCREF(self);

    Py_RETURN_NONE;
}
开发者ID:ConchLikeSun,项目名称:pyuv,代码行数:35,代码来源:stream.c

示例4: Stream_func_try_write

static PyObject *
Stream_func_try_write(Stream *self, PyObject *args)
{
    int err;
    uv_buf_t buf;
    Py_buffer view;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, PYUV_BYTES"*:try_write", &view)) {
        return NULL;
    }

    buf = uv_buf_init(view.buf, view.len);
    err = uv_try_write((uv_stream_t *)UV_HANDLE(self), &buf, 1);
    if (err < 0) {
        RAISE_STREAM_EXCEPTION(err, UV_HANDLE(self));
        PyBuffer_Release(&view);
        return NULL;
    }

    PyBuffer_Release(&view);
    return PyInt_FromLong((long)err);
}
开发者ID:ConchLikeSun,项目名称:pyuv,代码行数:25,代码来源:stream.c

示例5: Pipe_func_accept

static PyObject *
Pipe_func_accept(Pipe *self, PyObject *args)
{
    int r;
    PyObject *client;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:accept", &client)) {
        return NULL;
    }

    if (!PyObject_IsSubclass((PyObject *)client->ob_type, (PyObject *)&StreamType)) {
        PyErr_SetString(PyExc_TypeError, "Only stream objects are supported for accept");
        return NULL;
    }

    r = uv_accept((uv_stream_t *)UV_HANDLE(self), (uv_stream_t *)UV_HANDLE(client));
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_PipeError);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:tempbottle,项目名称:pyuv,代码行数:25,代码来源:pipe.c

示例6: Pipe_func_write2

static PyObject *
Pipe_func_write2(Pipe *self, PyObject *args)
{
    uv_buf_t buf;
    stream_write_ctx *ctx;
    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);

    ctx = PyMem_Malloc(sizeof *ctx);
    if (!ctx) {
        PyErr_NoMemory();
        return NULL;
    }

    view = &ctx->view[0];

    if (!PyArg_ParseTuple(args, PYUV_BYTES"*O|O:write", view, &send_handle, &callback)) {
        PyMem_Free(ctx);
        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, ctx, view, &buf, 1, callback, send_handle);

error:
        PyBuffer_Release(view);
        PyMem_Free(ctx);
        return NULL;
}
开发者ID:imclab,项目名称:pyuv,代码行数:52,代码来源:pipe.c

示例7: pyuv__stream_write_bytes

static PyObject *
pyuv__stream_write_bytes(Stream *self, PyObject *data, PyObject *callback, PyObject *send_handle)
{
    int err;
    uv_buf_t buf;
    stream_write_ctx *ctx;
    Py_buffer *view;

    ctx = PyMem_Malloc(sizeof *ctx);
    if (!ctx) {
        PyErr_NoMemory();
        return NULL;
    }

    ctx->views = ctx->viewsml;
    view = &ctx->views[0];

    if (PyObject_GetBuffer(data, view, PyBUF_SIMPLE) != 0) {
        PyMem_Free(ctx);
        return NULL;
    }

    ctx->view_count = 1;
    ctx->obj = self;
    ctx->callback = callback;
    ctx->send_handle = send_handle;

    Py_INCREF(callback);
    Py_XINCREF(send_handle);

    buf = uv_buf_init(view->buf, view->len);
    if (send_handle != NULL) {
        ASSERT(UV_HANDLE(self)->type == UV_NAMED_PIPE);
        err = uv_write2(&ctx->req, (uv_stream_t *)UV_HANDLE(self), &buf, 1, (uv_stream_t *)UV_HANDLE(send_handle), pyuv__stream_write_cb);
    } else {
        err = uv_write(&ctx->req, (uv_stream_t *)UV_HANDLE(self), &buf, 1, pyuv__stream_write_cb);
    }

    if (err < 0) {
        RAISE_STREAM_EXCEPTION(err, UV_HANDLE(self));
        Py_DECREF(callback);
        Py_XDECREF(send_handle);
        PyBuffer_Release(view);
        PyMem_Free(ctx);
        return NULL;
    }

    /* Increase refcount so that object is not removed before the callback is called */
    Py_INCREF(self);

    Py_RETURN_NONE;
}
开发者ID:ConchLikeSun,项目名称:pyuv,代码行数:52,代码来源:stream.c

示例8: Timer_repeat_set

static int
Timer_repeat_set(Timer *self, PyObject *value, void *closure)
{
    double repeat;

    UNUSED_ARG(closure);

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, -1);

    if (!value) {
        PyErr_SetString(PyExc_TypeError, "cannot delete attribute");
        return -1;
    }

    repeat = PyFloat_AsDouble(value);
    if (repeat == -1 && PyErr_Occurred()) {
        return -1;
    }

    if (repeat < 0.0) {
        PyErr_SetString(PyExc_ValueError, "a positive float or 0.0 is required");
        return -1;
    }

    uv_timer_set_repeat((uv_timer_t *)UV_HANDLE(self), (int64_t)(repeat * 1000));

    return 0;
}
开发者ID:SongJLG,项目名称:johan-doc,代码行数:28,代码来源:timer.c

示例9: Timer_repeat_get

static PyObject *
Timer_repeat_get(Timer *self, void *closure)
{
    UNUSED_ARG(closure);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);
    return PyFloat_FromDouble(uv_timer_get_repeat((uv_timer_t *)UV_HANDLE(self))/1000.0);
}
开发者ID:SongJLG,项目名称:johan-doc,代码行数:7,代码来源:timer.c

示例10: Check_func_start

static PyObject *
Check_func_start(Check *self, PyObject *args)
{
    int r;
    PyObject *tmp, *callback;

    tmp = NULL;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:start", &callback)) {
        return NULL;
    }

    if (!PyCallable_Check(callback)) {
        PyErr_SetString(PyExc_TypeError, "a callable is required");
        return NULL;
    }

    r = uv_check_start((uv_check_t *)UV_HANDLE(self), on_check_callback);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_CheckError);
        return NULL;
    }

    tmp = self->callback;
    Py_INCREF(callback);
    self->callback = callback;
    Py_XDECREF(tmp);

    Py_RETURN_NONE;
}
开发者ID:ayanamist,项目名称:pyuv,代码行数:33,代码来源:check.c

示例11: Signal_func_start

static PyObject *
Signal_func_start(Signal *self, PyObject *args)
{
    int r, signum;
    PyObject *tmp, *callback;

    tmp = NULL;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "Oi:start", &callback, &signum)) {
        return NULL;
    }

    if (!PyCallable_Check(callback)) {
        PyErr_SetString(PyExc_TypeError, "a callable is required");
        return NULL;
    }

    r = uv_signal_start((uv_signal_t *)UV_HANDLE(self), (uv_signal_cb)on_signal_callback, signum);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_SignalError);
        return NULL;
    }

    tmp = self->callback;
    Py_INCREF(callback);
    self->callback = callback;
    Py_XDECREF(tmp);

    Py_RETURN_NONE;
}
开发者ID:jppommet,项目名称:pyuv,代码行数:32,代码来源:signal.c

示例12: TCP_func_accept

static PyObject *
TCP_func_accept(TCP *self, PyObject *args)
{
    int err;
    PyObject *client;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:accept", &client)) {
        return NULL;
    }

    if (!PyObject_IsSubclass((PyObject *)client->ob_type, (PyObject *)&StreamType)) {
        PyErr_SetString(PyExc_TypeError, "Only stream objects are supported for accept");
        return NULL;
    }

    err = uv_accept((uv_stream_t *)&self->tcp_h, (uv_stream_t *)UV_HANDLE(client));
    if (err < 0) {
        RAISE_UV_EXCEPTION(err, PyExc_TCPError);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:idobatter,项目名称:pyuv,代码行数:26,代码来源:tcp.c

示例13: Pipe_func_start_read2

static PyObject *
Pipe_func_start_read2(Pipe *self, PyObject *args)
{
    int r;
    PyObject *tmp, *callback;

    tmp = NULL;

    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "O:start_read2", &callback)) {
        return NULL;
    }

    if (!PyCallable_Check(callback)) {
        PyErr_SetString(PyExc_TypeError, "a callable is required");
        return NULL;
    }

    r = uv_read2_start((uv_stream_t *)UV_HANDLE(self), (uv_alloc_cb)on_stream_alloc, (uv_read2_cb)on_pipe_read2);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_PipeError);
        return NULL;
    }

    tmp = ((Stream *)self)->on_read_cb;
    Py_INCREF(callback);
    ((Stream *)self)->on_read_cb = callback;
    Py_XDECREF(tmp);

    Py_RETURN_NONE;
}
开发者ID:tempbottle,项目名称:pyuv,代码行数:32,代码来源:pipe.c

示例14: UDP_func_set_ttl

static PyObject *
UDP_func_set_ttl(UDP *self, PyObject *args)
{
    int r, ttl;

    RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL);
    RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL);

    if (!PyArg_ParseTuple(args, "i:set_multicast_ttl", &ttl)) {
        return NULL;
    }

    if (ttl < 0 || ttl > 255) {
        PyErr_SetString(PyExc_ValueError, "ttl must be between 0 and 255");
        return NULL;
    }

    r = uv_udp_set_ttl((uv_udp_t *)UV_HANDLE(self), ttl);
    if (r != 0) {
        RAISE_UV_EXCEPTION(UV_HANDLE_LOOP(self), PyExc_UDPError);
        return NULL;
    }

    Py_RETURN_NONE;
}
开发者ID:ayanamist,项目名称:pyuv,代码行数:25,代码来源:udp.c

示例15: Async_tp_init

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;
}
开发者ID:ayanamist,项目名称:pyuv,代码行数:35,代码来源:async.c


注:本文中的UV_HANDLE函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。