no message
parent
11125aabe8
commit
ff47a114b9
|
@ -30,3 +30,6 @@
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
server/build/*
|
||||||
|
server/third/*
|
||||||
|
.vscode/*
|
||||||
|
|
|
@ -82,23 +82,20 @@ void conn_eventcb(struct bufferevent *bev, short events, void *user_data)
|
||||||
{
|
{
|
||||||
TcpClientLibevent *p;
|
TcpClientLibevent *p;
|
||||||
p = (TcpClientLibevent *)user_data;
|
p = (TcpClientLibevent *)user_data;
|
||||||
if (events & BEV_EVENT_EOF)
|
if (events & BEV_EVENT_EOF) {
|
||||||
{
|
|
||||||
if (nullptr != p->mObserver)
|
if (nullptr != p->mObserver)
|
||||||
p->mObserver->OnDisConnected();
|
p->mObserver->OnDisConnected();
|
||||||
if (p != nullptr)
|
if (p != nullptr)
|
||||||
p->mStatus = TcpClientLibevent::UNCONNECTED;
|
p->mStatus = TcpClientLibevent::UNCONNECTED;
|
||||||
printf("Connection closed\n");
|
printf("Connection closed\n");
|
||||||
}
|
}
|
||||||
else if (events & BEV_EVENT_ERROR)
|
else if (events & BEV_EVENT_ERROR) {
|
||||||
{
|
|
||||||
printf("Got an error on the connection: %s\n", strerror(errno));
|
printf("Got an error on the connection: %s\n", strerror(errno));
|
||||||
if (nullptr != p->mObserver)
|
if (nullptr != p->mObserver)
|
||||||
p->mObserver->OnDisConnected();
|
p->mObserver->OnDisConnected();
|
||||||
p->mStatus = TcpClientLibevent::FAIL;
|
p->mStatus = TcpClientLibevent::FAIL;
|
||||||
}
|
}
|
||||||
else if (events & BEV_EVENT_CONNECTED)
|
else if (events & BEV_EVENT_CONNECTED) {
|
||||||
{
|
|
||||||
printf("Connect succeed\n");
|
printf("Connect succeed\n");
|
||||||
//客户端链接成功后,给服务器发送第一条消息
|
//客户端链接成功后,给服务器发送第一条消息
|
||||||
if (nullptr != p->mObserver)
|
if (nullptr != p->mObserver)
|
||||||
|
@ -163,8 +160,7 @@ int TcpClientLibevent::ConnectServer() {
|
||||||
bufferevent_setcb(bev, conn_readcb, conn_writecb, conn_eventcb, this);
|
bufferevent_setcb(bev, conn_readcb, conn_writecb, conn_eventcb, this);
|
||||||
int flag = bufferevent_socket_connect(bev, (struct sockaddr *)&mSrv, sizeof(mSrv));
|
int flag = bufferevent_socket_connect(bev, (struct sockaddr *)&mSrv, sizeof(mSrv));
|
||||||
bufferevent_enable(bev, EV_READ | EV_WRITE);
|
bufferevent_enable(bev, EV_READ | EV_WRITE);
|
||||||
if (-1 == flag)
|
if (-1 == flag) {
|
||||||
{
|
|
||||||
this->mStatus = TcpClientLibevent::FAIL;
|
this->mStatus = TcpClientLibevent::FAIL;
|
||||||
bufferevent_free(bev);
|
bufferevent_free(bev);
|
||||||
bev = nullptr;
|
bev = nullptr;
|
||||||
|
|
|
@ -22,9 +22,8 @@ extern "C"{
|
||||||
#include "event2/util.h"
|
#include "event2/util.h"
|
||||||
#include "event2/event.h"
|
#include "event2/event.h"
|
||||||
#include "event2/thread.h"
|
#include "event2/thread.h"
|
||||||
#include<string.h>
|
|
||||||
};
|
};
|
||||||
|
#include<string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
// #include "PackageReceiver.h"
|
// #include "PackageReceiver.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: your name
|
* @Author: your name
|
||||||
* @Date: 2021-06-30 16:23:10
|
* @Date: 2021-06-30 16:23:10
|
||||||
* @LastEditTime: 2021-07-04 13:37:58
|
* @LastEditTime: 2021-07-06 20:50:25
|
||||||
* @LastEditors: Please set LastEditors
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \server\tcp_server_libevent.h
|
* @FilePath: \server\tcp_server_libevent.h
|
||||||
|
@ -28,8 +28,9 @@ extern "C"{
|
||||||
#include "event2/util.h"
|
#include "event2/util.h"
|
||||||
#include "event2/event.h"
|
#include "event2/event.h"
|
||||||
#include "event2/thread.h"
|
#include "event2/thread.h"
|
||||||
|
#include <stdint.h>
|
||||||
};
|
};
|
||||||
#include <stdint.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: your name
|
* @Author: your name
|
||||||
* @Date: 2021-07-04 16:39:42
|
* @Date: 2021-07-04 16:39:42
|
||||||
* @LastEditTime: 2021-07-05 00:19:40
|
* @LastEditTime: 2021-07-06 20:21:10
|
||||||
* @LastEditors: Please set LastEditors
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \server\tcp_swarm_libevent.h
|
* @FilePath: \server\tcp_swarm_libevent.h
|
||||||
|
@ -66,5 +66,4 @@ private:
|
||||||
uint32_t m_count;
|
uint32_t m_count;
|
||||||
int removeConection(evutil_socket_t fd);
|
int removeConection(evutil_socket_t fd);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GENERAL_TCPCLIENT_H
|
#endif //GENERAL_TCPCLIENT_H
|
||||||
|
|
Loading…
Reference in New Issue