跨平台优化
This commit is contained in:
@@ -20,5 +20,15 @@ add_library(Transmission
|
||||
Exception/PrepareDataException.h
|
||||
)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
add_definitions(-DBUILD_LINUX=1)
|
||||
message("以Linux为构建目标")
|
||||
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
|
||||
add_definitions(-DBUILD_WINDOWS=1)
|
||||
message("以Windows为构建目标")
|
||||
else ()
|
||||
message(FATAL_ERROR "未知的目标操作系统")
|
||||
endif ()
|
||||
|
||||
target_include_directories(Transmission PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(Transmission protobuf proto lzma)
|
||||
@@ -133,9 +133,9 @@ namespace Transmission {
|
||||
}
|
||||
|
||||
void Transmit::pushData(unsigned char *data, int32_t size) const {
|
||||
::send(this->fd, &size, sizeof(int32_t), 0);
|
||||
::send(this->fd, data, size, 0);
|
||||
::send(this->fd, &DATA_STOP, sizeof(DATA_STOP), 0);
|
||||
::send(this->fd, (const char *) &size, sizeof(int32_t), 0);
|
||||
::send(this->fd, (const char *) data, size, 0);
|
||||
::send(this->fd, (const char *) &DATA_STOP, sizeof(DATA_STOP), 0);
|
||||
}
|
||||
|
||||
void Transmit::pushData(DataPackets &data) {
|
||||
@@ -174,7 +174,7 @@ namespace Transmission {
|
||||
buff.put(ptr.get(), 0, (int64_t) lastSize);
|
||||
break;
|
||||
}
|
||||
if(ret != LZMA_OK)
|
||||
if (ret != LZMA_OK)
|
||||
throw PrepareDataException("LZMA压缩失败");
|
||||
lastSize = stream.total_out - lastSize;
|
||||
buff.put(ptr.get(), 0, (int64_t) lastSize);
|
||||
|
||||
@@ -8,7 +8,18 @@
|
||||
#define TRANSMISSION_TRANSMIT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef BUILD_LINUX
|
||||
|
||||
#include <pcap/socket.h>
|
||||
|
||||
#endif
|
||||
#ifdef BUILD_WINDOWS
|
||||
#include <winsock.h>
|
||||
#include <io.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include "CharBuff.h"
|
||||
#include "transmission.pb.h"
|
||||
|
||||
Reference in New Issue
Block a user