Make sockets' accept() methods return qintptr
Not necessarily relevant outside windows, where the socket descriptor is SOCKET (= unsigned 64-bit). Also follow their recommendation to not compare to -1, but rather to INVALID_SOCKET. Pick-to: 6.4 6.3 6.2 Change-Id: I0cfa4dfd9e147469132e2e72de22b30eab01e15c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ad1980cd43
commit
da9d60ecc3
@ -98,7 +98,7 @@ public:
|
||||
virtual bool connectToHostByName(const QString &name, quint16 port) = 0;
|
||||
virtual bool bind(const QHostAddress &address, quint16 port) = 0;
|
||||
virtual bool listen(int backlog) = 0;
|
||||
virtual int accept() = 0;
|
||||
virtual qintptr accept() = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual qint64 bytesAvailable() const = 0;
|
||||
|
@ -164,7 +164,7 @@ bool QHttpSocketEngine::listen(int backlog)
|
||||
return false;
|
||||
}
|
||||
|
||||
int QHttpSocketEngine::accept()
|
||||
qintptr QHttpSocketEngine::accept()
|
||||
{
|
||||
qWarning("Operation is not supported");
|
||||
setError(QAbstractSocket::UnsupportedSocketOperationError, "Unsupported socket operation"_L1);
|
||||
|
@ -60,7 +60,7 @@ public:
|
||||
bool connectToHostByName(const QString &name, quint16 port) override;
|
||||
bool bind(const QHostAddress &address, quint16 port) override;
|
||||
bool listen(int backlog) override;
|
||||
int accept() override;
|
||||
qintptr accept() override;
|
||||
void close() override;
|
||||
|
||||
qint64 bytesAvailable() const override;
|
||||
|
@ -679,7 +679,7 @@ bool QNativeSocketEngine::listen(int backlog)
|
||||
|
||||
\sa bind(), listen()
|
||||
*/
|
||||
int QNativeSocketEngine::accept()
|
||||
qintptr QNativeSocketEngine::accept()
|
||||
{
|
||||
Q_D(QNativeSocketEngine);
|
||||
Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::accept(), -1);
|
||||
@ -1255,7 +1255,7 @@ bool QReadNotifier::event(QEvent *e)
|
||||
class QWriteNotifier : public QSocketNotifier
|
||||
{
|
||||
public:
|
||||
QWriteNotifier(int fd, QNativeSocketEngine *parent)
|
||||
QWriteNotifier(qintptr fd, QNativeSocketEngine *parent)
|
||||
: QSocketNotifier(fd, QSocketNotifier::Write, parent) { engine = parent; }
|
||||
|
||||
protected:
|
||||
@ -1279,7 +1279,7 @@ bool QWriteNotifier::event(QEvent *e)
|
||||
class QExceptionNotifier : public QSocketNotifier
|
||||
{
|
||||
public:
|
||||
QExceptionNotifier(int fd, QNativeSocketEngine *parent)
|
||||
QExceptionNotifier(qintptr fd, QNativeSocketEngine *parent)
|
||||
: QSocketNotifier(fd, QSocketNotifier::Exception, parent) { engine = parent; }
|
||||
|
||||
protected:
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
bool connectToHostByName(const QString &name, quint16 port) override;
|
||||
bool bind(const QHostAddress &address, quint16 port) override;
|
||||
bool listen(int backlog) override;
|
||||
int accept() override;
|
||||
qintptr accept() override;
|
||||
void close() override;
|
||||
|
||||
qint64 bytesAvailable() const override;
|
||||
@ -225,7 +225,7 @@ public:
|
||||
bool nativeConnect(const QHostAddress &address, quint16 port);
|
||||
bool nativeBind(const QHostAddress &address, quint16 port);
|
||||
bool nativeListen(int backlog);
|
||||
int nativeAccept();
|
||||
qintptr nativeAccept();
|
||||
#ifndef QT_NO_NETWORKINTERFACE
|
||||
bool nativeJoinMulticastGroup(const QHostAddress &groupAddress,
|
||||
const QNetworkInterface &iface);
|
||||
|
@ -559,7 +559,7 @@ bool QNativeSocketEnginePrivate::nativeListen(int backlog)
|
||||
return true;
|
||||
}
|
||||
|
||||
int QNativeSocketEnginePrivate::nativeAccept()
|
||||
qintptr QNativeSocketEnginePrivate::nativeAccept()
|
||||
{
|
||||
int acceptedDescriptor = qt_safe_accept(socketDescriptor, nullptr, nullptr);
|
||||
if (acceptedDescriptor == -1) {
|
||||
@ -605,7 +605,7 @@ int QNativeSocketEnginePrivate::nativeAccept()
|
||||
}
|
||||
}
|
||||
|
||||
return acceptedDescriptor;
|
||||
return qintptr(acceptedDescriptor);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_NETWORKINTERFACE
|
||||
|
@ -773,10 +773,10 @@ bool QNativeSocketEnginePrivate::nativeListen(int backlog)
|
||||
return true;
|
||||
}
|
||||
|
||||
int QNativeSocketEnginePrivate::nativeAccept()
|
||||
qintptr QNativeSocketEnginePrivate::nativeAccept()
|
||||
{
|
||||
int acceptedDescriptor = WSAAccept(socketDescriptor, 0,0,0,0);
|
||||
if (acceptedDescriptor == -1) {
|
||||
SOCKET acceptedDescriptor = WSAAccept(socketDescriptor, 0,0,0,0);
|
||||
if (acceptedDescriptor == INVALID_SOCKET) {
|
||||
int err = WSAGetLastError();
|
||||
switch (err) {
|
||||
case WSAEACCES:
|
||||
@ -810,7 +810,7 @@ int QNativeSocketEnginePrivate::nativeAccept()
|
||||
setError(QAbstractSocket::UnknownSocketError, UnknownSocketErrorString);
|
||||
break;
|
||||
}
|
||||
} else if (acceptedDescriptor != -1 && QAbstractEventDispatcher::instance()) {
|
||||
} else if (acceptedDescriptor != INVALID_SOCKET && QAbstractEventDispatcher::instance()) {
|
||||
// Because of WSAAsyncSelect() WSAAccept returns a non blocking socket
|
||||
// with the same attributes as the listening socket including the current
|
||||
// WSAAsyncSelect(). To be able to change the socket to blocking mode the
|
||||
@ -820,9 +820,9 @@ int QNativeSocketEnginePrivate::nativeAccept()
|
||||
n.setEnabled(false);
|
||||
}
|
||||
#if defined (QNATIVESOCKETENGINE_DEBUG)
|
||||
qDebug("QNativeSocketEnginePrivate::nativeAccept() == %i", acceptedDescriptor);
|
||||
qDebug("QNativeSocketEnginePrivate::nativeAccept() == %lld", qint64(acceptedDescriptor));
|
||||
#endif
|
||||
return acceptedDescriptor;
|
||||
return qintptr(acceptedDescriptor);
|
||||
}
|
||||
|
||||
static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
|
||||
|
@ -1379,7 +1379,7 @@ bool QSocks5SocketEngine::listen(int backlog)
|
||||
return false;
|
||||
}
|
||||
|
||||
int QSocks5SocketEngine::accept()
|
||||
qintptr QSocks5SocketEngine::accept()
|
||||
{
|
||||
Q_D(QSocks5SocketEngine);
|
||||
// check we are listing ---
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
bool connectToHostByName(const QString &name, quint16 port) override;
|
||||
bool bind(const QHostAddress &address, quint16 port) override;
|
||||
bool listen(int backlog) override;
|
||||
int accept() override;
|
||||
qintptr accept() override;
|
||||
void close() override;
|
||||
|
||||
qint64 bytesAvailable() const override;
|
||||
|
@ -181,7 +181,7 @@ void QTcpServerPrivate::readNotification()
|
||||
return;
|
||||
}
|
||||
|
||||
int descriptor = socketEngine->accept();
|
||||
qintptr descriptor = socketEngine->accept();
|
||||
if (descriptor == -1) {
|
||||
if (socketEngine->error() != QAbstractSocket::TemporaryError) {
|
||||
q->pauseAccepting();
|
||||
|
Loading…
Reference in New Issue
Block a user