QT_BEGIN_NAMESPACE void QLocalServerPrivate::init() { Q_Q(QLocalServer); q->connect(&tcpServer, SIGNAL(newConnection()), SLOT(_q_onNewConnection())); }
void QLocalServerPrivate::waitForNewConnection(int msecs, bool *timedOut) { Q_Q(QLocalServer); if (!pendingConnections.isEmpty() || !q->isListening()) return; DWORD result = WaitForSingleObject(eventHandle, (msecs == -1) ? INFINITE : msecs); if (result == WAIT_TIMEOUT) { if (timedOut) *timedOut = true; } else { _q_onNewConnection(); } }
bool QLocalServerPrivate::listen(const QString &name) { Q_Q(QLocalServer); QString pipePath = QLatin1String("\\\\.\\pipe\\"); if (name.startsWith(pipePath)) fullServerName = name; else fullServerName = pipePath + name; // Use only one event for all listeners of one socket. // The idea is that listener events are rare, so polling all listeners once in a while is // cheap compared to waiting for N additional events in each iteration of the main loop. eventHandle = CreateEvent(NULL, TRUE, FALSE, NULL); connectionEventNotifier = new QWinEventNotifier(eventHandle , q); q->connect(connectionEventNotifier, SIGNAL(activated(HANDLE)), q, SLOT(_q_onNewConnection())); for (int i = 0; i < SYSTEM_MAX_PENDING_SOCKETS; ++i) if (!addListener()) return false; return true; }