mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
optimize internal socket creation
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e611701095
commit
ca6acd1e24
2 changed files with 13 additions and 8 deletions
|
@ -481,14 +481,6 @@ bool QAbstractSocketEngine::initialize(QAbstractSocket::SocketType socketType, Q
|
|||
return false;
|
||||
}
|
||||
|
||||
// Make the socket nonblocking.
|
||||
if (!setOption(NonBlockingSocketOption, 1)) {
|
||||
d->setError(QAbstractSocket::UnsupportedSocketOperationError,
|
||||
QAbstractSocketEnginePrivate::NonBlockingInitFailedErrorString);
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the broadcasting flag if it's a UDP socket.
|
||||
if (socketType == QAbstractSocket::UdpSocket
|
||||
&& !setOption(BroadcastSocketOption, 1)) {
|
||||
|
|
|
@ -98,6 +98,10 @@ bool QAbstractSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType s
|
|||
int protocol = AF_INET;
|
||||
#endif
|
||||
int type = (socketType == QAbstractSocket::UdpSocket) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
#ifdef SOCK_NONBLOCK
|
||||
// Linux specific
|
||||
type |= SOCK_NONBLOCK;
|
||||
#endif
|
||||
|
||||
int socket = qt_safe_socket(protocol, type, 0);
|
||||
|
||||
|
@ -124,6 +128,15 @@ bool QAbstractSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType s
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifndef SOCK_NONBLOCK
|
||||
// Make the socket nonblocking.
|
||||
int flags = ::fcntl(socket, F_GETFL, 0);
|
||||
if (flags == -1 || ::fcntl(socket, F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
d->errorOccurred(QAbstractSocket::UnsupportedSocketOperationError, ProtocolUnsupportedErrorString);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
socketDescriptor = socket;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue