no message
parent
37b0f641d9
commit
ff8ac94b4d
|
@ -11,6 +11,8 @@ target_link_libraries(superdog_server event.lib event_extra.lib event_core.lib
|
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
target_link_libraries(superdog_server event.a event_extra.a libevent_pthreads.a event_core.a pthread)
|
||||
endif()
|
||||
|
||||
|
||||
project(swarm_client)
|
||||
add_executable(swarm_client swarm.cpp tcp_client.cpp tcp_server_libevent.cpp tcp_swarm_libevent.cpp)
|
||||
target_link_directories(swarm_client PUBLIC "./third/lib")
|
||||
|
|
|
@ -5,5 +5,5 @@ lib, *.a -> ./third/lib # Copies all dll files from packages bin folder to my "b
|
|||
include, *.h -> ./third/include # Copies all dll files from packages bin folder to my "bin" folder
|
||||
include, *.hpp -> ./third/include # Copies all dll files from packages bin folder to my "bin" folder
|
||||
lib, *.so -> ./third/lib # Copies all dll files from packages bin folder to my "bin" folder
|
||||
|
||||
lib, *.dll -> ./third/lib # Copies all dll files from packages bin folder to my "bin" folder
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-06-30 10:02:04
|
||||
* @LastEditTime: 2021-07-06 23:03:05
|
||||
* @LastEditTime: 2021-08-29 00:56:54
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \server\main.cpp
|
||||
|
@ -51,7 +51,7 @@ int main(){
|
|||
#endif
|
||||
std::cout<<"start swarm client libevent\r\n";
|
||||
TcpSwarmClientLibevent swarm(20);
|
||||
swarm.ConnectToServer("192.168.100.110",8000);
|
||||
swarm.ConnectToServer("127.0.0.1", 8000);
|
||||
while(true){
|
||||
#ifdef WIN32
|
||||
Sleep(1000);
|
||||
|
|
|
@ -14,12 +14,9 @@ static void conn_eventcb(struct bufferevent *, short, void *);
|
|||
|
||||
void delay(int ms);
|
||||
int ThreadRun(TcpClientLibevent *p);
|
||||
//conn_writecwritecb函数将在bufferevent中的output evbuffer缓冲区发送完成后被调用。
|
||||
//此时evbuffer_get_length(output) = 0,说明output evbuffer缓冲区被清空。
|
||||
//假设发现有10000条记录要发送出去,1次发送10000条将占用大量内存,所以,我们要分批发送
|
||||
//先发送100条数据,假设每条数据为1024字节bufferevent_write(bev,buf,1024 *100);
|
||||
//系统在这100条记录发送完成后将调用conn_writecbb回调函数,然后在该函数中循环发送剩下的
|
||||
//数据
|
||||
|
||||
|
||||
|
||||
void conn_writecb(struct bufferevent *bev, void *user_data)
|
||||
{
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-06-30 16:23:10
|
||||
* @LastEditTime: 2021-07-06 20:50:25
|
||||
* @LastEditTime: 2021-07-15 22:29:01
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \server\tcp_server_libevent.h
|
||||
|
@ -101,7 +101,6 @@ private:
|
|||
map<uint32_t,ConnectionLibevent*> m_map_client;
|
||||
OnAccept m_handle_accept;
|
||||
int AddConnection(uint32_t fd,ConnectionLibevent *p);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-07-04 16:06:47
|
||||
* @LastEditTime: 2021-07-06 22:40:15
|
||||
* @LastEditTime: 2021-08-29 01:00:36
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \server\tcp_swarm_libevent.cpp
|
||||
|
@ -14,12 +14,9 @@ void conn_writecb(struct bufferevent *, void *);
|
|||
void conn_readcb(struct bufferevent *, void *);
|
||||
void conn_eventcb(struct bufferevent *, short, void *);
|
||||
|
||||
|
||||
void conn_writecb(struct bufferevent *bev, void *user_data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 运行线程
|
||||
int thread_dispatch(TcpSwarmClientLibevent *p) {
|
||||
if (nullptr != p) {
|
||||
|
@ -61,15 +58,15 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data)
|
|||
{
|
||||
evutil_socket_t fd = bufferevent_getfd(bev);
|
||||
server->addConection(fd,bev);
|
||||
std::cout << "conect new fd " << fd << std::endl;
|
||||
bufferevent_write(bev, string("hello world").c_str(), strlen("hello world"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TcpSwarmClientLibevent::TcpSwarmClientLibevent(int count){
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
|
||||
int TcpSwarmClientLibevent::addConection(evutil_socket_t fd,struct bufferevent* bev) {
|
||||
if(nullptr != bev)
|
||||
m_clients[fd] = bev;
|
||||
|
@ -82,7 +79,6 @@ int TcpSwarmClientLibevent::removeConection(evutil_socket_t fd){
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int TcpSwarmClientLibevent::ConnectToServer(string server, int port){
|
||||
memset(&m_addr, 0, sizeof(m_addr));
|
||||
#ifdef linux
|
||||
|
|
Loading…
Reference in New Issue