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