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