classPiiSocketDevice
#include <PiiSocketDevice.h>
A wrapper class that works as a generic socket device.
Description
The purpose of this class is to work around Qt's lack of a common
socket-type superclass for QLocalSocket and QAbstractSocket. These
cannot be used interchangeably because their common superclass,
QIODevice,
provides no general way of checking if the device is
readable/writable. For example, TCP sockets are "open" (isOpen()
returns true) even after the connection has been
broken. This class provides the isReadable() and isWritable() functions that can be used to check if
the socket is really available for reading and writing. This class
also provides functionality for reading and writing data to/from
devices that may not have everything available at once.
PiiSocketDevice is special in that it can be used in most places as if it was a QIODevice pointer. Once initialized with a QIODevice pointer, the class masquerades as one itself.
Constructors and destructor
|
(
Constructs a PiiSocketDevice that wraps the given socket. |
|
|
Constructs a copy of other. |
|
|
(
Constructs a PiiSocketDevice that wraps the given socket. |
|
|
Constructs a PiiSocketDevice that wraps the given device. |
|
|
( )
Constructs a null socket, which behaves like a null pointer. |
|
|
( )
|
Public member functions
|
( )
|
|
|
void
|
( )
Disconnects the socket if it is connected to a server. |
|
bool
|
( )
Returns |
|
bool
|
( )
Returns |
|
( )
|
|
|
|
|
|
qint64
|
Reads at most maxSize bytes of data from the socket and places it to data. |
|
qint64
|
Writes at most maxSize bytes of data from data to the socket. |
Function details
-
PiiSocketDevice
(- QAbstractSocket * socket
Constructs a PiiSocketDevice that wraps the given socket.
-
PiiSocketDevice
Constructs a copy of other.
-
PiiSocketDevice
(- QLocalSocket * socket
Constructs a PiiSocketDevice that wraps the given socket.
-
PiiSocketDevice
Constructs a PiiSocketDevice that wraps the given device.
The type of the device will be automatically determined. All Qt socket types are recognized.
-
PiiSocketDevice
()Constructs a null socket, which behaves like a null pointer.
Any access to the socket will cause a segfault.
-
~PiiSocketDevice
() -
QIODevice * device
() -
void disconnect
()Disconnects the socket if it is connected to a server.
-
bool isReadable
()Returns
trueif it is possible that the socket still has data andfalseotherwise.This function handles special cases such as a disconnected socket with unread data in its receive buffer.
-
bool isWritable
()Returns
trueif the socket can be written to andfalseotherwise. -
operator QIODevice *
() -
QIODevice * operator->
() -
PiiSocketDevice & operator=
-
qint64 readWaited
Reads at most maxSize bytes of data from the socket and places it to data.
If not enough data is immediately available, waits at most waitTime milliseconds to get more. If controller is given, it can be used to terminate a long wait.
-
qint64 writeWaited
Writes at most maxSize bytes of data from data to the socket.
If all data cannot be immediately written, waits at most waitTime milliseconds. If controller is given, it can be used to terminate a long wait.
Add a note
Not a single note added yet. Be the first, add yours.