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


C++ TCPStream::client_payload方法代码示例

本文整理汇总了C++中TCPStream::client_payload方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPStream::client_payload方法的具体用法?C++ TCPStream::client_payload怎么用?C++ TCPStream::client_payload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPStream的用法示例。


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

示例1: operator

    bool TCPStreamPyFunctor::operator()(TCPStream& stream) const {
        if (callback == NULL) {
            return true;
        }
        PyObject* client_mview = make_mview(stream.client_payload());       // new reference
        PyObject* server_mview = NULL;
        try {
            server_mview = make_mview(stream.server_payload());
        } catch(std::runtime_error&) {
            Py_DECREF(client_mview);
            throw;
        } catch(std::bad_alloc&) {
            Py_DECREF(client_mview);
            throw;
        }

        // create the TCPStream python object
        PyObject* py_stream = py_tcp_stream_factory(
            stream.stream_info().client_addr.to_string(),
            stream.stream_info().server_addr.to_string(),
            (int) stream.stream_info().client_port,
            (int) stream.stream_info().server_port,
            stream.id(),
            (int) stream.is_finished(),
            client_mview,
            server_mview
        );

        if (py_stream == NULL) {
            Py_DECREF(client_mview);
            Py_DECREF(server_mview);

            if (!PyErr_Occurred()) {
                throw std::runtime_error("Creating the TCPStream pyobject failed in TCPStreamPyFunctor::operator()");
            } else {
                // python already set an exception
                return false;
            }
        }

        // call the python callback
        PyObject* result = PyObject_CallFunctionObjArgs(callback, py_stream, NULL);     // new reference
        if (result == NULL) {
            Py_DECREF(client_mview);
            Py_DECREF(server_mview);
            Py_DECREF(py_stream);

            if (!PyErr_Occurred()) {
                throw std::runtime_error("Calling python callback failed in TCPStreamPyFunctor::operator()");
            } else {
                // python already set an exception
                return false;
            }
        }

        // cleaning
        Py_DECREF(client_mview);
        Py_DECREF(server_mview);
        Py_DECREF(py_stream);

        // return the result as a C bool
        if (PyObject_IsTrue(result) == 1) {
            Py_DECREF(result);
            return true;
        } else {
            Py_DECREF(result);
            // a False return value from the python functors clears the server payload (... incremental server payload)
            // stream.server_payload().clear();
            return false;
        }
    }
开发者ID:stephane-martin,项目名称:cycapture,代码行数:71,代码来源:py_tcp_stream_functor.cpp


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