Qt源码分析--QAbstractSocketEngine

QAbstractSocketEngine提供了一个socket操作的抽象接口,可以通过派生的方式为不同的socket类型和协议实现特定的socket引擎。

1.createSocketEngine

QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(qintptr socketDescripter, QObject *parent)
{
    QMutexLocker locker(&socketHandlers()->mutex);
    for (int i = 0; i < socketHandlers()->size(); i++) {
        if (QAbstractSocketEngine *ret = socketHandlers()->at(i)->createSocketEngine(socketDescripter, parent))
            return ret;
    }
    return new QNativeSocketEngine(parent);
}

根据给定的套接字描述符(socket descriptor)和父对象创建套接字引擎。遍历套接字处理程序列表,尝试使用每个处理程序来创建套接字引擎,直到成功创建一个引擎,然后返回该引擎。

QAbstractSocketEngine *QAbstractSocketEngine::createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &proxy, QObject *parent)
{
#ifndef QT_NO_NETWORKPROXY
    // proxy type must have been resolved by now
    if (proxy.type() == QNetworkProxy::DefaultProxy)
        return nullptr;
#endif
    QMutexLocker locker(&socketHandlers()->mutex);
    for (int i = 0; i < socketHandlers()->size(); i++) {
        if (QAbstractSocketEngine *ret = socketHandlers()->at(i)->createSocketEngine(socketType, proxy, parent))
   

你可能感兴趣的:(源码分析,Qt,qt,服务器)