Async  1.5.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 
71 class UdpPacket;
72 
73 
74 /****************************************************************************
75  *
76  * Namespace
77  *
78  ****************************************************************************/
79 
80 namespace Async
81 {
82 
83 
84 /****************************************************************************
85  *
86  * Forward declarations of classes inside of the declared namespace
87  *
88  ****************************************************************************/
89 
90 class 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 
124 class UdpSocket : public sigc::trackable
125 {
126  public:
134  UdpSocket(uint16_t local_port=0, const IpAddress &bind_ip=IpAddress());
135 
139  ~UdpSocket(void);
140 
149  bool initOk(void) const { return (sock != -1); }
150 
159  bool write(const IpAddress& remote_ip, int remote_port, const void *buf,
160  int count);
161 
167  int fd(void) const { return sock; }
168 
176  sigc::signal<void, const IpAddress&, uint16_t, void*, int> dataReceived;
177 
183  sigc::signal<void, bool> sendBufferFull;
184 
185  protected:
186 
187  private:
188  int sock;
189  FdWatch * rd_watch;
190  FdWatch * wr_watch;
191  UdpPacket * send_buf;
192 
193  void cleanup(void);
194  void handleInput(FdWatch *watch);
195  void sendRest(FdWatch *watch);
196 
197 }; /* class UdpSocket */
198 
199 
200 } /* namespace */
201 
202 #endif /* ASYNC_UDP_SOCKET_INCLUDED */
203 
204 
205 
206 /*
207  * This file has not been truncated
208  */
209 
sigc::signal< void, const IpAddress &, uint16_t, void *, int > dataReceived
A signal that is emitted when data has been received.
~UdpSocket(void)
Destructor.
bool write(const IpAddress &remote_ip, int remote_port, const void *buf, int count)
Write data to the remote host.
int fd(void) const
Get the file descriptor for the UDP socket.
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
bool initOk(void) const
Check if the initialization was ok.
sigc::signal< void, bool > sendBufferFull
A signal that is emitted when the send buffer is full.
Namespace for the asynchronous programming classes.
A class for working with UDP sockets.
Platform independent representation of an IP address.
A class for representing an IP address in an OS independent way.
UdpSocket(uint16_t local_port=0, const IpAddress &bind_ip=IpAddress())
Constructor.