Abstract base class for network sockets.
Definition abstractsocket.h:38
int _fd
Socket file descriptor.
Definition abstractsocket.h:203
void setSocketDescriptor(int fd)
Adopts an existing file descriptor as the socket.
void updateLocalAddress()
Updates the local address from the socket descriptor.
SocketType
The type of socket.
Definition abstractsocket.h:42
@ UdpSocketType
Datagram-oriented UDP socket.
Definition abstractsocket.h:44
@ RawSocketType
Raw Ethernet frame socket.
Definition abstractsocket.h:45
@ TcpSocketType
Stream-oriented TCP socket.
Definition abstractsocket.h:43
Error setNonBlocking(bool enable)
Sets the socket to non-blocking mode.
SocketAddress _peerAddress
Connected peer address.
Definition abstractsocket.h:207
SocketType socketType() const
Returns the socket type.
Definition abstractsocket.h:69
bool isSequential() const override
Returns true — sockets are sequential (non-seekable).
Definition abstractsocket.h:154
virtual ~AbstractSocket()
Destructor. Closes the socket if open.
Error setSocketOption(int level, int option, int value)
Sets a raw socket option via setsockopt().
SocketType _type
Socket type.
Definition abstractsocket.h:205
PROMEKI_SIGNAL(stateChanged, SocketState)
Emitted when the socket state changes.
PROMEKI_SIGNAL(connected)
Emitted when a connection is established.
SocketState _state
Current socket state.
Definition abstractsocket.h:204
PROMEKI_SIGNAL(disconnected)
Emitted when the socket is disconnected.
SocketState state() const
Returns the current socket state.
Definition abstractsocket.h:72
Error connectToHost(const SocketAddress &address)
Initiates a connection to a remote host.
int socketDescriptor() const
Returns the raw socket file descriptor.
Definition abstractsocket.h:121
AbstractSocket(SocketType type, ObjectBase *parent=nullptr)
Constructs an AbstractSocket.
Error waitForConnected(unsigned int timeoutMs=0)
Blocks until the socket is connected or timeout.
Result< int > socketOption(int level, int option) const
Gets a raw socket option via getsockopt().
SocketAddress peerAddress() const
Returns the address of the connected peer.
Definition abstractsocket.h:108
void closeSocket()
Closes the socket descriptor.
SocketAddress _localAddress
Local bound address.
Definition abstractsocket.h:206
SocketAddress localAddress() const
Returns the local address the socket is bound to.
Definition abstractsocket.h:105
void setState(SocketState state)
Sets the socket state and emits stateChanged.
SocketState
The current state of the socket.
Definition abstractsocket.h:49
@ Connecting
A non-blocking connect is in progress.
Definition abstractsocket.h:51
@ Listening
Socket is listening for incoming connections (TCP server).
Definition abstractsocket.h:55
@ Bound
Socket is bound to a local address.
Definition abstractsocket.h:53
@ Closing
Socket is being closed.
Definition abstractsocket.h:54
@ Unconnected
Socket is not connected or bound.
Definition abstractsocket.h:50
@ Connected
Socket is connected to a peer.
Definition abstractsocket.h:52
Error createSocket(int domain, int type, int protocol=0)
Creates the underlying socket descriptor.
void disconnectFromHost()
Disconnects from the remote host.
Error bind(const SocketAddress &address)
Binds the socket to a local address.
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Abstract base class for all I/O devices.
Definition iodevice.h:29
Dynamic array container wrapping std::vector.
Definition list.h:40
Base object for promeki.
Definition objectbase.h:129
ObjectBase * parent() const
Returns the parent object, if one. nullptr if none.
Definition objectbase.h:258
Network address with port number.
Definition socketaddress.h:50
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19
const T & value(const Result< T > &r)
Returns the value from a Result.
Definition result.h:56