本文整理汇总了C++中TCPSocket::poll方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPSocket::poll方法的具体用法?C++ TCPSocket::poll怎么用?C++ TCPSocket::poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPSocket
的用法示例。
在下文中一共展示了TCPSocket::poll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void ConnectThread::run()
{
QHostInfo addr = QHostInfo::fromName(mAddress);
if (addr.error() != QHostInfo::NoError) {
Q_EMIT error(addr.errorString());
return;
}
QHostAddress actualAddr;
QList<QHostAddress> addresses = addr.addresses();
for (QList<QHostAddress>::const_iterator iter = addresses.begin();
iter != addresses.end(); ++ iter) {
if (iter->protocol() == QAbstractSocket::IPv4Protocol) {
actualAddr = *iter;
break;
}
}
if (actualAddr.isNull()) {
Q_EMIT error(tr("无法解析域名: 找不到'%1'的IPv4地址").arg(mAddress));
return;
}
// Begin connection
{
std::string addr = actualAddr.toString().toStdString();
TCPSocketAddress remote (addr,mPort);
IOVideoSource *src = 0;
Error rc;
TCPSocket *ctrl = new TCPSocket (::socket(AF_INET, SOCK_STREAM, 0));
TCPSocket *data = new TCPSocket (::socket(AF_INET, SOCK_STREAM, 0));
ctrl->setBlockingMode(false);
data->setBlockingMode(false);
ctrl->connect(&remote);
do {
rc = ctrl->poll(IODevice::POLL_WRITE,200);
if (rc.isSuccess()) break;
else if (rc.getErrorType() == Error::ERR_TIMEOUT) continue;
else {
rc.setErrorString("无法连接到远端服务器");
goto connect_ctrl_failed;
}
}while(!mShouldStop);
data->connect(&remote);
do {
rc = data->poll(IODevice::POLL_WRITE,200);
if (rc.isSuccess()) break;
else if (rc.getErrorType() == Error::ERR_TIMEOUT) continue;
else {
rc.setErrorString("无法连接到远端服务器");
goto connect_data_failed;
}
}while(!mShouldStop);
ctrl->setBlockingMode(true);
data->setBlockingMode(true);
src = new IOVideoSource(ctrl,data);
rc = src->init();
if (rc.isError()) {
rc.setErrorString("初始化视频源失败,原因为:" + rc.getErrorString());
goto init_video_source_failed;
}
mVideoSource = src;
Q_EMIT success();
return;
init_video_source_failed:
delete src;
connect_data_failed:
connect_ctrl_failed:
ctrl->close();
data->close();
delete ctrl;
delete data;
Q_EMIT error(QString::fromStdString(rc.getErrorString()));
}
}