#pragma once #include #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 #include #endif #ifdef linux #include #include #include #define EVENT__HAVE_PTHREADS #endif #include #include #include #include #include #include #include class UdpDataGramLibevent { public: typedef std::function OnReadDataHandle; UdpDataGramLibevent(std::string ip, uint32_t port); UdpDataGramLibevent(std::string ip, uint32_t port, std::string group_addr); OnReadDataHandle OnReadHandle(); typedef enum { RUNNING, STOP, FAIL }STATUS; friend void read_cb(int, short, void*); void SetOnReadHandle(OnReadDataHandle); void SendTo(const char* dat, uint32_t len, std::string ip, int port); int SocketFD(); private: int bind_socket(struct event* ev, const char* ip, uint16_t port); int bind_socket_with_group(struct event* ev, const char* ip, uint16_t port, const char* udp_group); uint32_t m_port; // std::string m_bind_ip; // uint16_t m_backlog; int m_sock_fd; struct sockaddr_in m_bind_addr; // struct event* m_event; STATUS m_status; // std::thread* m_thread; // intptr_t mSocketFD; // socket OnReadDataHandle mOnRead; };