no message
This commit is contained in:
parent
ef927012e3
commit
c627a583b5
@ -303,8 +303,8 @@ void BasicForm::InitWindow(){
|
||||
|
||||
mRightSide->RemoveAll();
|
||||
|
||||
this->SetMinInfo(1024, 768, true);
|
||||
this->SetInitSize(1024, 768, false, false);
|
||||
this->SetMinInfo(1280, 768, true);
|
||||
this->SetInitSize(1280, 768, false, false);
|
||||
ui::UiRect maxRect = GetMaximizeInfo();
|
||||
|
||||
this->Invalidate(maxRect);
|
||||
|
@ -12,16 +12,13 @@ extern "C" {
|
||||
#include "event2/thread.h"
|
||||
};
|
||||
|
||||
|
||||
TcpServerFrom::TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p)
|
||||
{
|
||||
m_server = p;
|
||||
m_url = url;
|
||||
m_port = port;
|
||||
|
||||
|
||||
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 ,
|
||||
std::placeholders::_2, std::placeholders::_3 );
|
||||
TcpServerLibevent::OnAccept handler = std::bind(&TcpServerFrom::OnNewConnAccept, this,std::placeholders::_1 );
|
||||
m_server->SetNewConnectionHandle(handler);
|
||||
TcpServerLibevent::OnDisconnect handler2 = std::bind(&TcpServerFrom::OnDisConnected,
|
||||
this, std::placeholders::_1);
|
||||
@ -60,18 +57,26 @@ void TcpServerFrom::Init()
|
||||
m_label_1->SetText(p);
|
||||
}
|
||||
|
||||
ConnectionLibevent* TcpServerFrom::OnNewConnAccept(struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1)
|
||||
void TcpServerFrom::OnNewConnAccept(ConnectionLibevent*p)
|
||||
{
|
||||
std::cout << "TcpServerFrom OnNewConnAccept fd" << fd << " addr " << inet_ntoa(p1->sin_addr)<<std::endl;
|
||||
std::cout << "TcpServerFrom OnNewConnAccept addr " << p->IpAddress()<<std::endl;
|
||||
updateStatus();
|
||||
|
||||
wchar_t text[40] = L"";
|
||||
wsprintf(text, L"Á¬½ÓÊý:%d", m_server->ConnectionCount());
|
||||
m_label_1->SetText(text);
|
||||
return new ConnectionLibevent(ev, fd, p1);
|
||||
return;
|
||||
}
|
||||
|
||||
void TcpServerFrom::OnDisConnected(ConnectionLibevent* cli)
|
||||
{
|
||||
std::cout << "TcpServerFrom Disconnected" << cli->IpAddress() << " fd " << cli->SocketFd() << std::endl;
|
||||
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
void TcpServerFrom::updateStatus()
|
||||
{
|
||||
wchar_t tmp[200] = L"";
|
||||
wsprintf(tmp, L"监听地址: %s 端口: %d 在线连接数目: %d", string2wstring(m_url).c_str(),
|
||||
m_port,
|
||||
m_server->ConnectionCount());
|
||||
m_label_1->SetText(tmp);
|
||||
}
|
||||
|
@ -16,12 +16,14 @@ public:
|
||||
TcpServerFrom(ui::Window* hwnd, string url, uint32_t port, TcpServerLibevent* p);
|
||||
TcpServerLibevent* ServerP();
|
||||
virtual void Init() override;
|
||||
ConnectionLibevent* OnNewConnAccept(struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1);
|
||||
void OnNewConnAccept(ConnectionLibevent*);
|
||||
void OnDisConnected(ConnectionLibevent*);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
void updateStatus();
|
||||
|
||||
TcpServerLibevent* m_server;
|
||||
std::string m_url;
|
||||
uint32_t m_port;
|
||||
|
@ -39,9 +39,10 @@ ConnectionLibevent::ConnectionLibevent(struct bufferevent* ev, uint32_t fd, stru
|
||||
std::cout << "\r\n " << m_addr << " ConnectionLibevent " << inet_ntoa(m_addr->sin_addr) << std::endl;
|
||||
}
|
||||
|
||||
ConnectionLibevent* defaultConnAccept(struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1) {
|
||||
std::cout << "defaultConnAccept " << inet_ntoa(p1->sin_addr);
|
||||
return new ConnectionLibevent(ev, fd, p1);
|
||||
void defaultConnAccept(ConnectionLibevent*p1) {
|
||||
std::cout << "defaultConnAccept " << p1->Close();
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void defaultConnClose(ConnectionLibevent*p) {
|
||||
@ -152,13 +153,14 @@ void ServerCallbacks::cb_listener(struct evconnlistener* listener, evutil_socket
|
||||
bev = bufferevent_socket_new(server->m_event_base, fd, BEV_OPT_CLOSE_ON_FREE);
|
||||
std::cout << "null 4" << bev << std::endl;
|
||||
// 这是一个bad design,
|
||||
ConnectionLibevent* conn = server->m_handle_accept(bev, ntohs(client->sin_port), client);
|
||||
ConnectionLibevent* conn = new ConnectionLibevent(bev, ntohs(client->sin_port), client);
|
||||
conn->SetServer(server);
|
||||
server->AddConnection(ntohs(client->sin_port), conn);
|
||||
bufferevent_setcb(bev, read_cb,
|
||||
write_cb,
|
||||
event_cb,
|
||||
conn);
|
||||
server->m_handle_accept(conn);
|
||||
bufferevent_enable(bev, EV_READ | EV_WRITE);
|
||||
}
|
||||
else {
|
||||
@ -242,8 +244,8 @@ int TcpServerLibevent::AddConnection(uint32_t fd, ConnectionLibevent* p) {
|
||||
int TcpServerLibevent::RemoveConnection(uint32_t fd) {
|
||||
if (m_map_client.find(fd) != m_map_client.end()) {
|
||||
auto pClient = m_map_client[fd];
|
||||
this->m_handle_disconnect(pClient);
|
||||
m_map_client.erase(fd);
|
||||
this->m_handle_disconnect(pClient);
|
||||
delete pClient;
|
||||
return 0;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class TcpServerLibevent {
|
||||
FAIL
|
||||
}SERVER_STATUS;
|
||||
public:
|
||||
typedef std::function<ConnectionLibevent* (struct bufferevent* ev, uint32_t fd, struct sockaddr_in* p1)> OnAccept;
|
||||
typedef std::function<void (ConnectionLibevent*)> OnAccept;
|
||||
typedef std::function<void (ConnectionLibevent*)> OnDisconnect;
|
||||
|
||||
TcpServerLibevent(int port, string bindip);
|
||||
|
Loading…
Reference in New Issue
Block a user