diff --git a/examples/proto_debuger/udp_form.cpp b/examples/proto_debuger/udp_form.cpp index 47c2df3f..4cb74cf2 100644 --- a/examples/proto_debuger/udp_form.cpp +++ b/examples/proto_debuger/udp_form.cpp @@ -14,8 +14,6 @@ UdpForm::~UdpForm() void UdpForm::Init() { ui::ChildBox::Init(); - - ui::Label* m_label_1 = dynamic_cast(FindSubControl(L"uart_info_label")); ui::RichEdit* m_rich_edit_1 = dynamic_cast(FindSubControl(L"uart_recv_eidt")); ui::RichEdit* m_rich_edit_2 = dynamic_cast(FindSubControl(L"lua_script")); @@ -24,7 +22,6 @@ void UdpForm::Init() ui::Button* m_button_2 = dynamic_cast(FindSubControl(L"btn_close_uart")); ui::Button* m_button_3 = dynamic_cast(FindSubControl(L"btn_save_lua")); ui::Button* m_button_4 = dynamic_cast(FindSubControl(L"btn_do_lua")); - } LuaDelegate* UdpForm::LuaVM() @@ -34,8 +31,10 @@ LuaDelegate* UdpForm::LuaVM() void UdpForm::ShowDataInEdit(const char*) { + } void UdpForm::HandleMessage(ui::EventArgs& msg) { + } diff --git a/examples/proto_debuger/udp_form.h b/examples/proto_debuger/udp_form.h index ce0b3c29..c5da9616 100644 --- a/examples/proto_debuger/udp_form.h +++ b/examples/proto_debuger/udp_form.h @@ -25,13 +25,11 @@ class UdpForm : public ui::ChildBox { - public: UdpForm(ui::Window* hwnd, string url, uint32_t port, UdpDataGramLibevent* p); ~UdpForm(); virtual void Init() override; LuaDelegate* LuaVM(); - protected: void ShowDataInEdit(const char*) ; @@ -45,7 +43,6 @@ private: ui::Button* m_button_3; ui::Button* m_button_4; - virtual void HandleMessage(ui::EventArgs& msg); std::string mLuaScript; std::string m_url; diff --git a/examples/proto_debuger/udp_group_libevent.cpp b/examples/proto_debuger/udp_group_libevent.cpp new file mode 100644 index 00000000..23ab8b80 --- /dev/null +++ b/examples/proto_debuger/udp_group_libevent.cpp @@ -0,0 +1,3 @@ +#include "udp_group_libevent.h" + + diff --git a/examples/proto_debuger/udp_group_libevent.h b/examples/proto_debuger/udp_group_libevent.h new file mode 100644 index 00000000..85e32fba --- /dev/null +++ b/examples/proto_debuger/udp_group_libevent.h @@ -0,0 +1,55 @@ +#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 UdpGroupLibevent { +public: + typedef std::function OnReadDataHandle; + UdpGroupLibevent(std::string ip, uint32_t port); + 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); + 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; +}; + +