Skip to content

Commit

Permalink
refactor(cpp): exturn全局变量改为 static inline
Browse files Browse the repository at this point in the history
  • Loading branch information
pdt012 committed Mar 1, 2023
1 parent ceb18e9 commit b5242dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 6 additions & 5 deletions cpp/src/hsocket/header/HTcpSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

typedef SOCKET SOCKET;

namespace SocketConfig {
extern int RECV_BUFFER_SIZE;
extern int FILE_BUFFER_SIZE;
const char DEFAULT_DOWNLOAD_PATH[] = "download/";
}
class SocketConfig {
public:
static inline int RECV_BUFFER_SIZE = 1024;
static inline int FILE_BUFFER_SIZE = 2048;
static inline std::string DEFAULT_DOWNLOAD_PATH = "download/";
};

class HTcpSocket : public HSocket
{
Expand Down
9 changes: 2 additions & 7 deletions cpp/src/hsocket/source/HTcpSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

#define USE_UNICODE_FILEPATHS

namespace SocketConfig {
int RECV_BUFFER_SIZE = 1024;
int FILE_BUFFER_SIZE = 2048;
}

HTcpSocket::HTcpSocket()
: HSocket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
{
Expand Down Expand Up @@ -85,8 +80,8 @@ std::string HTcpSocket::recvFile()
memcpy_s(&filesize, 4, filesize_b.c_str(), 4);
// file content
if (!filename.empty() && filesize > 0) {
if (!fileutil::exists(SocketConfig::DEFAULT_DOWNLOAD_PATH))
fileutil::mkdir(SocketConfig::DEFAULT_DOWNLOAD_PATH);
if (!fileutil::exists(SocketConfig::DEFAULT_DOWNLOAD_PATH.c_str()))
fileutil::mkdir(SocketConfig::DEFAULT_DOWNLOAD_PATH.c_str());
std::string downPath = pathutil::join(SocketConfig::DEFAULT_DOWNLOAD_PATH, filename);
int totalRecvSize = 0; // 收到的字节数
#ifdef USE_UNICODE_FILEPATHS
Expand Down

0 comments on commit b5242dd

Please sign in to comment.