00001 00034 #ifndef ASYNC_UDP_SOCKET_INCLUDED 00035 #define ASYNC_UDP_SOCKET_INCLUDED 00036 00037 00038 /**************************************************************************** 00039 * 00040 * System Includes 00041 * 00042 ****************************************************************************/ 00043 00044 #include <sigc++/sigc++.h> 00045 #include <stdint.h> 00046 00047 00048 /**************************************************************************** 00049 * 00050 * Project Includes 00051 * 00052 ****************************************************************************/ 00053 00054 00055 00056 /**************************************************************************** 00057 * 00058 * Local Includes 00059 * 00060 ****************************************************************************/ 00061 00062 00063 00064 /**************************************************************************** 00065 * 00066 * Forward declarations 00067 * 00068 ****************************************************************************/ 00069 00070 class UdpPacket; 00071 00072 00073 /**************************************************************************** 00074 * 00075 * Namespace 00076 * 00077 ****************************************************************************/ 00078 00079 namespace Async 00080 { 00081 00082 00083 /**************************************************************************** 00084 * 00085 * Forward declarations of classes inside of the declared namespace 00086 * 00087 ****************************************************************************/ 00088 00089 class FdWatch; 00090 class IpAddress; 00091 00092 00093 /**************************************************************************** 00094 * 00095 * Defines & typedefs 00096 * 00097 ****************************************************************************/ 00098 00099 00100 00101 /**************************************************************************** 00102 * 00103 * Exported Global Variables 00104 * 00105 ****************************************************************************/ 00106 00107 00108 00109 /**************************************************************************** 00110 * 00111 * Class definitions 00112 * 00113 ****************************************************************************/ 00114 00124 class UdpSocket : public SigC::Object 00125 { 00126 public: 00132 UdpSocket(uint16_t local_port=0); 00133 00137 ~UdpSocket(void); 00138 00147 bool initOk(void) const { return (sock != -1); } 00148 00157 bool write(const IpAddress& remote_ip, int remote_port, const void *buf, 00158 int count); 00159 00166 SigC::Signal3<void, const IpAddress&, void *, int> dataReceived; 00167 00173 SigC::Signal1<void, bool> sendBufferFull; 00174 00175 protected: 00176 00177 private: 00178 int sock; 00179 FdWatch * rd_watch; 00180 FdWatch * wr_watch; 00181 UdpPacket * send_buf; 00182 00183 void cleanup(void); 00184 void handleInput(FdWatch *watch); 00185 void sendRest(FdWatch *watch); 00186 00187 }; /* class UdpSocket */ 00188 00189 00190 } /* namespace */ 00191 00192 #endif /* ASYNC_UDP_SOCKET_INCLUDED */ 00193 00194 00195 00196 /* 00197 * This file has not been truncated 00198 */ 00199