Async 1.8.0
AsyncUdpSocket.h
Go to the documentation of this file.
1
34#ifndef ASYNC_UDP_SOCKET_INCLUDED
35#define ASYNC_UDP_SOCKET_INCLUDED
36
37
38/****************************************************************************
39 *
40 * System Includes
41 *
42 ****************************************************************************/
43
44#include <sigc++/sigc++.h>
45#include <stdint.h>
46
47
48/****************************************************************************
49 *
50 * Project Includes
51 *
52 ****************************************************************************/
53
54#include <AsyncIpAddress.h>
55
56
57/****************************************************************************
58 *
59 * Local Includes
60 *
61 ****************************************************************************/
62
63
64
65/****************************************************************************
66 *
67 * Forward declarations
68 *
69 ****************************************************************************/
70
71class UdpPacket;
72
73
74/****************************************************************************
75 *
76 * Namespace
77 *
78 ****************************************************************************/
79
80namespace Async
81{
82
83
84/****************************************************************************
85 *
86 * Forward declarations of classes inside of the declared namespace
87 *
88 ****************************************************************************/
89
90class FdWatch;
91
92
93/****************************************************************************
94 *
95 * Defines & typedefs
96 *
97 ****************************************************************************/
98
99
100
101/****************************************************************************
102 *
103 * Exported Global Variables
104 *
105 ****************************************************************************/
106
107
108
109/****************************************************************************
110 *
111 * Class definitions
112 *
113 ****************************************************************************/
114
124class UdpSocket : public sigc::trackable
125{
126 public:
134 UdpSocket(uint16_t local_port=0, const IpAddress &bind_ip=IpAddress());
135
139 virtual ~UdpSocket(void);
140
149 virtual bool initOk(void) const { return (sock != -1); }
150
156
161 uint16_t localPort(void) const;
162
171 virtual bool write(const IpAddress& remote_ip, int remote_port,
172 const void *buf, int count);
173
179 virtual int fd(void) const { return sock; }
180
188 sigc::signal<void, const IpAddress&, uint16_t, void*, int> dataReceived;
189
195 sigc::signal<void, bool> sendBufferFull;
196
197 protected:
198 virtual void onDataReceived(const IpAddress& ip, uint16_t port, void* buf,
199 int count);
200
201 private:
202 int sock;
203 FdWatch * rd_watch;
204 FdWatch * wr_watch;
205 UdpPacket * send_buf;
206
207 void cleanup(void);
208 void handleInput(FdWatch *watch);
209 void sendRest(FdWatch *watch);
210
211}; /* class UdpSocket */
212
213
214} /* namespace */
215
216#endif /* ASYNC_UDP_SOCKET_INCLUDED */
217
218
219
220/*
221 * This file has not been truncated
222 */
223
Platform independent representation of an IP address.
A class for watching file descriptors.
A class for representing an IP address in an OS independent way.
A class for working with UDP sockets.
virtual ~UdpSocket(void)
Destructor.
uint16_t localPort(void) const
Get the local UDP port associated with this connection.
Async::IpAddress localAddr(void) const
Get the local IP address associated with this connection.
virtual bool write(const IpAddress &remote_ip, int remote_port, const void *buf, int count)
Write data to the remote host.
virtual int fd(void) const
Get the file descriptor for the UDP socket.
sigc::signal< void, bool > sendBufferFull
A signal that is emitted when the send buffer is full.
sigc::signal< void, const IpAddress &, uint16_t, void *, int > dataReceived
A signal that is emitted when data has been received.
UdpSocket(uint16_t local_port=0, const IpAddress &bind_ip=IpAddress())
Constructor.
virtual bool initOk(void) const
Check if the initialization was ok.
virtual void onDataReceived(const IpAddress &ip, uint16_t port, void *buf, int count)
Namespace for the asynchronous programming classes.