![]() |
Qt 6.x
The Qt SDK
|
The QNativeSocketEngine class provides low level access to a socket. More...
#include <qnativesocketengine_p.h>
Public Slots | |
void | connectionNotification () |
If there's a connection activity on the socket, process it. | |
![]() | |
void | readNotification () |
void | writeNotification () |
void | closeNotification () |
void | exceptionNotification () |
void | connectionNotification () |
void | proxyAuthenticationRequired (const QNetworkProxy &proxy, QAuthenticator *authenticator) |
![]() | |
void | deleteLater () |
\threadsafe | |
Public Member Functions | |
QNativeSocketEngine (QObject *parent=nullptr) | |
Constructs a QNativeSocketEngine. | |
~QNativeSocketEngine () | |
Destructs a QNativeSocketEngine. | |
bool | initialize (QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol) override |
Initializes a QNativeSocketEngine by creating a new socket of type socketType and network layer protocol protocol. | |
bool | initialize (qintptr socketDescriptor, QAbstractSocket::SocketState socketState=QAbstractSocket::ConnectedState) override |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes the socket using socketDescriptor instead of creating a new one. | |
qintptr | socketDescriptor () const override |
Returns the native socket descriptor. | |
bool | isValid () const override |
Returns true if the socket is valid; otherwise returns false . | |
bool | connectToHost (const QHostAddress &address, quint16 port) override |
Connects to the IP address and port specified by address and port. | |
bool | connectToHostByName (const QString &name, quint16 port) override |
Connects to the remote host name given by name on port port. | |
bool | bind (const QHostAddress &address, quint16 port) override |
Binds the socket to the address address and port port. | |
bool | listen (int backlog) override |
Prepares a TCP server for accepting incoming connections. | |
qintptr | accept () override |
Accepts a pending connection from the socket, which must be in ListeningState, and returns its socket descriptor. | |
void | close () override |
Closes the socket. | |
qint64 | bytesAvailable () const override |
Returns the number of bytes that are currently available for reading. | |
qint64 | read (char *data, qint64 maxlen) override |
Reads up to maxSize bytes into data from the socket. | |
qint64 | write (const char *data, qint64 len) override |
Writes a block of size bytes from data to the socket. | |
bool | joinMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &iface) override |
bool | leaveMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &iface) override |
QNetworkInterface | multicastInterface () const override |
bool | setMulticastInterface (const QNetworkInterface &iface) override |
bool | hasPendingDatagrams () const override |
Returns true if there is at least one datagram pending. | |
qint64 | pendingDatagramSize () const override |
Returns the size of the pending datagram, or -1 if no datagram is pending. | |
qint64 | readDatagram (char *data, qint64 maxlen, QIpPacketHeader *=nullptr, PacketHeaderOptions=WantNone) override |
Reads up to maxSize bytes of a datagram from the socket, stores it in data and returns the number of bytes read. | |
qint64 | writeDatagram (const char *data, qint64 len, const QIpPacketHeader &) override |
Writes a datagram of size size bytes to the socket from data to the destination contained in header, and returns the number of bytes written, or -1 if an error occurred. | |
qint64 | bytesToWrite () const override |
int | option (SocketOption option) const override |
Returns the value of the option socketOption. | |
bool | setOption (SocketOption option, int value) override |
Sets the option option to the value value. | |
bool | waitForRead (int msecs=30000, bool *timedOut=nullptr) override |
Waits for msecs milliseconds or until the socket is ready for reading. | |
bool | waitForWrite (int msecs=30000, bool *timedOut=nullptr) override |
Waits for msecs milliseconds or until the socket is ready for writing. | |
bool | waitForReadOrWrite (bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=nullptr) override |
bool | isReadNotificationEnabled () const override |
void | setReadNotificationEnabled (bool enable) override |
bool | isWriteNotificationEnabled () const override |
void | setWriteNotificationEnabled (bool enable) override |
bool | isExceptionNotificationEnabled () const override |
void | setExceptionNotificationEnabled (bool enable) override |
![]() | |
QAbstractSocketEngine (QObject *parent=nullptr) | |
virtual bool | initialize (QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)=0 |
virtual bool | initialize (qintptr socketDescriptor, QAbstractSocket::SocketState socketState=QAbstractSocket::ConnectedState)=0 |
virtual qintptr | socketDescriptor () const =0 |
virtual bool | isValid () const =0 |
virtual bool | connectToHost (const QHostAddress &address, quint16 port)=0 |
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 qintptr | accept ()=0 |
virtual void | close ()=0 |
virtual qint64 | bytesAvailable () const =0 |
virtual qint64 | read (char *data, qint64 maxlen)=0 |
virtual qint64 | write (const char *data, qint64 len)=0 |
virtual bool | joinMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &iface)=0 |
virtual bool | leaveMulticastGroup (const QHostAddress &groupAddress, const QNetworkInterface &iface)=0 |
virtual QNetworkInterface | multicastInterface () const =0 |
virtual bool | setMulticastInterface (const QNetworkInterface &iface)=0 |
virtual bool | hasPendingDatagrams () const =0 |
virtual qint64 | pendingDatagramSize () const =0 |
virtual qint64 | readDatagram (char *data, qint64 maxlen, QIpPacketHeader *header=nullptr, PacketHeaderOptions=WantNone)=0 |
virtual qint64 | writeDatagram (const char *data, qint64 len, const QIpPacketHeader &header)=0 |
virtual qint64 | bytesToWrite () const =0 |
virtual int | option (SocketOption option) const =0 |
virtual bool | setOption (SocketOption option, int value)=0 |
virtual bool | waitForRead (int msecs=30000, bool *timedOut=nullptr)=0 |
virtual bool | waitForWrite (int msecs=30000, bool *timedOut=nullptr)=0 |
virtual bool | waitForReadOrWrite (bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=nullptr)=0 |
QAbstractSocket::SocketError | error () const |
QString | errorString () const |
QAbstractSocket::SocketState | state () const |
QAbstractSocket::SocketType | socketType () const |
QAbstractSocket::NetworkLayerProtocol | protocol () const |
QHostAddress | localAddress () const |
quint16 | localPort () const |
QHostAddress | peerAddress () const |
quint16 | peerPort () const |
int | inboundStreamCount () const |
int | outboundStreamCount () const |
virtual bool | isReadNotificationEnabled () const =0 |
virtual void | setReadNotificationEnabled (bool enable)=0 |
virtual bool | isWriteNotificationEnabled () const =0 |
virtual void | setWriteNotificationEnabled (bool enable)=0 |
virtual bool | isExceptionNotificationEnabled () const =0 |
virtual void | setExceptionNotificationEnabled (bool enable)=0 |
void | setReceiver (QAbstractSocketEngineReceiver *receiver) |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Additional Inherited Members | |
![]() | |
enum | SocketOption { NonBlockingSocketOption , BroadcastSocketOption , ReceiveBufferSocketOption , SendBufferSocketOption , AddressReusable , BindExclusively , ReceiveOutOfBandData , LowDelayOption , KeepAliveOption , MulticastTtlOption , MulticastLoopbackOption , TypeOfServiceOption , ReceivePacketInformation , ReceiveHopLimit , MaxStreamsSocketOption , PathMtuInformation } |
enum | PacketHeaderOption { WantNone = 0 , WantDatagramSender = 0x01 , WantDatagramDestination = 0x02 , WantDatagramHopLimit = 0x04 , WantStreamNumber = 0x08 , WantEndOfRecord = 0x10 , WantAll = 0xff } |
Specifies which fields in the IP packet header are desired in the call to readDatagram(). More... | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
![]() | |
static QAbstractSocketEngine * | createSocketEngine (QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent) |
static QAbstractSocketEngine * | createSocketEngine (qintptr socketDescriptor, QObject *parent) |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QAbstractSocketEngine (QAbstractSocketEnginePrivate &dd, QObject *parent=nullptr) | |
void | setError (QAbstractSocket::SocketError error, const QString &errorString) const |
void | setState (QAbstractSocket::SocketState state) |
void | setSocketType (QAbstractSocket::SocketType socketType) |
void | setProtocol (QAbstractSocket::NetworkLayerProtocol protocol) |
void | setLocalAddress (const QHostAddress &address) |
void | setLocalPort (quint16 port) |
void | setPeerAddress (const QHostAddress &address) |
void | setPeerPort (quint16 port) |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QNativeSocketEngine class provides low level access to a socket.
\reentrant
\inmodule QtNetwork
QtSocketLayer provides basic socket functionality provided by the operating system. It also keeps track of what state the socket is in, and which errors that occur.
The classes QTcpSocket, QUdpSocket and QTcpServer provide a higher level API, and are in general more useful for the common application.
There are two main ways of initializing the a QNativeSocketEngine; either create a new socket by passing the socket type (TcpSocket or UdpSocket) and network layer protocol (IPv4Protocol or IPv6Protocol) to initialize(), or pass an existing socket descriptor and have QNativeSocketEngine determine the type and protocol itself. The native socket descriptor can later be fetched by calling socketDescriptor(). The socket is made non-blocking, but blocking behavior can still be achieved by calling waitForRead() and waitForWrite(). isValid() can be called to check if the socket has been successfully initialized and is ready to use.
To connect to a host, determine its address and pass this and the port number to connectToHost(). The socket can then be used as a TCP or UDP client. Otherwise; bind(), listen() and accept() are used to have the socket function as a TCP or UDP server. Call close() to close the socket.
bytesAvailable() is called to determine how much data is available for reading. read() and write() are used by both TCP and UDP clients to exchange data with the connected peer. UDP clients can also call hasMoreDatagrams(), nextDatagramSize(), readDatagram(), and writeDatagram().
Call state() to determine the state of the socket, for example, ListeningState or ConnectedState. socketType() tells whether the socket is a TCP socket or a UDP socket, or if the socket type is unknown. protocol() is used to determine the socket's network layer protocol.
localAddress(), localPort() are called to find the address and port that are currently bound to the socket. If the socket is connected, peerAddress() and peerPort() determine the address and port of the connected peer.
Finally, if any function should fail, error() and errorString() can be called to determine the cause of the error.
Definition at line 101 of file qnativesocketengine_p.h.
Constructs a QNativeSocketEngine.
Definition at line 384 of file qnativesocketengine.cpp.
QNativeSocketEngine::~QNativeSocketEngine | ( | ) |
Destructs a QNativeSocketEngine.
Definition at line 392 of file qnativesocketengine.cpp.
References close().
|
overridevirtual |
Accepts a pending connection from the socket, which must be in ListeningState, and returns its socket descriptor.
If no pending connections are available, -1 is returned.
Implements QAbstractSocketEngine.
Definition at line 682 of file qnativesocketengine.cpp.
References accept(), d, QAbstractSocket::ListeningState, Q_CHECK_STATE, Q_CHECK_TYPE, Q_CHECK_TYPES, Q_CHECK_VALID_SOCKETLAYER, QAbstractSocket::SctpSocket, and QAbstractSocket::TcpSocket.
Referenced by accept(), and if().
|
overridevirtual |
Binds the socket to the address address and port port.
Returns true
on success; otherwise false is returned. The port may be 0, in which case an arbitrary unused port is assigned automatically by the operating system.
Servers call this function to set up the server's address and port. TCP servers must in addition call listen() after bind().
Implements QAbstractSocketEngine.
Definition at line 628 of file qnativesocketengine.cpp.
References bind(), d, Q_CHECK_STATE, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UnconnectedState.
Referenced by bind().
|
overridevirtual |
Returns the number of bytes that are currently available for reading.
On error, -1 is returned.
For UDP sockets, this function returns the accumulated size of all pending datagrams, and it is therefore more useful for UDP sockets to call hasPendingDatagrams() and pendingDatagramSize().
Implements QAbstractSocketEngine.
Definition at line 705 of file qnativesocketengine.cpp.
References bytesAvailable(), d, Q_CHECK_NOT_STATE, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UnconnectedState.
Referenced by bytesAvailable().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 886 of file qnativesocketengine.cpp.
|
overridevirtual |
Closes the socket.
In order to use the socket again, initialize() must be called.
Implements QAbstractSocketEngine.
Definition at line 929 of file qnativesocketengine.cpp.
References d, qDeleteInEventHandler(), and QAbstractSocket::UnconnectedState.
Referenced by ~QNativeSocketEngine(), initialize(), initialize(), and read().
|
slot |
If there's a connection activity on the socket, process it.
Then notify our parent if there really was activity.
Definition at line 589 of file qnativesocketengine.cpp.
References QAbstractSocket::ConnectingState, QAbstractSocketEngine::connectionNotification(), connectToHost(), d, Q_ASSERT, and QAbstractSocketEngine::state().
Referenced by QWriteNotifier::event(), and QExceptionNotifier::event().
|
overridevirtual |
Connects to the IP address and port specified by address and port.
If the connection is established, this function returns true
and the socket enters ConnectedState. Otherwise, false is returned.
If false is returned, state() should be called to see if the socket is in ConnectingState. If so, a delayed TCP connection is taking place, and connectToHost() must be called again later to determine if the connection was established successfully or not. The second connection attempt must be made when the socket is ready for writing. This state can be determined either by connecting a QSocketNotifier to the socket descriptor returned by socketDescriptor(), or by calling the blocking function waitForWrite().
Example:
Otherwise, error() should be called to determine the cause of the error.
Implements QAbstractSocketEngine.
Definition at line 565 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, connected, QAbstractSocket::ConnectingState, connectToHost(), d, Q_CHECK_STATES3, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UnconnectedState.
Referenced by connectionNotification(), connectToHost(), waitForRead(), waitForReadOrWrite(), and waitForWrite().
|
overridevirtual |
Connects to the remote host name given by name on port port.
When this function is called, the upper-level will not perform a hostname lookup.
The native socket engine does not support this operation, but some other socket engines (notably proxy-based ones) do.
Implements QAbstractSocketEngine.
Definition at line 609 of file qnativesocketengine.cpp.
References d, QNativeSocketEnginePrivate::OperationUnsupportedErrorString, Q_UNUSED, and QAbstractSocket::UnsupportedSocketOperationError.
|
overridevirtual |
Returns true
if there is at least one datagram pending.
This function is only called by UDP sockets, where a datagram can have a size of 0. TCP sockets call bytesAvailable().
Implements QAbstractSocketEngine.
Definition at line 785 of file qnativesocketengine.cpp.
References d, hasPendingDatagrams(), Q_CHECK_NOT_STATE, Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, QAbstractSocket::UdpSocket, and QAbstractSocket::UnconnectedState.
Referenced by hasPendingDatagrams().
|
overridevirtual |
Initializes a QNativeSocketEngine by creating a new socket of type socketType and network layer protocol protocol.
Returns true
on success; otherwise returns false
.
If the socket was already initialized, this function closes the socket before reeinitializing it.
The new socket is non-blocking, and for UDP sockets it's also broadcast enabled.
Implements QAbstractSocketEngine.
Definition at line 408 of file qnativesocketengine.cpp.
References QNativeSocketEnginePrivate::BroadcastingInitFailedErrorString, QAbstractSocketEngine::BroadcastSocketOption, close(), QByteArray::constData(), QLatin1StringView::constData(), d, QAbstractSocket::IPv4Protocol, QAbstractSocket::IPv6Protocol, isValid(), QAbstractSocketEngine::protocol(), qDebug, qWarning, QAbstractSocketEngine::ReceiveHopLimit, QAbstractSocketEngine::ReceiveOutOfBandData, QAbstractSocketEngine::ReceivePacketInformation, QAbstractSocket::SctpSocket, setOption(), QAbstractSocketEngine::socketType(), QAbstractSocket::TcpSocket, QString::toLatin1(), typeStr(), QAbstractSocket::UdpSocket, and QAbstractSocket::UnsupportedSocketOperationError.
|
overridevirtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Initializes the socket using socketDescriptor instead of creating a new one.
The socket type and network layer protocol are determined automatically. The socket's state is set to socketState.
If the socket type is either TCP or UDP, it is made non-blocking. UDP sockets are also broadcast enabled.
Implements QAbstractSocketEngine.
Definition at line 480 of file qnativesocketengine.cpp.
References QNativeSocketEnginePrivate::BroadcastingInitFailedErrorString, QAbstractSocketEngine::BroadcastSocketOption, close(), d, isValid(), QNativeSocketEnginePrivate::NonBlockingInitFailedErrorString, QAbstractSocketEngine::NonBlockingSocketOption, qDebug, setOption(), socketDescriptor(), QAbstractSocket::UdpSocket, QAbstractSocket::UnknownSocketType, and QAbstractSocket::UnsupportedSocketOperationError.
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1331 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1208 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Returns true
if the socket is valid; otherwise returns false
.
A socket is valid if it has not been successfully initialized, or if it has been closed.
Implements QAbstractSocketEngine.
Definition at line 527 of file qnativesocketengine.cpp.
References d.
Referenced by initialize(), and initialize().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1314 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 720 of file qnativesocketengine.cpp.
References QAbstractSocket::AnyIPProtocol, QAbstractSocket::BoundState, d, QAbstractSocket::IPv4Protocol, QAbstractSocket::IPv6Protocol, joinMulticastGroup(), QHostAddress::protocol(), Q_CHECK_STATE, Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, qWarning, and QAbstractSocket::UdpSocket.
Referenced by joinMulticastGroup().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 746 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, d, leaveMulticastGroup(), Q_CHECK_STATE, Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UdpSocket.
Referenced by leaveMulticastGroup().
|
overridevirtual |
Prepares a TCP server for accepting incoming connections.
This function must be called after bind(), and only by TCP sockets.
After this function has been called, pending client connections are detected by checking if the socket is ready for reading. This can be done by either creating a QSocketNotifier, passing the socket descriptor returned by socketDescriptor(), or by calling the blocking function waitForRead().
Example:
Implements QAbstractSocketEngine.
Definition at line 660 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, d, listen(), Q_CHECK_STATE, Q_CHECK_TYPE, Q_CHECK_TYPES, Q_CHECK_VALID_SOCKETLAYER, QAbstractSocket::SctpSocket, and QAbstractSocket::TcpSocket.
Referenced by listen().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 759 of file qnativesocketengine.cpp.
References d, multicastInterface(), Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UdpSocket.
Referenced by multicastInterface().
|
overridevirtual |
Returns the value of the option socketOption.
Implements QAbstractSocketEngine.
Definition at line 1202 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Returns the size of the pending datagram, or -1 if no datagram is pending.
A datagram size of 0 is perfectly valid. This function is called by UDP sockets before receiveMessage(). For TCP sockets, call bytesAvailable().
Implements QAbstractSocketEngine.
Definition at line 801 of file qnativesocketengine.cpp.
References d, pendingDatagramSize(), Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, and QAbstractSocket::UdpSocket.
Referenced by pendingDatagramSize().
Reads up to maxSize bytes into data from the socket.
Returns the number of bytes read, or -1 if an error occurred.
Implements QAbstractSocketEngine.
Definition at line 895 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, close(), QAbstractSocket::ConnectedState, d, QAbstractSocket::NetworkError, Q_CHECK_STATES, Q_CHECK_VALID_SOCKETLAYER, qt_error_string(), read(), QAbstractSocket::RemoteHostClosedError, QNativeSocketEnginePrivate::RemoteHostClosedErrorString, QAbstractSocket::SctpSocket, and QAbstractSocket::TcpSocket.
Referenced by read().
|
overridevirtual |
Reads up to maxSize bytes of a datagram from the socket, stores it in data and returns the number of bytes read.
The address, port, and other IP header fields are stored in header according to the request in options.
For UDP sockets, to avoid unnecessarily loss of data, call pendingDatagramSize() to determine the size of the pending message before reading it. If maxSize is too small, the rest of the datagram will be lost.
Returns -1 if an error occurred.
Implements QAbstractSocketEngine.
Definition at line 826 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, QAbstractSocket::ConnectedState, d, header(), Q_CHECK_STATES, Q_CHECK_VALID_SOCKETLAYER, and readDatagram().
Referenced by readDatagram().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1337 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 770 of file qnativesocketengine.cpp.
References d, Q_CHECK_TYPE, Q_CHECK_VALID_SOCKETLAYER, setMulticastInterface(), and QAbstractSocket::UdpSocket.
Referenced by setMulticastInterface().
|
overridevirtual |
Sets the option option to the value value.
Implements QAbstractSocketEngine.
Definition at line 1193 of file qnativesocketengine.cpp.
References d.
Referenced by initialize(), and initialize().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1303 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1320 of file qnativesocketengine.cpp.
References d.
|
overridevirtual |
Returns the native socket descriptor.
Any use of this descriptor stands the risk of being non-portable.
Implements QAbstractSocketEngine.
Definition at line 537 of file qnativesocketengine.cpp.
References d.
Referenced by initialize().
|
overridevirtual |
Waits for msecs milliseconds or until the socket is ready for reading.
If timedOut is not \nullptr and msecs milliseconds have passed, the value of timedOut is set to true.
Returns true
if data is available for reading; otherwise returns false.
This is a blocking function call; its use is disadvised in a single threaded application, as the whole thread will stop responding until the function returns. waitForRead() is most useful when there is no event loop available. The general approach is to create a QSocketNotifier, passing the socket descriptor returned by socketDescriptor() to its constructor.
Implements QAbstractSocketEngine.
Definition at line 979 of file qnativesocketengine.cpp.
References QAbstractSocket::ConnectingState, connectToHost(), d, Q_CHECK_NOT_STATE, Q_CHECK_VALID_SOCKETLAYER, ret, QAbstractSocket::SocketTimeoutError, QAbstractSocketEngine::state(), QNativeSocketEnginePrivate::TimeOutErrorString, QAbstractSocket::UnconnectedState, and waitForRead().
Referenced by waitForRead().
|
overridevirtual |
Implements QAbstractSocketEngine.
Definition at line 1075 of file qnativesocketengine.cpp.
References QAbstractSocket::ConnectedState, QAbstractSocket::ConnectingState, QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString, connectToHost(), d, QNativeSocketEnginePrivate::HostUnreachableErrorString, QAbstractSocket::NetworkError, Q_CHECK_NOT_STATE, Q_CHECK_VALID_SOCKETLAYER, ret, QAbstractSocketEngine::setState(), QAbstractSocket::SocketTimeoutError, QAbstractSocketEngine::state(), QNativeSocketEnginePrivate::TimeOutErrorString, QAbstractSocket::UnconnectedState, and waitForReadOrWrite().
Referenced by waitForReadOrWrite().
|
overridevirtual |
Waits for msecs milliseconds or until the socket is ready for writing.
If timedOut is not \nullptr and msecs milliseconds have passed, the value of timedOut is set to true.
Returns true
if data is available for writing; otherwise returns false.
This is a blocking function call; its use is disadvised in a single threaded application, as the whole thread will stop responding until the function returns. waitForWrite() is most useful when there is no event loop available. The general approach is to create a QSocketNotifier, passing the socket descriptor returned by socketDescriptor() to its constructor.
Implements QAbstractSocketEngine.
Definition at line 1019 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, QAbstractSocket::ConnectedState, QAbstractSocket::ConnectingState, QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString, connectToHost(), d, QNativeSocketEnginePrivate::HostUnreachableErrorString, QAbstractSocket::NetworkError, Q_CHECK_NOT_STATE, Q_CHECK_VALID_SOCKETLAYER, ret, QAbstractSocketEngine::setState(), QAbstractSocket::SocketTimeoutError, QAbstractSocketEngine::state(), QNativeSocketEnginePrivate::TimeOutErrorString, QAbstractSocket::UnconnectedState, and waitForWrite().
Referenced by waitForWrite().
Writes a block of size bytes from data to the socket.
Returns the number of bytes written, or -1 if an error occurred.
Passing zero as the size parameter on a connected UDP socket will send an empty datagram. For other socket types results are unspecified.
Implements QAbstractSocketEngine.
Definition at line 877 of file qnativesocketengine.cpp.
References QAbstractSocket::ConnectedState, d, Q_CHECK_STATE, Q_CHECK_VALID_SOCKETLAYER, and write().
Referenced by write().
|
overridevirtual |
Writes a datagram of size size bytes to the socket from data to the destination contained in header, and returns the number of bytes written, or -1 if an error occurred.
If header contains other settings like hop limit or source address, this function will try to pass them to the operating system too, but will not indicate an error if it could not pass them.
Only one datagram is sent, and if there is too much data to fit into a single datagram, the operation will fail and error() will return QAbstractSocket::DatagramTooLargeError. Operating systems impose an upper limit to the size of a datagram, but this size is different on almost all platforms. Sending large datagrams is in general disadvised, as even if they are sent successfully, they are likely to be fragmented before arriving at their destination.
Experience has shown that it is in general safe to send IPv4 datagrams no larger than 512 bytes or IPv6 datagrams no larger than 1280 (the minimum MTU).
Implements QAbstractSocketEngine.
Definition at line 859 of file qnativesocketengine.cpp.
References QAbstractSocket::BoundState, QAbstractSocket::ConnectedState, d, header(), Q_CHECK_STATES, Q_CHECK_VALID_SOCKETLAYER, and writeDatagram().
Referenced by writeDatagram().