Async  1.4.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 
175  sigc::signal<void, const IpAddress&, void *, int> dataReceived;
176 
182  sigc::signal<void, bool> sendBufferFull;
183 
184  protected:
185 
186  private:
187  int sock;
188  FdWatch * rd_watch;
189  FdWatch * wr_watch;
190  UdpPacket * send_buf;
191 
192  void cleanup(void);
193  void handleInput(FdWatch *watch);
194  void sendRest(FdWatch *watch);
195 
196 }; /* class UdpSocket */
197 
198 
199 } /* namespace */
200 
201 #endif /* ASYNC_UDP_SOCKET_INCLUDED */
202 
203 
204 
205 /*
206  * This file has not been truncated
207  */
208 
~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.
bool initOk(void) const
Check if the initialization was ok.
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
sigc::signal< void, const IpAddress &, void *, int > dataReceived
A signal that is emitted when data has been received.
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.