107 #include <private/qthread_p.h> 108 #include <private/qobject_p.h> 110 #if !defined(QT_NO_NETWORKPROXY) 123 #define Q_CHECK_VALID_SOCKETLAYER(function, returnValue) do { \ 125 qWarning(""#function" was called on an uninitialized socket device"); \ 126 return returnValue; \ 128 #define Q_CHECK_INVALID_SOCKETLAYER(function, returnValue) do { \ 130 qWarning(""#function" was called on an already initialized socket device"); \ 131 return returnValue; \ 133 #define Q_CHECK_STATE(function, checkState, returnValue) do { \ 134 if (d->socketState != (checkState)) { \ 135 qWarning(""#function" was not called in "#checkState); \ 136 return (returnValue); \ 138 #define Q_CHECK_NOT_STATE(function, checkState, returnValue) do { \ 139 if (d->socketState == (checkState)) { \ 140 qWarning(""#function" was called in "#checkState); \ 141 return (returnValue); \ 143 #define Q_CHECK_STATES(function, state1, state2, returnValue) do { \ 144 if (d->socketState != (state1) && d->socketState != (state2)) { \ 145 qWarning(""#function" was called" \ 146 " not in "#state1" or "#state2); \ 147 return (returnValue); \ 149 #define Q_CHECK_TYPE(function, type, returnValue) do { \ 150 if (d->socketType != (type)) { \ 151 qWarning(#function" was called by a" \ 152 " socket other than "#type""); \ 153 return (returnValue); \ 155 #define Q_TR(a) QT_TRANSLATE_NOOP(QNativeSocketEngine, a) 168 socketDescriptor(-1),
211 switch (errorString) {
298 #if !defined(QT_NO_NETWORKPROXY) 301 if (
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(parent)) {
302 proxy = socket->proxy();
360 #if defined(QT_NO_IPV6) 369 if (!
d->createNewSocket(socketType, protocol)) {
370 #if defined (QNATIVESOCKETENGINE_DEBUG) 377 qDebug(
"QNativeSocketEngine::initialize(type == %s, protocol == %s) failed: %s",
404 qWarning(
"QNativeSocketEngine::initialize unable to inline out-of-band data");
449 if (!
d->fetchConnectionParameters()) {
450 #if defined (QNATIVESOCKETENGINE_DEBUG) 451 qDebug(
"QNativeSocketEngine::initialize(socketDescriptor == %i) failed: %s",
452 socketDescriptor,
d->socketErrorString.toLatin1().constData());
454 d->socketDescriptor = -1;
477 d->socketState = socketState;
489 return d->socketDescriptor != -1;
499 return d->socketDescriptor;
529 #if defined (QT_NO_IPV6) 536 if (!
d->checkProxy(address))
542 d->peerAddress = address;
544 bool connected =
d->nativeConnect(address, port);
546 d->fetchConnectionParameters();
599 #if defined (QT_NO_IPV6) 606 if (!
d->checkProxy(address))
611 if (!
d->nativeBind(address, port))
614 d->fetchConnectionParameters();
644 return d->nativeListen(50);
661 return d->nativeAccept();
664 #ifndef QT_NO_NETWORKINTERFACE 676 return d->nativeJoinMulticastGroup(groupAddress, iface);
689 return d->nativeLeaveMulticastGroup(groupAddress, iface);
698 return d->nativeMulticastInterface();
707 return d->nativeSetMulticastInterface(iface);
710 #endif // QT_NO_NETWORKINTERFACE 726 return d->nativeBytesAvailable();
741 return d->nativeHasPendingDatagrams();
756 return d->nativePendingDatagramSize();
781 return d->nativeReceiveDatagram(data, maxSize, address, port);
808 return d->nativeSendDatagram(data, size, host, port);
820 return d->nativeWrite(data, size);
839 qint64 readBytes =
d->nativeRead(data, maxSize);
847 }
else if (readBytes == -1) {
848 if (!
d->hasSetSocketError) {
849 d->hasSetSocketError =
true;
867 d->readNotifier->setEnabled(
false);
868 if (
d->writeNotifier)
869 d->writeNotifier->setEnabled(
false);
870 if (
d->exceptNotifier)
871 d->exceptNotifier->setEnabled(
false);
873 if(
d->socketDescriptor != -1) {
875 d->socketDescriptor = -1;
878 d->hasSetSocketError =
false;
880 d->localAddress.clear();
882 d->peerAddress.clear();
883 if (
d->readNotifier) {
887 if (
d->writeNotifier) {
889 d->writeNotifier = 0;
891 if (
d->exceptNotifier) {
893 d->exceptNotifier = 0;
922 int ret =
d->nativeSelect(msecs,
true);
928 d->hasSetSocketError =
false;
962 int ret =
d->nativeSelect(msecs,
false);
966 #if defined (Q_WS_WIN) 969 d_func()->fetchConnectionParameters();
973 int valueSize =
sizeof(value);
974 if (::getsockopt(
d->socketDescriptor, SOL_SOCKET, SO_ERROR, (
char *) &value, &valueSize) == 0) {
975 if (value == WSAECONNREFUSED) {
979 }
else if (value == WSAETIMEDOUT) {
983 }
else if (value == WSAEHOSTUNREACH) {
997 d->hasSetSocketError =
false;
1007 bool checkRead,
bool checkWrite,
1008 int msecs,
bool *timedOut)
1015 int ret =
d->nativeSelect(msecs, checkRead, checkWrite, readyToRead, readyToWrite);
1019 #if defined (Q_WS_WIN) 1020 if (checkWrite && ((readyToWrite && *readyToWrite) || !readyToWrite) && ret > 0) {
1022 d_func()->fetchConnectionParameters();
1026 int valueSize =
sizeof(value);
1027 if (::getsockopt(
d->socketDescriptor, SOL_SOCKET, SO_ERROR, (
char *) &value, &valueSize) == 0) {
1028 if (value == WSAECONNREFUSED) {
1032 }
else if (value == WSAETIMEDOUT) {
1036 }
else if (value == WSAEHOSTUNREACH) {
1049 d->hasSetSocketError =
false;
1124 return d->setOption(option, value);
1133 return d->option(socketOption);
1139 return d->readNotifier &&
d->readNotifier->isEnabled();
1166 engine->readNotification();
1196 engine->connectionNotification();
1198 engine->writeNotification();
1220 engine->connectionNotification();
1222 engine->exceptionNotification();
1231 if (
d->readNotifier) {
1232 d->readNotifier->setEnabled(enable);
1233 }
else if (enable &&
d->threadData->eventDispatcher) {
1235 d->readNotifier->setEnabled(
true);
1242 return d->writeNotifier &&
d->writeNotifier->isEnabled();
1248 if (
d->writeNotifier) {
1249 d->writeNotifier->setEnabled(enable);
1250 }
else if (enable &&
d->threadData->eventDispatcher) {
1252 d->writeNotifier->setEnabled(
true);
1259 return d->exceptNotifier &&
d->exceptNotifier->isEnabled();
1265 if (
d->exceptNotifier) {
1266 d->exceptNotifier->setEnabled(enable);
1267 }
else if (enable &&
d->threadData->eventDispatcher) {
1269 d->exceptNotifier->setEnabled(
true);
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
bool setMulticastInterface(const QNetworkInterface &iface)
QString qt_error_string(int errorCode)
QNativeSocketEngine(QObject *parent=0)
Constructs a QNativeSocketEngine.
qint64 read(char *data, qint64 maxlen)
Reads up to maxSize bytes into data from the socket.
qint64 bytesAvailable() const
Returns the number of bytes that are currently available for reading.
int socketDescriptor() const
Returns the native socket descriptor.
bool setOption(SocketOption option, int value)
Sets the option option to the value value.
#define QT_END_NAMESPACE
This macro expands to.
bool listen()
Prepares a TCP server for accepting incoming connections.
SocketType
This enum describes the transport layer protocol.
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)
bool hasPendingDatagrams() const
Returns true if there is at least one datagram pending.
void setReadNotificationEnabled(bool enable)
bool connectToHostByName(const QString &name, quint16 port)
Connects to the remote host name given by name on port port.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
QReadNotifier(int fd, QNativeSocketEngine *parent)
QExceptionNotifier(int fd, QNativeSocketEngine *parent)
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
void setReceiveBufferSize(qint64 bufferSize)
Sets the size of the operating system receive buffer to size.
The QNativeSocketEngine class provides low level access to a socket.
bool waitForRead(int msecs=30000, bool *timedOut=0)
Waits for msecs milliseconds or until the socket is ready for reading.
bool isValid() const
Returns true if the socket is valid; otherwise returns false.
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)
Reads up to maxSize bytes of a datagram from the socket, stores it in data and returns the number of ...
QNativeSocketEngine * engine
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
qint64 sendBufferSize() const
Returns the size of the operating system send buffer.
#define Q_CHECK_TYPE(function, type, returnValue)
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
SocketState
This enum describes the different states in which a socket can be.
Q_CORE_EXPORT void qDebug(const char *,...)
bool connectToHost(const QHostAddress &address, quint16 port)
Connects to the IP address and port specified by address and port.
static QNetworkProxy applicationProxy()
Returns the application level network proxying.
The QNetworkProxy class provides a network layer proxy.
void setWriteNotificationEnabled(bool enable)
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QIntfbScreen * connected
void setSendBufferSize(qint64 bufferSize)
Sets the size of the operating system send buffer to size.
qint64 receiveBufferSize() const
Returns the size of the operating system's socket receive buffer.
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)
Writes a UDP datagram of size size bytes to the socket from data to the address host on port port...
int option(SocketOption option) const
Returns the value of the option socketOption.
QString socketErrorString
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
SocketError
This enum describes the socket errors that can occur.
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
QAbstractSocket::SocketError socketError
~QNativeSocketEngine()
Destructs a QNativeSocketEngine.
void connectionNotification()
#define Q_CHECK_NOT_STATE(function, checkState, returnValue)
#define Q_CHECK_VALID_SOCKETLAYER(function, returnValue)
const char * constData() const
Returns a pointer to the data stored in the byte array.
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
bool bind(const QHostAddress &address, quint16 port)
Binds the socket to the address address and port port.
static QAuServer & server()
QWriteNotifier(int fd, QNativeSocketEngine *parent)
void connectionNotification()
If there's a connection activity on the socket, process it.
QNativeSocketEngine * engine
bool checkProxy(const QHostAddress &address)
QAbstractSocket::NetworkLayerProtocol protocol() const
Returns the network layer protocol of the host address.
void qDeleteInEventHandler(QObject *o)
QNetworkInterface multicastInterface() const
~QNativeSocketEnginePrivate()
Destructs the private class.
bool waitForWrite(int msecs=30000, bool *timedOut=0)
Waits for msecs milliseconds or until the socket is ready for writing.
QObject * parent() const
Returns a pointer to the parent object.
QAbstractSocket::NetworkLayerProtocol protocol() const
void setError(QAbstractSocket::SocketError error, ErrorString errorString) const
Sets the error and error string if not set already.
#define Q_CHECK_STATE(function, checkState, returnValue)
The QTcpServer class provides a TCP-based server.
int accept()
Accepts a pending connection from the socket, which must be in ListeningState, and returns its socket...
void setExceptionNotificationEnabled(bool enable)
bool isExceptionNotificationEnabled() const
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)
Initializes a QNativeSocketEngine by creating a new socket of type socketType and network layer proto...
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces...
bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
QNativeSocketEnginePrivate()
Constructs the private class and initializes all data members.
The QHostAddress class provides an IP address.
QAbstractSocket::SocketState state() const
QAbstractSocket::SocketType socketType() const
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
qint64 bytesToWrite() const
The QAbstractSocket class provides the base functionality common to all socket types.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
qint64 write(const char *data, qint64 len)
Writes a block of size bytes from data to the socket.
void close()
Closes the socket.
bool isReadNotificationEnabled() const
bool isWriteNotificationEnabled() const
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)
qint64 pendingDatagramSize() const
Returns the size of the pending datagram, or -1 if no datagram is pending.
#define Q_CHECK_STATES(function, state1, state2, returnValue)
QNativeSocketEngine * engine