少个虚构函数加上去,cmakefile最后打包库的路径写错了
parent
71eae9a32a
commit
b8820ee80c
|
@ -27,8 +27,8 @@ IF (WIN32)
|
||||||
add_custom_command (
|
add_custom_command (
|
||||||
TARGET generallib POST_BUILD
|
TARGET generallib POST_BUILD
|
||||||
COMMAND ar -x
|
COMMAND ar -x
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/libd/libgenerallib.a
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/libgenerallib.a
|
||||||
COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libgenerallib.a"
|
COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/libgenerallib.a"
|
||||||
)
|
)
|
||||||
add_custom_command (
|
add_custom_command (
|
||||||
TARGET generallib POST_BUILD
|
TARGET generallib POST_BUILD
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
void conn_writecb(struct bufferevent *, void *);
|
void conn_writecb(struct bufferevent *, void *);
|
||||||
void conn_readcb(struct bufferevent *, void *);
|
void conn_readcb(struct bufferevent *, void *);
|
||||||
void conn_eventcb(struct bufferevent *, short, void *);
|
void conn_eventcb(struct bufferevent *, short, void *);
|
||||||
|
|
||||||
void delay(int ms);
|
void delay(int ms);
|
||||||
int ThreadRun(TcpClientLibevent *p);
|
int ThreadRun(TcpClientLibevent *p);
|
||||||
|
|
||||||
|
@ -68,11 +69,13 @@ void conn_readcb(struct bufferevent *bev, void *user_data)
|
||||||
size_t sz = evbuffer_get_length(input);
|
size_t sz = evbuffer_get_length(input);
|
||||||
if (sz > 0)
|
if (sz > 0)
|
||||||
{
|
{
|
||||||
char *msg = new char[sz];
|
uint8_t *msg = new uint8_t[sz];
|
||||||
int ret = bufferevent_read(bev, msg, sz);
|
int ret = bufferevent_read(bev, msg, sz);
|
||||||
printf("%s\n", msg);
|
printf("%s\n", msg);
|
||||||
server->mPack.SortPack((uint8_t *)msg, ret);
|
if(server->mObserver != nullptr){
|
||||||
delete msg;
|
}
|
||||||
|
server->mObserver->OnData(msg,ret);
|
||||||
|
delete[] msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +142,6 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi
|
||||||
evthread_use_pthreads();
|
evthread_use_pthreads();
|
||||||
#endif
|
#endif
|
||||||
ConnectServer();
|
ConnectServer();
|
||||||
this->mPack.SetObserver(this);
|
|
||||||
this->mThread = new thread(ThreadRun,this);
|
this->mThread = new thread(ThreadRun,this);
|
||||||
this->mObserver = p;
|
this->mObserver = p;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +183,8 @@ int TcpClientLibevent::Dispatch() {
|
||||||
return event_base_dispatch(mBase);;
|
return event_base_dispatch(mBase);;
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpClientLibevent::~TcpClientLibevent() {
|
|
||||||
|
|
||||||
|
int TcpClientLibevent::Close() {
|
||||||
|
event_base_free(mBase);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
//
|
//
|
||||||
// Created by 29019 on 2020/4/18.
|
// Created by 29019 on 2020/4/18.
|
||||||
//
|
//
|
||||||
#define _WIN32_WINNT 0x0500
|
|
||||||
#ifndef GENERAL_TCPCLIENT_H
|
#ifndef GENERAL_TCPCLIENT_H
|
||||||
#define GENERAL_TCPCLIENT_H
|
#define GENERAL_TCPCLIENT_H
|
||||||
|
|
||||||
|
#ifndef _WIN32_WINNT
|
||||||
|
#define _WIN32_WINNT 0x0500
|
||||||
|
#endif
|
||||||
extern "C"{
|
extern "C"{
|
||||||
#include "third/include/event2/bufferevent.h"
|
#include "third/include/event2/bufferevent.h"
|
||||||
#include "third/include/event2/buffer.h"
|
#include "third/include/event2/buffer.h"
|
||||||
|
@ -18,7 +22,7 @@ extern "C"{
|
||||||
#include <thread>
|
#include <thread>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class TcpClientLibevent :public PackageReceiver::PackageReceiverObserver{
|
class TcpClientLibevent {
|
||||||
public:
|
public:
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UNCONNECTED, // 未连接
|
UNCONNECTED, // 未连接
|
||||||
|
@ -27,13 +31,17 @@ public:
|
||||||
}Status;
|
}Status;
|
||||||
class TcpClientObserver{
|
class TcpClientObserver{
|
||||||
public:
|
public:
|
||||||
|
virtual ~TcpClientObserver(){return;}
|
||||||
mutex mMux;
|
mutex mMux;
|
||||||
virtual void OnConnected() { return; };
|
virtual void OnConnected() { return; };
|
||||||
virtual void OnDisConnected() { return; };
|
virtual void OnDisConnected() { return; };
|
||||||
|
virtual void OnData(uint8_t *dat,uint64_t len){return;};
|
||||||
|
virtual void OnClose(){return;};
|
||||||
};
|
};
|
||||||
TcpClientLibevent(std::string addrinfo,int port, TcpClientObserver *p);
|
TcpClientLibevent(std::string addrinfo,int port, TcpClientObserver *p);
|
||||||
~TcpClientLibevent();
|
~TcpClientLibevent(){
|
||||||
|
event_base_free(mBase);
|
||||||
|
};
|
||||||
int ConnectServer();
|
int ConnectServer();
|
||||||
bool Connected();
|
bool Connected();
|
||||||
int Dispatch();
|
int Dispatch();
|
||||||
|
@ -42,7 +50,6 @@ public:
|
||||||
int SetObserver(TcpClientObserver*);
|
int SetObserver(TcpClientObserver*);
|
||||||
int Close();
|
int Close();
|
||||||
Status mStatus;
|
Status mStatus;
|
||||||
PackageReceiver mPack;
|
|
||||||
TcpClientObserver *mObserver;
|
TcpClientObserver *mObserver;
|
||||||
private:
|
private:
|
||||||
bool mReConnect = false;
|
bool mReConnect = false;
|
||||||
|
|
Loading…
Reference in New Issue