9 #include<jsoncpp/json/json.h>
25 #include<openssl/sha.h>
29 #include<sys/socket.h>
31 #include<openssl/bio.h>
32 #include<openssl/evp.h>
33 #include<openssl/buffer.h>
38 #include<condition_variable>
40 #include<unordered_map>
41 #include <openssl/ssl.h>
42 #include <openssl/err.h>
43 #include<openssl/crypto.h>
76 static bool createDir(
const std::string & ddir,
const mode_t &mode=0775);
85 static bool copy(
const std::string &sourceFile,
const std::string &objectFile);
94 static bool createFile(
const std::string &filePath,
const mode_t &mode=0666);
139 static std::mutex
l1;
140 static std::unordered_map<std::string,FileThreadLock>
fl2;
149 std::vector<std::string> data;
150 std::vector<std::string> backUp;
151 char *data_binary=
nullptr;
152 char *backUp_binary=
nullptr;
156 size_t multiple_backup=0;
161 std::string fileName;
163 std::string fileNameTemp;
168 uint64_t totalLines=0;
213 bool openFile(
const std::string &fileName,
const bool &create=
true,
const int &multiple=0,
const size_t &size=0,
const mode_t &mode=0666);
296 int findC(
const std::string &targetString,
const int linePos=1);
306 bool appendLineC(
const std::string &data,
const int &linePos=0);
332 bool chgLineC(
const std::string &data,
const int &linePos=0);
342 bool readLineC(std::string &data,
const int linePos);
352 std::string&
readC(std::string &data,
const int &linePos,
const int &num);
359 std::string&
readAllC(std::string &data);
375 bool readC(
char *data,
const size_t &pos,
const size_t &size);
386 bool writeC(
const char *data,
const size_t &pos,
const size_t &size);
407 int find(
const std::string &targetString,
const int linePos=1);
417 bool appendLine(
const std::string &data,
const int &linePos=0);
443 bool chgLine(
const std::string &data,
const int &linePos=0);
453 bool readLine(std::string &data,
const int linePos);
463 std::string&
read(std::string &data,
const int &linePos,
const int &num);
470 std::string&
readAll(std::string &data);
486 bool read(
char *data,
const size_t &pos,
const size_t &size);
497 bool write(
const char *data,
const size_t &pos,
const size_t &size);
554 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
556 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
570 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
572 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
586 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
588 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
602 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
604 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
618 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
620 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
633 long long dayy =
day;
645 if (msecc / 1000 != 0)
647 secc += msecc / 1000;
648 msecc = msecc % 1000;
677 long long dayy =
day;
683 msecc = dayy * 24 * 60 * 60 * 1000 + hourr * 60 * 60 * 1000 + minn * 60 * 1000 + secc * 1000 + msecc - b.
day * 24 * 60 * 60 * 1000 - b.
hour * 60 * 60 * 1000 - b.
min * 60 * 1000 - b.
sec * 1000 - b.
msec;
689 if (msecc / 1000 != 0)
691 secc += msecc / 1000;
692 msecc = msecc % 1000;
721 total =
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
722 double k =
day + total / 86400000.0000;
732 double k =
day * 24 +
hour + total / 36000000.0000;
742 double k =
day * 24 * 60 +
hour * 60 +
min + total / 60000.0000;
752 double k =
day * 24 * 60 * 60 +
hour * 60 * 60 +
min * 60 +
sec + total / 1000.0000;
761 total =
day * 24 * 60 * 60 * 1000 +
hour * 60 * 60 * 1000 +
min * 60 * 1000 +
sec * 1000 +
msec;
777 if (
msec / 1000 != 0)
816 std::ostream&
operator<<(std::ostream &os,
const Duration &a);
819 using Seconds = std::chrono::duration<uint64_t>;
823 #define ISO8086A "yyyy-mm-ddThh:mi:ss"
827 #define ISO8086B "yyyy-mm-ddThh:mi:ss.sss"
841 static std::string &toPGtimeFormat();
842 static std::chrono::system_clock::time_point strToTimePoint(
const std::string &timeStr,
const std::string &format =
ISO8086A);
843 static std::string& timePointToStr(
const std::chrono::system_clock::time_point &tp, std::string &timeStr,
const std::string &format =
ISO8086A);
852 static std::string&
getTime(std::string &timeStr,
const std::string &format =
ISO8086A);
861 static bool convertFormat(std::string &timeStr,
const std::string &oldFormat,
const std::string &newFormat =
ISO8086A);
882 static std::string&
calculateTime(
const std::string &time1,
const Duration &time2, std::string &result,
const std::string &am,
const std::string &format1 =
ISO8086A,
const std::string &format2 =
ISO8086A);
892 static bool compareTime(
const std::string &time1,
const std::string &time2,
const std::string &format1 =
ISO8086A,
const std::string &format2 =
ISO8086A);
896 std::chrono::steady_clock::time_point start;
897 std::chrono::steady_clock::time_point end;
937 std::string timeFormat;
938 std::string contentFormat;
949 bool openFile(
const std::string &fileName,
const std::string &timeFormat =
ISO8086A,
const std::string &contentFormat =
" ");
971 bool writeLog(
const std::string &data);
984 bool deleteLogByTime(
const std::string &date1 =
"1",
const std::string &date2 =
"2");
1010 static bool encryptSymmetric(
const unsigned char *before,
const size_t &length,
const unsigned char *passwd,
const unsigned char *iv,
unsigned char *after);
1021 static bool decryptSymmetric(
const unsigned char *before,
const size_t &length,
const unsigned char *passwd,
const unsigned char *iv,
unsigned char *after);
1034 static std::string&
sha1(
const std::string &ori_str, std::string &result);
1047 static std::string&
sha11(
const std::string &ori_str, std::string &result);
1062 static std::string&
bitOutput(
char input, std::string &result);
1070 static std::string&
bitOutput(
const std::string &input, std::string &result);
1079 static char&
bitOutput_bit(
char input,
const int pos,
char &result);
1087 static unsigned long&
bitStrToNumber(
const std::string &input,
unsigned long &result);
1097 static unsigned long&
bitToNumber(
const std::string &input,
unsigned long &result);
1105 static char&
toBit(
const std::string &input,
char &result);
1113 static std::string&
toBit(
const std::string &input, std::string &result);
1186 static std::string&
getPreciesFloat(
const float &number,
const int &bit, std::string &str);
1203 static std::string&
getPreciesDouble(
const double &number,
const int &bit, std::string &str);
1248 static size_t get_split_str(
const std::string_view& ori_str, std::string_view &str,
const std::string_view &a,
const std::string_view &b,
const size_t &pos = 0);
1259 static std::string_view&
get_value_str(
const std::string_view& ori_str, std::string_view &str,
const std::string& name);
1268 static std::string_view&
get_value_header(
const std::string_view& ori_str, std::string_view &str,
const std::string& name);
1278 static std::string_view&
get_location_str(
const std::string_view& ori_str, std::string_view &str);
1288 static std::string_view&
getLocPara(
const std::string_view &url, std::string_view &locPara);
1297 static std::string_view&
getPara(
const std::string_view &url, std::string_view ¶);
1317 static size_t get_split_str(
const std::string_view& ori_str, std::string &str,
const std::string_view &a,
const std::string_view &b,
const size_t &pos = 0);
1328 static std::string&
get_value_str(
const std::string& ori_str, std::string &str,
const std::string& name);
1337 static std::string&
get_value_header(
const std::string& ori_str, std::string &str,
const std::string& name);
1347 static std::string&
get_location_str(
const std::string& ori_str, std::string &str);
1357 static std::string&
getLocPara(
const std::string &url, std::string &locPara);
1366 static std::string&
getPara(
const std::string &url, std::string ¶);
1377 static std::string&
getIP(
const std::string &url, std::string &IP);
1388 static int&
getPort(
const std::string &url,
int &port);
1398 static std::string
createHeader(
const std::string& first,
const std::string& second);
1419 template<
class... Args>
1420 static std::string
createHeader(
const std::string& first,
const std::string& second, Args... args)
1422 std::string cf = first +
": " + second +
"\r\n" +
createHeader(args...);
1459 static int&
toInt(
const std::string_view&ori_str,
int &result,
const int &i = -1);
1466 static int&
str16toInt(
const std::string_view&ori_str,
int &result,
const int &i=-1);
1475 static long&
toLong(
const std::string_view&ori_str,
long &result,
const long &i = -1);
1484 static float&
toFloat(
const std::string&ori_str,
float &result,
const float &i = -1);
1493 static double&
toDouble(
const std::string&ori_str,
double &result,
const double &i = -1);
1501 static bool&
toBool(
const std::string_view&ori_str,
bool &result);
1512 static std::string&
strto16(
const std::string &ori_str, std::string &result);
1574 static std::string&
maskCalculate(std::string &data,
const std::string &mask);
1594 static int getValue(
const std::string &oriStr,std::string& result,
const std::string &type=
"value",
const std::string &name=
"a",
const int &num=0);
1601 static std::string
toString(
const Json::Value &val);
1607 static Json::Value
toJsonArray(
const std::string & str);
1617 template<
class T1,
class T2>
1621 root[first] = second;
1622 Json::StreamWriterBuilder builder;
1623 std::string jsonString = Json::writeString(builder, root);
1637 template<
class T1,
class T2,
class... Args>
1641 root[first] = second;
1643 Json::StreamWriterBuilder builder;
1644 std::string jsonString = Json::writeString(builder, root);
1645 jsonString = jsonString.erase(jsonString.length() - 2);
1647 return jsonString +
"," + kk;
1660 Json::Value root(Json::arrayValue);
1662 Json::StreamWriterBuilder builder;
1663 std::string jsonString = Json::writeString(builder, root);
1675 template<
class T,
class... Args>
1678 Json::Value root(Json::arrayValue);
1681 Json::StreamWriterBuilder builder;
1682 std::string jsonString = Json::writeString(builder, root);
1683 jsonString = jsonString.erase(jsonString.length() - 2);
1685 return jsonString +
"," + kk;
1694 static std::string
jsonAdd(
const std::string &a,
const std::string &b);
1701 static std::string&
jsonFormatify(
const std::string &a, std::string &b);
1708 static std::string&
jsonToUTF8(
const std::string &input, std::string &output);
1733 int connectionLimit;
1734 int connectionRateLimit;
1735 std::unordered_map<std::string,IPInformation> connectionTable;
1743 ConnectionLimiter(
const int &connectionLimit=20,
const int &connectionRateLimit=6):connectionLimit(connectionLimit),connectionRateLimit(connectionRateLimit){}
1749 bool allow(
const std::string &ip);
1754 void clearIP(
const std::string &ip);
1807 void close(
const bool &cle =
true);
1849 int sendData(
const std::string &data,
const bool &block =
true);
1873 int sendData(
const char *data,
const uint64_t &length,
const bool &block =
true);
1918 int recvData(std::string &data,
const uint64_t &length);
1931 int recvData(
char *data,
const uint64_t &length);
1941 std::string serverIP =
"";
1942 int serverPort = -1;
1945 SSL_CTX *ctx =
nullptr;
1952 void closeAndUnCreate();
1953 bool initCTX(
const char *ca,
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
1967 TcpClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
1974 bool connect(
const std::string &ip,
const int &port);
1988 void resetCTX(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
2040 HttpClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"") :
TcpClient(TLS, ca, cert, key, passwd) {}
2059 bool getRequest(
const std::string &url,
const std::string &
header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &
sec=-1);
2078 bool postRequest(
const std::string &url,
const std::string &
body =
"",
const std::string &
header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &
sec=-1);
2098 bool getRequestFromFD(
const int &
fd, SSL *
ssl,
const std::string &url,
const std::string &
header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &
sec=2);
2119 bool postRequestFromFD(
const int &
fd, SSL *
ssl,
const std::string &url,
const std::string &
body =
"",
const std::string &
header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &
sec=2);
2144 std::function<bool(const int &fd)> fc = [](
const int &fd)->
bool
2146 std::function<void(const int &fd)> fcEnd = [](
const int &fd)->
void
2148 std::function<bool(const int &fd)> fcTimeOut = [](
const int &fd)->
bool
2180 void setFunction(std::function<
bool(
const int &fd)> fc) { this->fc = fc; }
2188 void setEndFunction(std::function<
void(
const int &fd)> fcEnd) { this->fcEnd = fcEnd; };
2232 std::function<bool(const std::string &message, WebSocketClient &k)> fc = [](
const std::string &message,
WebSocketClient &k)->
bool
2233 {std::cout<<
"Received: "<<message<<std::endl;
return true;};
2252 WebSocketClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"") :
TcpClient(TLS, ca, cert, key, passwd) {}
2272 bool connect(
const std::string &url,
const int &min = 20);
2295 bool sendMessage(
const std::string &message,
const std::string &type =
"0001");
2305 void close(
const std::string &closeCodeAndMessage,
const bool &wait =
true);
2324 void close(
const short &code = 1000,
const std::string &message =
"bye",
const bool &wait =
true);
2428 bool sendBack(
const std::string &data,
const std::string &header =
"",
const std::string &code =
"200 OK",
const std::string &header1 =
"");
2442 bool sendBack(
const char *data,
const size_t &length,
const char *header=
"\0",
const char *code=
"200 OK\0",
const char *header1=
"\0",
const size_t &header_length=50);
2582 std::condition_variable *
cv;
2598 std::function<bool(TcpFDHandler &k,TcpFDInf &inf)> fc;
2604 void epolll(
const int &evsNum);
2605 virtual void consumer(
const int &threadID);
2619 TcpServer(
const int &
maxFD=10000,
const bool &
security_open=
true,
const int &connectionNumLimit=20,
const int &connectionRateLimit=6,
const int &
buffer_size=8,
const int &
requestRate=12,
const int &
checkFrequency=1,
const int &
connectionTimeout=1800):
maxFD(
maxFD),
connectionLimiter(connectionNumLimit,connectionRateLimit),
security_open(
security_open),
buffer_size(
buffer_size*1024),
requestRate(
requestRate),
checkFrequency(
checkFrequency),
connectionTimeout(
connectionTimeout){}
2626 bool startListen(
const int &port,
const int &threads = 8);
2654 bool setTLS(
const char *cert,
const char *key,
const char *passwd,
const char *ca);
2688 bool close(
const int &fd);
2699 SSL*
getSSL(
const int &fd);
2716 std::function<bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc;
2718 void consumer(
const int &threadID);
2732 HttpServer(
const int &
maxFD=10000000,
const bool &
security_open=
true,
const int &connectionNumLimit=20,
const int &connectionRateLimit=6,
const int &
buffer_size=8,
const int &
requestRate=12,
const int &
checkFrequency=1,
const int &
connectionTimeout=60):
TcpServer(
maxFD,
security_open,connectionNumLimit,connectionRateLimit,
buffer_size,
requestRate,
checkFrequency,
connectionTimeout){}
2796 bool sendMessage(
const std::string &msg,
const std::string &type =
"0001");
2806 std::unordered_map<int, WebSocketFDInformation> wbclientfd;
2808 std::function<bool(const std::string &msg, WebSocketServer &k,const WebSocketFDInformation &inf)> fc = [](
const std::string &message,
WebSocketServer &k,
const WebSocketFDInformation &inf)->
bool
2809 {std::cout <<
"Received: " << message << std::endl;
return true;};
2821 void consumer(
const int &threadID);
2823 void closeAck(
const int &fd,
const std::string &closeCodeAndMessage);
2824 void closeAck(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
2826 bool closeWithoutLock(
const int &fd,
const std::string &closeCodeAndMessage);
2827 bool closeWithoutLock(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
2838 WebSocketServer(
const int &
maxFD=10000000,
const bool &
security_open=
true,
const int &connectionNumLimit=20,
const int &connectionRateLimit=6,
const int &
buffer_size=8,
const int &
requestRate=12):
TcpServer(
maxFD,
security_open,connectionNumLimit,connectionRateLimit,
buffer_size,
requestRate,-1,-1){}
2892 bool close(
const int &fd,
const std::string &closeCodeAndMessage);
2913 bool close(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
2951 std::thread(&WebSocketServer::HB,
this).detach();
2975 void sendMessage(
const std::string &msg,
const std::string &type =
"0001");
3002 void setFD(
const int &fd,
const bool &
flag1 =
false,
const int &
sec = -1,
const bool &
flag2 =
false);
3025 void close(
const bool &cle =
true);
3046 int sendData(
const std::string &data,
const std::string &ip,
const int &port,
const bool &block =
true);
3067 int sendData(
const char *data,
const uint64_t &length,
const std::string &ip,
const int &port,
const bool &block =
true);
3082 int recvData(std::string &data,
const uint64_t &length, std::string &ip,
int &port);
3097 int recvData(
char *data,
const uint64_t &length, std::string &ip,
int &port);
3143 bool createFD(
const int &port,
const bool &
flag1 =
false,
const int &
sec = -1,
const bool &
flag2 =
true);
3228 struct semid_ds *buf;
3229 unsigned short *arry;
3254 bool init(key_t key,
unsigned short value = 1,
short sem_flg = SEM_UNDO);
3264 bool wait(
short value = -1);
3274 bool post(
short value = 1);
3301 #define MAX_PROCESS_NAME 100
3305 #define MAX_PROCESS_INF 1000
3309 #define SHARED_MEMORY_KEY 0x5095
3313 #define SHARED_MEMORY_LOCK_KEY 0x5095
3369 bool join(
const char *name,
const char *argv0 =
"",
const char *argv1 =
"",
const char *argv2 =
"");
3385 static bool HBCheck(
const int &sec);
3426 template<
class... Args>
3427 static bool startProcess(
const std::string &name,
const int &sec = -1, Args ...args)
3429 std::vector<const char *> paramList={args...,
nullptr};
3439 execv(name.c_str(),
const_cast<char* const*
>(paramList.data()));
3443 for(
int ii=1;ii<=64;ii++)
3454 signal(SIGCHLD,SIG_DFL);
3461 execv(name.c_str(),
const_cast<char* const*
>(paramList.data()));
3496 template<
class Fn,
class... Args>
3497 static typename std::enable_if<!std::is_convertible<Fn, std::string>::value,
bool>::type
3509 auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
3514 for(
int ii=1;ii<=64;ii++)
3525 signal(SIGCHLD,SIG_DFL);
3532 auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
struct HttpRequestInformation HttpInf
saves http/https protocol information
Definition: sttnet_English.h:2525
static std::string & transfer_websocket_key(std::string &str)
Generate the Sec-WebSocket-Accept field value in the WebSocket handshake response.
Restrict the classes that can be connected to the same IP address.
Definition: sttnet_English.h:1730
int sendData(const std::string &data, const std::string &ip, const int &port, const bool &block=true)
Send string data to the target.
std::chrono::duration< uint64_t > Seconds
Definition: sttnet_English.h:819
bool close()
Close listening and all connections.
bool operator>(const Duration &b)
Determine if the current time interval is greater than another time interval.
Definition: sttnet_English.h:551
int getServerPort()
Return the port of the connected client.
Definition: sttnet_English.h:2008
SSL * getSSL()
Get the encrypted SSL handle of this object.
Definition: sttnet_English.h:1802
void setStartFunction(std::function< void(const WebSocketFDInformation &inf, WebSocketServer &k)> fccc)
Set the callback function to be executed after a websocket connection is successful Register a callba...
Definition: sttnet_English.h:2847
int checkFrequency
Definition: sttnet_English.h:2591
bool isStart()
Return the timing status of the object.
Definition: sttnet_English.h:925
int fd
Definition: sttnet_English.h:1771
bool startTiming()
Start timing.
bool connect(const std::string &ip, const int &port)
Initiate a TCP connection to the server.
TcpFDInf * clientfd
Definition: sttnet_English.h:2577
~WebSocketClient()
Destructor of WebSocketClient class, gracefully disconnects when destroying the object.
std::string getServerIp()
Return the server ip if connected to the server.
Definition: sttnet_English.h:2340
bool unblock
Definition: sttnet_English.h:2585
void setFD(const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true)
Initialize the object, pass in socket and other parameters.
Definition: sttnet_English.h:2403
TCP socket operation class.
Definition: sttnet_English.h:1768
The structure of the message queue element.
Definition: sttnet_English.h:2553
bool readLine(std::string &data, const int linePos)
Read a single line.
bool writeLog(const std::string &data)
Write a line of log.
static std::string createJson(T1 first, T2 second, Args...args)
Create a JSON string composed of multiple key-value pairs (recursive variadic template).
Definition: sttnet_English.h:1638
std::string & readAll(std::string &data)
Read all lines.
A structure representing a time interval, supporting granularity in days, hours, minutes, seconds, and milliseconds.
Definition: sttnet_English.h:519
std::string & readAllC(std::string &data)
Read all lines.
WebSocket protocol operation class Only pass in the socket, then use this class for WebSocket operati...
Definition: sttnet_English.h:2749
static void setLogFile(file::LogFile *logfile=nullptr, const std::string &language="")
Set the log file object for the logging system If the passed log file object is uninitialized (empty)...
static void init(file::LogFile *logfile=nullptr, const std::string &language="")
Execute the setExceptionHandling and setfile::LogFile functions to complete the initialization of sig...
bool isConnect()
Determine if the object has a socket bound.
Definition: sttnet_English.h:1825
Class for time operations, calculations, and timing.
Definition: sttnet_English.h:836
bool createFD(const int &port, const bool &flag1=false, const int &sec=-1, const bool &flag2=true)
Destroy the original socket and recreate a server.
int getFD()
Get the socket of this object.
Definition: sttnet_English.h:1797
static long getRandomNumber(const long &a, const long &b)
Generate a random integer.
static int & str16toInt(const std::string_view &ori_str, int &result, const int &i=-1)
Convert a hexadecimal number's string representation to a decimal int type number.
bool deleteLine(const int &linePos=0)
Delete a line.
void waitAndQuit(const time::Duration &t=time::Duration{0, 0, 0, 10, 10})
Start the epoll exit countdown until new messages arrive on the socket If no new messages arrive by t...
Definition: sttnet_English.h:2215
bool connect(const std::string &url, const int &min=20)
Connect to a websocket server.
bool operator<=(const Duration &b)
Determine if the current time interval is less than or equal to another time interval.
Definition: sttnet_English.h:615
static std::string & sha11(const std::string &ori_str, std::string &result)
Calculate the SHA-1 hash value of the input string and return it as a hexadecimal string...
Http/HttpServer server operation class.
Definition: sttnet_English.h:2713
int recvData(std::string &data, const uint64_t &length, std::string &ip, int &port)
Receive data once into a string container.
int sendData(const std::string &data, const bool &block=true)
Send string data to the connected socket.
bool sendMessage(const int &fd, const std::string &msg, const std::string &type="0001")
Send a WebSocket message to a specific client.
Definition: sttnet_English.h:2937
std::mutex * lq1
Definition: sttnet_English.h:2580
pid_t pid
Process ID.
Definition: sttnet_English.h:3323
bool allow(const std::string &ip)
Determines whether to allow connections to a particular IP address based on the number of connections...
WebSocketClient(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Constructor of WebSocketClient class.
Definition: sttnet_English.h:2252
void setFunction(std::function< bool(const std::string &msg, WebSocketServer &k, const WebSocketFDInformation &inf)> fc)
Set the callback function after receiving a message from the client Register a callback function...
Definition: sttnet_English.h:2869
Duration(long long a, int b, int c, int d, int e)
Constructor, taking days, hours, minutes, seconds, milliseconds.
Definition: sttnet_English.h:544
bool post(short value=1)
V operation (release), attempts to add value to the semaphore.
int getFD()
Return fd.
Definition: sttnet_English.h:3020
static unsigned long & htonl_ntohl_64(unsigned long &data)
Reverse the endianness of a 64-bit unsigned integer (big endian <-> little endian).
bool stopListen()
Stop listening.
Duration endTiming()
Stop timing.
char argv1[20]
Second parameter of the process.
Definition: sttnet_English.h:3339
bool writeC(const char *data, const size_t &pos, const size_t &size)
Write a data block.
bool postRequestFromFD(const int &fd, SSL *ssl, const std::string &url, const std::string &body="", const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=2)
Send a POST request to the server.
std::string loc
The file path.
Definition: sttnet_English.h:113
unsigned long p_buffer_now
Receives a spatial position pointer.
Definition: sttnet_English.h:2538
bool isConnect()
Return the connection status of the object.
Definition: sttnet_English.h:2013
std::ostream & operator<<(std::ostream &os, const Duration &a)
Output the Duration object to a stream in a readable format.
int sec
Seconds.
Definition: sttnet_English.h:536
~TcpServer()
Destructor of TcpServer class.
Definition: sttnet_English.h:2704
double convertToMin()
Convert the current time interval to a floating-point representation in minutes.
Definition: sttnet_English.h:738
int recvDataByLength(std::string &data, const uint64_t &length, const int &sec=2)
Blocking receive of specified length of data from a connected socket into a string.
static bool decryptSymmetric(const unsigned char *before, const size_t &length, const unsigned char *passwd, const unsigned char *iv, unsigned char *after)
Symmetric decryption function in AES-256-CBC mode.
static std::string & generateMask_4(std::string &mask)
Generate a 32-bit (4-byte) random mask.
static long & toLong(const std::string_view &ori_str, long &result, const long &i=-1)
Convert string to long type.
static std::string & getRandomStr_base64(std::string &str, const int &length)
Generate a pseudo-random string of specified length within the Base64 character set, and append '=' at the end to complete the Base64 string format.
static float & toFloat(const std::string &ori_str, float &result, const float &i=-1)
Convert string to float type.
unsigned long buffer_size
Definition: sttnet_English.h:2572
std::string getServerPort()
Return the server port if connected to the server.
Definition: sttnet_English.h:2345
bool closeFile(const bool &del=false)
Close the log file opened by the object.
TcpClient(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Constructor of TcpClient class.
#define ISO8086A
Define the macro ISO8086A as "yyyy-mm-ddThh:mi:ss".
Definition: sttnet_English.h:823
bool close
is not a closing message
Definition: sttnet_English.h:2562
HttpServer(const int &maxFD=10000000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=60)
Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to...
Definition: sttnet_English.h:2732
void setTimeOutFunction(std::function< bool(const int &fd)> fcTimeOut)
Set the callback function triggered after epoll timeout Register a callback function.
Definition: sttnet_English.h:2198
bool flag2
Definition: sttnet_English.h:1773
Duration recoverForm(const long long &t)
Recover the standard days-hours-minutes-seconds-milliseconds format from given milliseconds.
Definition: sttnet_English.h:769
static std::string createArray(T first)
Create a JSON array string containing only one element.
Definition: sttnet_English.h:1658
void close(const bool &cle=true)
Empty the object and close the socket.
UdpClient(const bool &flag1=false, const int &sec=-1)
Constructor.
Responsible for conversion between strings and numbers.
Definition: sttnet_English.h:1448
~EpollSingle()
Destructor of EpollSingle Calls eldListen to block and exit epoll.
Definition: sttnet_English.h:2220
int threads
Records how many threads are currently using the file.
Definition: sttnet_English.h:117
static double & toDouble(const std::string &ori_str, double &result, const double &i=-1)
Convert string to double type.
static std::string language
Language selection for the system's logging system, default is English.
Definition: sttnet_English.h:3175
static std::string & getPreciesFloat(const float &number, const int &bit, std::string &str)
Format a floating-point number into a string representation with a specified number of decimal places...
Class responsible for process heartbeat monitoring and scheduling Used to monitor service processes a...
Definition: sttnet_English.h:3353
bool flag1
Definition: sttnet_English.h:1772
void startListen(const int &fd, const bool &flag=true, const time::Duration &dt=time::Duration{0, 0, 20, 0, 0})
Start listening.
Duration checkTime()
Check time during timing.
void format()
Format the data.
size_t getFileSize()
Get the size of the file opened in binary mode.
Definition: sttnet_English.h:257
bool deleteAllC()
Delete all lines.
Tcp server class.
Definition: sttnet_English.h:2569
static std::string createArray(T first, Args...args)
Create a JSON array string composed of multiple elements (recursive variadic template).
Definition: sttnet_English.h:1676
int fd
sockets
Definition: sttnet_English.h:2558
static std::mutex l1
Definition: sttnet_English.h:139
bool startListen(const int &port, const int &threads=8)
Start the TCP server listening program.
std::string port
Client port.
Definition: sttnet_English.h:2513
UDP operation class Pass in the socket for UDP protocol operations.
Definition: sttnet_English.h:2987
void blockSet(const int &sec=-1)
Set the socket in the object to blocking mode.
int recvData(std::string &data, const uint64_t &length)
Receive data once from a connected socket into a string container.
bool flag1
Definition: sttnet_English.h:2991
size_t getSize1()
Get the size of the file opened in binary mode in memory.
Definition: sttnet_English.h:266
static std::enable_if<!std::is_convertible< Fn, std::string >::value, bool >::type startProcess(Fn &&fn, const int &sec=-1, Args &&...args)
Create a child process through a function (with the option to restart periodically) ...
Definition: sttnet_English.h:3498
~File()
Destructor.
Definition: sttnet_English.h:224
static std::string_view & get_location_str(const std::string_view &ori_str, std::string_view &str)
Extract the path and query part from the URL.
HttpClient(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Constructor of HttpClient class.
Definition: sttnet_English.h:2040
TcpServer(const int &maxFD=10000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12, const int &checkFrequency=1, const int &connectionTimeout=1800)
Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to...
Definition: sttnet_English.h:2619
static std::string_view & getLocPara(const std::string_view &url, std::string_view &locPara)
Extract the path part of the URL (excluding the query).
WebSocketServer server operation class.
Definition: sttnet_English.h:2803
Operation class for parsing and responding to Http/https requests Only pass in the socket...
Definition: sttnet_English.h:2393
int getMessage(TcpFDInf &Tcpinf, WebSocketFDInformation &Websocketinf, const int &ii=1)
Get a websocket message.
bool chgLineC(const std::string &data, const int &linePos=0)
Modify a line.
bool operator<(const Duration &b)
Determine if the current time interval is less than another time interval.
Definition: sttnet_English.h:567
bool isConnect()
Return the connection status.
Definition: sttnet_English.h:2330
static bool HBCheck(const int &sec)
Check the heartbeat monitoring system If the time difference between the last heartbeat update and th...
Responsible for encryption, decryption, and hashing.
Definition: sttnet_English.h:997
Responsible for floating-point precision processing.
Definition: sttnet_English.h:1174
static std::string & sha1(const std::string &ori_str, std::string &result)
Calculate the SHA-1 hash value (raw binary form) of the input string.
SSL_CTX * ctx
Definition: sttnet_English.h:2586
bool deleteLogByTime(const std::string &date1="1", const std::string &date2="2")
Delete logs within a specified time interval.
std::string & read(std::string &data, const int &linePos, const int &num)
Read multiple lines.
static void list()
Output information of all processes in the heartbeat monitoring system.
static std::string & jsonToUTF8(const std::string &input, std::string &output)
Convert in a JSON string to UTF-8 characters.
Responsible for conversion between binary data and strings.
Definition: sttnet_English.h:1052
static unsigned long & bitToNumber(const std::string &input, unsigned long &result)
Convert a string to binary and then to the corresponding numeric value.
class of solving json data
Definition: sttnet_English.h:1579
int maxFD
Definition: sttnet_English.h:2573
static std::string & generateMask_4(std::string &mask)
Generate a 32-bit (4-byte) random mask.
static Duration & calculateTime(const std::string &time1, const std::string &time2, Duration &result, const std::string &format1=ISO8086A, const std::string &format2=ISO8086A)
Calculate the difference between two time strings.
static Json::Value toJsonArray(const std::string &str)
Parse a JSON string into Json::Value.
bool renew()
Update the heartbeat of the current process.
~csemp()
Destructor, does not automatically destroy the semaphore.
ConnectionLimiter(const int &connectionLimit=20, const int &connectionRateLimit=6)
ConnectionLimiter constructor.
Definition: sttnet_English.h:1743
Structure for process information.
Definition: sttnet_English.h:3318
std::string & readC(std::string &data, const int &linePos, const int &num)
Read multiple lines.
static std::unordered_map< std::string, FileThreadLock > fl2
Definition: sttnet_English.h:140
void resetCTX(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Reset TLS encryption parameters for the first time or reconfigure.
bool getRequest(const std::string &url, const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=-1)
Send a GET request to the server.
static std::string base64_encode(const std::string &input)
Base64 encode a string.
bool deleteLineC(const int &linePos=0)
Delete a line.
bool multiUseSet()
Set SO_REUSEADDR mode.
void setJudgeFunction(std::function< bool(const WebSocketFDInformation &k)> fcc)
Set the handshake phase check function for websocket, only execute subsequent handshake if check pass...
Definition: sttnet_English.h:2857
static std::string createHeader(const std::string &first, const std::string &second)
Create an HTTP request header field string.
int getvalue()
Get the current value of the semaphore.
TCP client operation class.
Definition: sttnet_English.h:1938
Responsible for HTTP string and URL parsing Including functions to extract parameters, IP, port, request header fields, etc., from URLs or request messages.
Definition: sttnet_English.h:1229
double convertToHour()
Convert the current time interval to a floating-point representation in hours.
Definition: sttnet_English.h:728
csemp()
Constructor, initializes internal state.
Definition: sttnet_English.h:3242
time_t lastTime
Last heartbeat time of the process, as a timestamp.
Definition: sttnet_English.h:3327
long long day
Days.
Definition: sttnet_English.h:524
static int & getPort(const std::string &url, int &port)
Extract the port number from the URL.
int sec
Definition: sttnet_English.h:2993
static void setExceptionHandling()
Set system signals.
bool chgLine(const std::string &data, const int &linePos=0)
Modify a line.
static std::string & strto16(const std::string &ori_str, std::string &result)
Convert a normal string to its corresponding hexadecimal representation string (hex string)...
void redrawTLS()
Revoke TLS encryption, CA certificate, etc.
bool close()
If the object has a socket connection, close and release the connection and socket, and create a new socket.
std::mutex lock
The lock for this file.
Definition: sttnet_English.h:121
int min
Minutes.
Definition: sttnet_English.h:532
std::queue< QueueFD > * fdQueue
Definition: sttnet_English.h:2579
void endListenWithSignal()
Send a signal to end epoll.
Definition: sttnet_English.h:2209
static float & getValidFloat(float &number, const int &bit)
Dynamically adjust the decimal precision based on the value, retaining a specified number of signific...
bool unlockMemory(const bool &rec=false)
Write data from memory to disk.
SSL * ssl
Definition: sttnet_English.h:1774
bool readLineC(std::string &data, const int linePos)
Read a single line.
static bool & toBool(const std::string_view &ori_str, bool &result)
Convert string to bool type.
static char & toBit(const std::string &input, char &result)
Compress a "01" string of up to 8 bits into 1 byte (char).
bool createFD(const bool &flag1=false, const int &sec=-1)
Destroy the original socket and recreate a client.
char argv2[20]
Third parameter of the process.
Definition: sttnet_English.h:3343
UdpServer(const int &port, const bool &flag1=false, const int &sec=-1, const bool &flag2=true)
Constructor.
static std::string toString(const Json::Value &val)
Convert Json::Value to a string.
bool write(const char *data, const size_t &pos, const size_t &size)
Write a data block.
bool allowRequest(const int &cclientfd)
bool TLS
Definition: sttnet_English.h:2587
double convertToSec()
Convert the current time interval to a floating-point representation in seconds.
Definition: sttnet_English.h:748
static std::string base64_decode(const std::string &input)
Decode a Base64 encoded string.
std::chrono::duration< uint64_t, std::milli > Milliseconds
Definition: sttnet_English.h:818
std::string getUrl()
Return the url if connected to the server.
Definition: sttnet_English.h:2335
static file::LogFile * logfile
Pointer to the log file object for reading and writing logs in the system.
Definition: sttnet_English.h:3171
static std::string createHeader(const std::string &first, const std::string &second, Args...args)
Recursively construct multiple HTTP request header fields.
Definition: sttnet_English.h:1420
time::Duration operator+(const time::Duration &b)
Add two time intervals.
Definition: sttnet_English.h:631
Listen to a single handle with epoll.
Definition: sttnet_English.h:2139
static std::string & transfer_websocket_key(std::string &str)
Generate the Sec-WebSocket-Accept field value in the WebSocket handshake response.
int consumerNum
Definition: sttnet_English.h:2583
bool getRequestFromFD(const int &fd, SSL *ssl, const std::string &url, const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=2)
Send a GET request to the server from a tcp socket.
int requestRate
Definition: sttnet_English.h:2590
bool sendMessage(const std::string &message, const std::string &type="0001")
Send a WebSocket message.
bool flag3
if the connection lost while using sendData function with block=true,this flag will be set to true ...
Definition: sttnet_English.h:1780
bool lockMemory()
Read data from disk into memory.
bool sendMessage(const std::string &msg, const std::string &type="0001")
Send a websocket message.
static std::string & bitOutput(char input, std::string &result)
Convert a single character to its corresponding 8-bit binary string.
void setFD(const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true)
Initialize the object, pass in socket and other parameters.
Definition: sttnet_English.h:2759
FileThreadLock(const std::string &loc, const int &threads)
The constructor of this structure.
Definition: sttnet_English.h:127
bool operator>=(const Duration &b)
Determine if the current time interval is greater than or equal to another time interval.
Definition: sttnet_English.h:599
std::condition_variable * cv
Definition: sttnet_English.h:2582
bool wait(short value=-1)
P operation (wait), attempts to subtract value from the semaphore.
bool destroy()
Destroy the current semaphore.
int fd
Definition: sttnet_English.h:2990
std::string getFileName()
Get the name of the opened file.
Definition: sttnet_English.h:239
~TcpClient()
Destructor of TcpClient, closes and releases the socket and its connection.
Definition: sttnet_English.h:1997
static std::string_view & getPara(const std::string_view &url, std::string_view ¶)
Get the query parameter string in the URL (including ?).
void setEndFunction(std::function< void(const int &fd)> fcEnd)
Set the callback function before epoll exits Register a callback function.
Definition: sttnet_English.h:2188
std::string body
Server response body.
Definition: sttnet_English.h:2133
static std::string & getIP(const std::string &url, std::string &IP)
Extract the host IP or domain name from the URL.
~HBSystem()
Destructor of HBSystem.
Responsible for string operations related to the WebSocket protocol.
Definition: sttnet_English.h:1429
Duration getDt()
Get the last timing duration.
Definition: sttnet_English.h:920
Data encoding/decoding, mask processing, etc.
Definition: sttnet_English.h:1517
int findC(const std::string &targetString, const int linePos=1)
Find a line.
~UdpServer()
Destructor, closes the socket when the object's life ends.
Definition: sttnet_English.h:3147
HttpServerFDHandler k
Classes that deal with HTTP.
Definition: sttnet_English.h:2543
bool operator==(const Duration &b)
Determine if the current time interval is equal to another time interval.
Definition: sttnet_English.h:583
bool appendLineC(const std::string &data, const int &linePos=0)
Insert a line.
std::deque< std::chrono::steady_clock::time_point > requestSpeedQueue
Queue for requesting speed limit, implementing sliding window algorithm.
Definition: sttnet_English.h:2547
bool deleteFromHBS()
Remove the current process from the heartbeat system.
bool join(const char *name, const char *argv0="", const char *argv1="", const char *argv2="")
Add a process to the heartbeat system.
void close(const bool &cle=true)
Close the object.
char * buffer
Receives the space pointer.
Definition: sttnet_English.h:2534
static unsigned long & bitStrToNumber(const std::string &input, unsigned long &result)
Convert a "01" string (binary string) to an unsigned integer.
A structure that records the relationship between files and threads.
Definition: sttnet_English.h:108
static size_t get_split_str(const std::string_view &ori_str, std::string_view &str, const std::string_view &a, const std::string_view &b, const size_t &pos=0)
Extract a substring between two markers from the original string.
int status
The current fd status, used to save the processor logic.
Definition: sttnet_English.h:2517
bool init(key_t key, unsigned short value=1, short sem_flg=SEM_UNDO)
Initialize the semaphore.
int sec
Definition: sttnet_English.h:1775
#define MAX_PROCESS_NAME
Define the macro MAX_PROCESS_NAME as 100, meaning the process name in process information does not ex...
Definition: sttnet_English.h:3301
static bool convertFormat(std::string &timeStr, const std::string &oldFormat, const std::string &newFormat=ISO8086A)
Convert the format of a time string.
Class for initializing the service system.
Definition: sttnet_English.h:3165
~UdpClient()
Destructor, closes the socket when the object's life ends.
Definition: sttnet_English.h:3121
bool close()
Close listening and all connected sockets.
bool deleteAll()
Delete all lines.
uint64_t getFileLine()
Get the number of lines in the opened file.
Definition: sttnet_English.h:248
void setFD(const int &fd, const bool &flag1=false, const int &sec=-1, const bool &flag2=false)
Set fd.
bool isOpen()
Check if the object has opened a file.
Definition: sttnet_English.h:229
int flag1
Definition: sttnet_English.h:2578
bool isReturn()
Get the server response status.
Definition: sttnet_English.h:2125
std::string_view data
Save the data received from the client.
Definition: sttnet_English.h:2521
bool flag2
Definition: sttnet_English.h:2992
WebSocketServer(const int &maxFD=10000000, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionRateLimit=6, const int &buffer_size=8, const int &requestRate=12)
Constructor, which is enabled by default. Limit the maximum number of connections to an IP address to...
Definition: sttnet_English.h:2838
static std::string & jsonFormatify(const std::string &a, std::string &b)
Remove indentation, spaces, etc., from a formatted JSON string to make it compact.
std::string header
Server response header.
Definition: sttnet_English.h:2129
bool openFile(const std::string &fileName, const bool &create=true, const int &multiple=0, const size_t &size=0, const mode_t &mode=0666)
Open a file.
static std::string & maskCalculate(std::string &data, const std::string &mask)
Perform XOR operation (XOR Masking) on a string using a given 4-byte mask.
Websocket client operation class.
Definition: sttnet_English.h:2228
bool isBinary()
Check if the object has opened the file in binary mode.
Definition: sttnet_English.h:234
void blockSet(const int &sec=-1)
Set to blocking mode.
void setFD(const int &fd, SSL *ssl, const bool &flag1=false, const bool &flag2=false, const int &sec=-1)
Initialize the object with a socket.
std::string getServerIP()
Return the IP of the connected server.
Definition: sttnet_English.h:2003
int solveRequest(TcpFDInf &TcpInf, const unsigned long &buffer_size, const int ×=1)
Parse Http/Https request.
static std::string & getPreciesDouble(const double &number, const int &bit, std::string &str)
Format a double-precision floating-point number into a string representation with a specified number ...
Synchronization tool class encapsulating System V semaphores.
Definition: sttnet_English.h:3217
bool openFile(const std::string &fileName, const std::string &timeFormat=ISO8086A, const std::string &contentFormat=" ")
Open a log file.
bool clearLog()
Clear all logs.
Responsible for endianness conversion.
Definition: sttnet_English.h:1154
time::Duration operator-(const time::Duration &b)
Calculate the difference between two time intervals (current object minus parameter b)...
Definition: sttnet_English.h:675
static bool encryptSymmetric(const unsigned char *before, const size_t &length, const unsigned char *passwd, const unsigned char *iv, unsigned char *after)
Symmetric encryption function in AES-256-CBC mode.
~WebSocketServer()
Destructor of WebSocketServer.
Definition: sttnet_English.h:2980
std::mutex che
Definition: sttnet_English.h:142
bool startListen(const int &port, const int &threads=8)
Open the Websocket server listening program.
Definition: sttnet_English.h:2949
std::string getFileName()
Get the file name opened by the object.
Definition: sttnet_English.h:959
Udp server operation class.
Definition: sttnet_English.h:3126
double convertToDay()
Convert the current time interval to a floating-point representation in days.
Definition: sttnet_English.h:718
bool isListen()
Return epoll listening status.
Definition: sttnet_English.h:2170
Http/Https client operation class.
Definition: sttnet_English.h:2023
char argv0[20]
First parameter of the process.
Definition: sttnet_English.h:3335
int fd
Socket file descriptor.
Definition: sttnet_English.h:2505
bool postRequest(const std::string &url, const std::string &body="", const std::string &header="", const std::string &header1="Connection: keep-alive", const int &sec=-1)
Send a POST request to the server.
bool security_open
Definition: sttnet_English.h:2593
bool setTLS(const char *cert, const char *key, const char *passwd, const char *ca)
Enable TLS encryption and configure server-side certificate and key.
void formatC()
Format the data.
Static utility class for process management.
Definition: sttnet_English.h:3401
static std::string_view & get_value_str(const std::string_view &ori_str, std::string_view &str, const std::string &name)
Extract the value of a specified key from the URL query parameters.
bool sendBack(const std::string &data, const std::string &header="", const std::string &code="200 OK", const std::string &header1="")
Send Http/Https response.
static std::string_view & get_value_header(const std::string_view &ori_str, std::string_view &str, const std::string &name)
Extract the value of a specified field from the HTTP request header.
static int getValue(const std::string &oriStr, std::string &result, const std::string &type="value", const std::string &name="a", const int &num=0)
Extract the value or nested structure of a specified field in a JSON string.
int hour
Hours.
Definition: sttnet_English.h:528
long long convertToMsec()
Convert the current time interval to total milliseconds.
Definition: sttnet_English.h:758
int connectionTimeout
Definition: sttnet_English.h:2592
void setFunction(std::function< bool(const int &fd)> fc)
Set the processing function after epoll triggering Register a callback function.
Definition: sttnet_English.h:2180
Udp client operation class.
Definition: sttnet_English.h:3103
static int & toInt(const std::string_view &ori_str, int &result, const int &i=-1)
Convert string to int type.
static std::string createJson(T1 first, T2 second)
Create a JSON string containing only one key-value pair.
Definition: sttnet_English.h:1618
Structure to save TCP client information.
Definition: sttnet_English.h:2500
static std::string jsonAdd(const std::string &a, const std::string &b)
Concatenate two JSON strings into a valid JSON (suitable for object or array concatenation).
static bool compareTime(const std::string &time1, const std::string &time2, const std::string &format1=ISO8086A, const std::string &format2=ISO8086A)
Compare the magnitudes of two time strings.
security::ConnectionLimiter connectionLimiter
Definition: sttnet_English.h:2574
bool closeFile(const bool &del=false)
Close the opened file.
bool appendLine(const std::string &data, const int &linePos=0)
Insert a line.
std::string ip
Client IP.
Definition: sttnet_English.h:2509
bool isOpen()
Get the status of whether the log file is open.
Definition: sttnet_English.h:954
void setHBTimeOutTime(const int &secb)
Set the waiting time after sending a heartbeat.
Definition: sttnet_English.h:2880
Log file operation class.
Definition: sttnet_English.h:934
A class for reading and writing disk files.
Definition: sttnet_English.h:136
int msec
Milliseconds.
Definition: sttnet_English.h:540
std::mutex lco1
Definition: sttnet_English.h:2584
Related to random number and string generation.
Definition: sttnet_English.h:1118
int find(const std::string &targetString, const int linePos=1)
Find a line.
bool setFunction(std::function< bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc)
Set a callback function for responding after receiving and successfully parsing an Http/Https request...
Definition: sttnet_English.h:2743
static char & bitOutput_bit(char input, const int pos, char &result)
Get the pos-th bit (from left to right) of the character input (binary) and return '1' or '0'...
bool endListen()
End epoll listening Will block until epoll exits completely.
void unblockSet()
Set the socket in the object to non-blocking mode.
SSL * ssl
If encrypted, store the encryption handle.
Definition: sttnet_English.h:2529
bool isListen()
Return the listening status of the object.
Definition: sttnet_English.h:2694
bool setFunction(std::function< bool(TcpFDHandler &k, TcpFDInf &inf)> fc)
Set the callback function after receiving a message from the client Register a callback function...
Definition: sttnet_English.h:2669
bool multiUseSet()
Set the socket in the object to SO_REUSEADDR mode.
char name[MAX_PROCESS_NAME]
Process name.
Definition: sttnet_English.h:3331
static bool startProcess(const std::string &name, const int &sec=-1, Args...args)
Start a new process (with the option to restart periodically)
Definition: sttnet_English.h:3427
SSL * getSSL(const int &fd)
Query the connection with the server, pass in the socket, and return the encrypted SSL handle...
void unblockSet()
Set to non-blocking mode.
static std::string & getTime(std::string &timeStr, const std::string &format=ISO8086A)
Get the current time.
void setTimeOutTime(const int &seca)
Set heartbeat time.
Definition: sttnet_English.h:2874
void setFunction(std::function< bool(const std::string &message, WebSocketClient &k)> fc)
Set the callback function after receiving a message from the server Register a callback function...
Definition: sttnet_English.h:2263
void clearIP(const std::string &ip)
Clear the number of connections that record an IP address.