本文整理汇总了C++中TcpSocket::setSocketDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::setSocketDescriptor方法的具体用法?C++ TcpSocket::setSocketDescriptor怎么用?C++ TcpSocket::setSocketDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::setSocketDescriptor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: incomingConnection
/**
*函数介绍:有请求连接,新建一个socket
*输入参数:int socketId,新建socket的SocketDescriptor
*返回值:无
*/
void TcpServer::incomingConnection(int socketId)
{
TcpSocket *socket = new TcpSocket(socketId,this);
//设置socket描述符
socket->setSocketDescriptor(socketId);
//写入系统日志
//Global::systemLog->append(tr("网络通信服务端有新的连接请求"), QString(tr("服务端接收新的连接请求,socket描述符 = %1.")).arg(socketId), SystemLog::INFO);
qDebug()<<"服务端有新的连接,socketDescriptor:"<<socket->socketDescriptor();
//新建了一个socket连接
addServerSocket(socketId);
//获得客户端数据
connect(socket, SIGNAL(haveReadDataSignal(QByteArray,int)), this, SLOT(getClientMessage(QByteArray,int)));
//信号槽:跟踪服务端Socket状态
connect(socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(getServerSocketState(QAbstractSocket::SocketState)));
//信号槽:服务端socket出现错误
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(serverSocketError(QAbstractSocket::SocketError)));
//与客户端断开某socket连接,服务端状态发生改变
connect(socket, SIGNAL(disconnectedBeforeDeleteSignal(int)), this, SLOT(removeServerSocket(int)));
//与客户端断开连接,输出服务器当前连接
//connect(socket, SIGNAL(disconnectedBeforeDeleteSignal(int)), this, SLOT(getAllConnection()));
//与客户端连接上后,输出服务器当前连接
//connect(socket, SIGNAL(connectedForServerSignal(int)), this, SLOT(getAllConnection()));
//与客户端连接上后,输出服务器当前连接
//connect(socket, SIGNAL(connectedForServerSignal(int)), this, SLOT(addServerSocket(int)));
}
示例2: newSocket
void Worker::newSocket(qintptr socket)
{
//qDebug() << m_name << " is handling a new request; thread id" << thread()->currentThreadId();
TcpSocket* s = new TcpSocket(this);
s->m_id = static_cast<unsigned int>(rand());
connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
s->setSocketDescriptor(socket);
s->setTimeout(1000*60*2);
#ifndef NO_LOG
sLog() << m_name << " receive a new request from ip:" << s->peerAddress().toString();
#endif
}
示例3: incomingConnection
void TcpServer::incomingConnection(qintptr handle)
{
TcpSocket *sock;
if (!m_socks.empty()) {
sock = m_socks.back();
m_socks.pop_back();
sock->resetSocket();
} else {
sock = new TcpSocket(m_wsgi, this);
sock->engine = m_engine;
static QString serverAddr = serverAddress().toString();
sock->serverAddress = serverAddr;
connect(sock, &QIODevice::readyRead, m_proto, &Protocol::readyRead);
connect(sock, &TcpSocket::finished, this, &TcpServer::enqueue);
}
sock->setSocketDescriptor(handle);
sock->start = QDateTime::currentMSecsSinceEpoch();
}