|
| | AbstractSocket (SocketType type, ObjectBase *parent=nullptr) |
| | Constructs an AbstractSocket.
|
| |
|
virtual | ~AbstractSocket () |
| | Destructor. Closes the socket if open.
|
| |
|
SocketType | socketType () const |
| | Returns the socket type.
|
| |
|
SocketState | state () const |
| | Returns the current socket state.
|
| |
| Error | bind (const SocketAddress &address) |
| | Binds the socket to a local address.
|
| |
| Error | connectToHost (const SocketAddress &address) |
| | Initiates a connection to a remote host.
|
| |
| void | disconnectFromHost () |
| | Disconnects from the remote host.
|
| |
|
SocketAddress | localAddress () const |
| | Returns the local address the socket is bound to.
|
| |
|
SocketAddress | peerAddress () const |
| | Returns the address of the connected peer.
|
| |
| Error | waitForConnected (unsigned int timeoutMs=0) |
| | Blocks until the socket is connected or timeout.
|
| |
| int | socketDescriptor () const |
| | Returns the raw socket file descriptor.
|
| |
| void | setSocketDescriptor (int fd) |
| | Adopts an existing file descriptor as the socket.
|
| |
| Error | setSocketOption (int level, int option, int value) |
| | Sets a raw socket option via setsockopt().
|
| |
| Result< int > | socketOption (int level, int option) const |
| | Gets a raw socket option via getsockopt().
|
| |
| bool | isSequential () const override |
| | Returns true — sockets are sequential (non-seekable).
|
| |
| | PROMEKI_SIGNAL (connected) |
| | Emitted when a connection is established.
|
| |
| | PROMEKI_SIGNAL (disconnected) |
| | Emitted when the socket is disconnected.
|
| |
| | PROMEKI_SIGNAL (stateChanged, SocketState) |
| | Emitted when the socket state changes.
|
| |
| | IODevice (ObjectBase *parent=nullptr) |
| | Constructs an IODevice.
|
| |
|
virtual | ~IODevice () |
| | Destructor.
|
| |
| virtual Error | open (OpenMode mode)=0 |
| | Opens the device with the specified mode.
|
| |
| virtual Error | close ()=0 |
| | Closes the device.
|
| |
| virtual bool | isOpen () const =0 |
| | Returns true if the device is open.
|
| |
| virtual int64_t | read (void *data, int64_t maxSize)=0 |
| | Reads up to maxSize bytes into data.
|
| |
| virtual int64_t | write (const void *data, int64_t maxSize)=0 |
| | Writes up to maxSize bytes from data.
|
| |
| virtual void | flush () |
| | Flushes any buffered output data to the underlying device.
|
| |
| virtual int64_t | bytesAvailable () const |
| | Returns the number of bytes available for reading.
|
| |
| virtual bool | waitForReadyRead (unsigned int timeoutMs=0) |
| | Waits until data is available for reading or timeout.
|
| |
| virtual bool | waitForBytesWritten (unsigned int timeoutMs=0) |
| | Waits until all pending data has been written or timeout.
|
| |
| virtual Error | seek (int64_t pos) |
| | Seeks to the given byte offset from the beginning.
|
| |
| virtual int64_t | pos () const |
| | Returns the current read/write position.
|
| |
| virtual Result< int64_t > | size () const |
| | Returns the total size of the device in bytes.
|
| |
| virtual bool | atEnd () const |
| | Returns true if the current position is at the end.
|
| |
| OpenMode | openMode () const |
| | Returns the current open mode.
|
| |
| bool | isReadable () const |
| | Returns true if the device is readable.
|
| |
| bool | isWritable () const |
| | Returns true if the device is writable.
|
| |
| Error | error () const |
| | Returns the current error state.
|
| |
|
void | clearError () |
| | Clears the error state to Ok.
|
| |
| | PROMEKI_SIGNAL (readyRead) |
| | Emitted when data is available for reading.
|
| |
| | PROMEKI_SIGNAL (bytesWritten, int64_t) |
| | Emitted when bytes have been written.
|
| |
| | PROMEKI_SIGNAL (errorOccurred, Error) |
| | Emitted when an error occurs.
|
| |
| | PROMEKI_SIGNAL (aboutToClose) |
| | Emitted just before the device is closed.
|
| |
| | ObjectBase (ObjectBase *p=nullptr) |
| | Default ObjectBase constructor.
|
| |
|
virtual | ~ObjectBase () |
| | Destructor. Emits aboutToDestroy, detaches from parent, and destroys children.
|
| |
| ObjectBase * | parent () const |
| | Returns the parent object, if one. nullptr if none.
|
| |
|
void | setParent (ObjectBase *p) |
| | Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one.
|
| |
| const ObjectBaseList & | childList () const |
| | Returns a list of children of this object.
|
| |
| template<typename... Args> |
| int | registerSlot (Slot< Args... > *slot) |
| | Registers a slot with this object and assigns it an ID.
|
| |
| EventLoop * | eventLoop () const |
| | Returns the EventLoop this object is affiliated with.
|
| |
| void | moveToThread (EventLoop *loop) |
| | Changes the EventLoop affinity of this object.
|
| |
| int | startTimer (unsigned int intervalMs, bool singleShot=false) |
| | Starts a timer on this object's EventLoop.
|
| |
| void | stopTimer (int timerId) |
| | Stops a timer previously started with startTimer().
|
| |
|
template<typename... Args> |
| PROMEKI_NAMESPACE_BEGIN void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
| |
Abstract base class for network sockets.
AbstractSocket derives from IODevice and provides the common interface for TCP, UDP, and raw sockets. It manages socket state, local and peer addresses, and raw socket descriptor lifecycle.
Subclasses implement open(), close(), read(), and write() for their specific protocol. The socket descriptor is created by open() and closed by close().
This class must only be used from the thread that created it (or moved to via moveToThread()).
- Example
Lightweight error code wrapper for the promeki library.
Definition error.h:39
@ ReadWrite
Open for reading and writing.
Definition iodevice.h:37
Dynamic array container wrapping std::vector.
Definition list.h:40
static SocketAddress any(uint16_t port)
Returns INADDR_ANY with the given port.
Definition socketaddress.h:71
Datagram-oriented UDP socket with multicast support.
Definition udpsocket.h:47