少个虚构函数加上去,cmakefile最后打包库的路径写错了

master
a7458969 2020-05-07 00:31:11 +08:00
parent 71eae9a32a
commit b8820ee80c
3 changed files with 23 additions and 12 deletions

View File

@ -27,8 +27,8 @@ IF (WIN32)
add_custom_command (
TARGET generallib POST_BUILD
COMMAND ar -x
${CMAKE_CURRENT_SOURCE_DIR}/libd/libgenerallib.a
COMMENT "package library 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}/cmake-build-debug/libgenerallib.a"
)
add_custom_command (
TARGET generallib POST_BUILD

View File

@ -9,6 +9,7 @@
void conn_writecb(struct bufferevent *, void *);
void conn_readcb(struct bufferevent *, void *);
void conn_eventcb(struct bufferevent *, short, void *);
void delay(int ms);
int ThreadRun(TcpClientLibevent *p);
@ -68,11 +69,13 @@ void conn_readcb(struct bufferevent *bev, void *user_data)
size_t sz = evbuffer_get_length(input);
if (sz > 0)
{
char *msg = new char[sz];
uint8_t *msg = new uint8_t[sz];
int ret = bufferevent_read(bev, msg, sz);
printf("%s\n", msg);
server->mPack.SortPack((uint8_t *)msg, ret);
delete msg;
if(server->mObserver != nullptr){
}
server->mObserver->OnData(msg,ret);
delete[] msg;
}
}
@ -139,7 +142,6 @@ TcpClientLibevent::TcpClientLibevent(std::string addrinfo, int port, TcpClientLi
evthread_use_pthreads();
#endif
ConnectServer();
this->mPack.SetObserver(this);
this->mThread = new thread(ThreadRun,this);
this->mObserver = p;
}
@ -181,6 +183,8 @@ int TcpClientLibevent::Dispatch() {
return event_base_dispatch(mBase);;
}
TcpClientLibevent::~TcpClientLibevent() {
int TcpClientLibevent::Close() {
event_base_free(mBase);
return 0;
}

View File

@ -1,9 +1,13 @@
//
// Created by 29019 on 2020/4/18.
//
#define _WIN32_WINNT 0x0500
#ifndef GENERAL_TCPCLIENT_H
#define GENERAL_TCPCLIENT_H
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
extern "C"{
#include "third/include/event2/bufferevent.h"
#include "third/include/event2/buffer.h"
@ -18,7 +22,7 @@ extern "C"{
#include <thread>
using namespace std;
class TcpClientLibevent :public PackageReceiver::PackageReceiverObserver{
class TcpClientLibevent {
public:
typedef enum {
UNCONNECTED, // 未连接
@ -27,13 +31,17 @@ public:
}Status;
class TcpClientObserver{
public:
virtual ~TcpClientObserver(){return;}
mutex mMux;
virtual void OnConnected() { 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();
~TcpClientLibevent(){
event_base_free(mBase);
};
int ConnectServer();
bool Connected();
int Dispatch();
@ -42,7 +50,6 @@ public:
int SetObserver(TcpClientObserver*);
int Close();
Status mStatus;
PackageReceiver mPack;
TcpClientObserver *mObserver;
private:
bool mReConnect = false;