|
|
| UdpSocket () |
| | Creates a closed socket.
|
|
| UdpSocket (System::EventLoop &loop) |
| | Creates a socket and attaches it to loop.
|
|
| ~UdpSocket () |
| | Destroys the socket.
|
| void | bind (const Endpoint &ep) |
| | Binds to local endpoint ep.
|
| void | bind (const Endpoint &ep, const UdpSocketOptions &o) |
| | Binds to ep with o.
|
| bool | beginBind (const Endpoint &ep) |
| | Begins binding to ep.
|
| bool | beginBind (const Endpoint &ep, const UdpSocketOptions &o) |
| | Begins binding to ep with o.
|
| void | endBind () |
| | Ends binding to a local endpoint.
|
|
Signal< UdpSocket & > & | bound () |
| | Returns the signal that the socket was bound.
|
|
bool | isBound () const |
| | Returns true if the socket is bound.
|
| void | connect (const Endpoint &ep) |
| | Connects to ep.
|
| void | connect (const Endpoint &ep, const UdpSocketOptions &o) |
| | Connects to ep with o.
|
| void | setTarget (const Endpoint &ep) |
| | Sets the send target to ep.
|
| void | setTarget (const Endpoint &ep, const UdpSocketOptions &o) |
| | Sets the send target to ep with o.
|
| bool | beginConnect (const Endpoint &ep) |
| | Begins connecting to ep.
|
| bool | beginConnect (const Endpoint &ep, const UdpSocketOptions &o) |
| | Begins connecting to ep with o.
|
| void | endConnect () |
| | Ends connecting to an endpoint.
|
|
Signal< UdpSocket & > & | connected () |
| | Returns the signal that the socket was connected.
|
|
bool | isConnected () const |
| | Returns true if the socket is connected.
|
|
void | joinMulticastGroup (const std::string &ipaddr) |
| | Joins multicast group ipaddr.
|
|
void | localEndpoint (Endpoint &ep) const |
| | Writes the local endpoint into ep.
|
|
const Endpoint & | remoteEndpoint () const |
| | Returns the remote endpoint.
|
|
void | close () |
| | Closes the device.
|
|
void | setTimeout (std::size_t timeout) |
| | Sets the timeout for blocking I/O in milliseconds.
|
|
void | beginRead (char *buffer, std::size_t n) |
| | Begins to read data.
|
|
std::size_t | endRead () |
| | Ends reading data.
|
| std::size_t | read (char *buffer, std::size_t n) |
| | Read data from I/O device.
|
|
void | beginWrite (const char *buffer, std::size_t n) |
| | Begins to write data.
|
|
std::size_t | endWrite () |
| | Ends writing data.
|
| std::size_t | write (const char *buffer, std::size_t n) |
| | Write data to I/O device.
|
|
bool | seekable () const |
| | Returns true if device is seekable.
|
| pos_type | seek (off_type offset, seekdir sd) |
| | Moves the read position to the given offset.
|
| std::size_t | peek (char *buffer, std::size_t n) |
| | Peek data from I/O device without consuming them.
|
| void | sync () |
| | Synchronize device.
|
| pos_type | position () |
| | Returns the current I/O position.
|
|
bool | isEof () const |
| | Returns if the device has reached EOF.
|
| Signal< IODevice & > & | inputReady () |
| | Notifies about available data.
|
| Signal< IODevice & > & | outputReady () |
| | Notifies when data can be written.
|
|
bool | isReading () const |
| | Returns true if the device is reading.
|
|
bool | isWriting () const |
| | Returns true if the device is writing.
|
|
EventLoop * | loop () const |
| | Returns the used event loop.
|
|
void | setActive (EventLoop &parent) |
| | Sets the parent loop, so that operations can be run.
|
|
void | detach () |
| | Remove from event loop and cancels outstanding operations.
|
|
void | cancel () |
| | Cancels all operations.
|
|
bool | run () |
| | Run operation if it is ready.
|
|
EventLoop * | parent () const |
| | Returns the used event loop.
|
UdpSocket is the datagram IODevice for unicast, broadcast, and multicast, so one type covers all three modes. After a local bind or a send destination is set, read() and write() are the inherited device operations, blocking or asynchronous, except that each write() sends one datagram and each read() receives one datagram.
bind() sets the local endpoint that receives datagrams, throwing AddressInUse if that address is already occupied and AccessFailed if the host cannot be used. connect() associates a remote peer so writes go there and reads come from it, while setTarget() sets a send destination without associating the socket, which is the path broadcast and multicast sends use. connect() and setTarget() throw AccessFailed when the host is not reachable.
- Asynchronous bind and connect
beginBind() and beginConnect() start those operations on an attached event loop and return true when the operation completed immediately. bound() and connected() are emitted when the attempt finishes, and endBind() and endConnect() complete it. The socket must be attached before either begin method is called. isBound() and isConnected() report the current associations, localEndpoint() writes the local side, and remoteEndpoint() is the associated peer.
- Broadcast and multicast
Broadcast send sets the broadcast option and uses the IPv4 broadcast endpoint as the target, while multicast send uses a multicast group address as the target. To receive a group's datagrams, bind first, then joinMulticastGroup(). UdpSocketOptions also set the hop limit; those values configure an operation, but they do not open a socket.
The first example is asynchronous unicast: one socket binds the local any-address, the other connects to loopback, and each slot completes the begin operation before I/O. The second example is a broadcast send, and the third binds, joins a group, and sends to that group.
char buffer[256];
{
}
{
}
static Endpoint ip4Any(unsigned short port)
Creates the IPv4 any-address for port.
static Endpoint ip4Loopback(unsigned short port)
Creates the IPv4 loopback address for port.
UDP datagram socket.
Definition UdpSocket.h:193
void endConnect()
Ends connecting to an endpoint.
Signal< UdpSocket & > & connected()
Returns the signal that the socket was connected.
Definition UdpSocket.h:311
bool beginBind(const Endpoint &ep)
Begins binding to ep.
bool beginConnect(const Endpoint &ep)
Begins connecting to ep.
Signal< UdpSocket & > & bound()
Returns the signal that the socket was bound.
Definition UdpSocket.h:254
void endBind()
Ends binding to a local endpoint.
ConstMethodSlot< R, ClassT, As... > slot(ClassT &object, R(BaseT::*method)(As...) const)
Returns a slot object for the given object/member pair.
Definition ConstMethod.h:172
void run()
Starts the loop.
void beginWrite(const char *buffer, std::size_t n)
Begins to write data.
void beginRead(char *buffer, std::size_t n)
Begins to read data.
EventLoop * loop() const
Returns the used event loop.
Definition IODevice.h:240
Platform event loop.
Definition MainLoop.h:51
void setActive(EventLoop &parent)
Sets the parent loop, so that operations can be run.
sender.
write(
"Hello", 5);
static Endpoint ip4Broadcast(unsigned short port)
Creates the IPv4 broadcast address for port.
UDP socket bind and send options.
Definition UdpSocket.h:47
void setBroadcast()
Enables UDP broadcast.
Definition UdpSocket.h:72
void setTarget(const Endpoint &ep)
Sets the send target to ep.
std::size_t write(const char *buffer, std::size_t n)
Write data to I/O device.
sender.
write(
"Hello", 5);
Host and service address.
Definition Endpoint.h:77
void joinMulticastGroup(const std::string &ipaddr)
Joins multicast group ipaddr.
void bind(const Endpoint &ep)
Binds to local endpoint ep.