STTNet
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
sttnet_English.h
Go to the documentation of this file.
1 
7 #ifndef PUBLIC_H
8 #define PUBLIC_H 1
9 #include<jsoncpp/json/json.h>
10 #include<string_view>
11 #include<string>
12 #include<atomic>
13 #include<iostream>
14 #include<unistd.h>
15 #include<sys/stat.h>
16 #include<fstream>
17 #include<fcntl.h>
18 #include<sstream>
19 #include<mutex>
20 #include<chrono>
21 #include<iomanip>
22 #include<random>
23 #include<cmath>
24 #include<thread>
25 #include<openssl/sha.h>
26 #include<netdb.h>
27 #include<arpa/inet.h>
28 #include<sys/types.h>
29 #include<sys/socket.h>
30 #include<cstring>
31 #include<openssl/bio.h>
32 #include<openssl/evp.h>
33 #include<openssl/buffer.h>
34 #include<functional>
35 #include<list>
36 #include<queue>
37 #include<sys/epoll.h>
38 #include<condition_variable>
39 #include <regex>
40 #include<unordered_map>
41 #include <openssl/ssl.h>
42 #include <openssl/err.h>
43 #include<openssl/crypto.h>
44 #include<signal.h>
45 #include<sys/ipc.h>
46 #include<sys/sem.h>
47 #include<sys/wait.h>
48 #include<sys/shm.h>
49 #include<type_traits>
50 #include<charconv>
54 namespace stt
55 {
61  namespace file
62  {
66  class FileTool
67  {
68  public:
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);
101  static size_t get_file_size(const std::string &fileName);
102  };
103 
109  {
113  std::string loc;
117  int threads;
121  std::mutex lock;
127  FileThreadLock(const std::string &loc,const int &threads):loc(loc),threads(threads){};
128  };
129 
136  class File:private FileTool
137  {
138  protected:
139  static std::mutex l1;
140  static std::unordered_map<std::string,FileThreadLock> fl2;
141  protected:
142  std::mutex che;
143 
144  private:
145  void lockfl2();
146  void unlockfl2();
147  private:
148  std::ifstream fin;
149  std::vector<std::string> data;
150  std::vector<std::string> backUp;
151  char *data_binary=nullptr;
152  char *backUp_binary=nullptr;
153  size_t size1=0;
154  size_t size2=0;
155  int multiple=0;
156  size_t multiple_backup=0;
157  size_t malloced=0;
158  std::mutex fl1;
159 
160  std::ofstream fout;
161  std::string fileName;
162 
163  std::string fileNameTemp;
164  bool flag=false;
165  bool binary;
166  mode_t mode;
167  size_t size=0;
168  uint64_t totalLines=0;
169  private:
170  void toMemory();
171  bool toDisk();
172  public:
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);
219  bool closeFile(const bool &del=false);
224  ~File(){closeFile(false);}
229  bool isOpen(){return flag;}
234  bool isBinary(){return binary;}
239  std::string getFileName(){return fileName;}
248  uint64_t getFileLine(){return totalLines;}
257  size_t getFileSize(){return size;}
266  size_t getSize1(){return size1;}
267  public:
273  bool lockMemory();
281  bool unlockMemory(const bool &rec=false);
282  public:
296  int findC(const std::string &targetString,const int linePos=1);
306  bool appendLineC(const std::string &data,const int &linePos=0);
315  bool deleteLineC(const int &linePos=0);
322  bool deleteAllC();
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);
391  void formatC();
393  public:
407  int find(const std::string &targetString,const int linePos=1);
417  bool appendLine(const std::string &data,const int &linePos=0);
426  bool deleteLine(const int &linePos=0);
433  bool deleteAll();
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);
502  void format();
504  };
505  }
511  namespace time
512  {
519  struct Duration
520 {
524  long long day;
528  int hour;
532  int min;
536  int sec;
540  int msec;
544  Duration(long long a, int b, int c, int d, int e) : day(a), hour(b), min(c), sec(d), msec(e) {}
545  Duration() = default;
551  bool operator>(const Duration &b)
552  {
553  long long total;
554  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
555  long long totalB;
556  totalB = b.day * 24 * 60 * 60 * 1000 + b.hour * 60 * 60 * 1000 + b.min * 60 * 1000 + b.sec * 1000 + b.msec;
557  if (total > totalB)
558  return true;
559  else
560  return false;
561  }
567  bool operator<(const Duration &b)
568  {
569  long long total;
570  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
571  long long totalB;
572  totalB = b.day * 24 * 60 * 60 * 1000 + b.hour * 60 * 60 * 1000 + b.min * 60 * 1000 + b.sec * 1000 + b.msec;
573  if (total < totalB)
574  return true;
575  else
576  return false;
577  }
583  bool operator==(const Duration &b)
584  {
585  long long total;
586  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
587  long long totalB;
588  totalB = b.day * 24 * 60 * 60 * 1000 + b.hour * 60 * 60 * 1000 + b.min * 60 * 1000 + b.sec * 1000 + b.msec;
589  if (total == totalB)
590  return true;
591  else
592  return false;
593  }
599  bool operator>=(const Duration &b)
600  {
601  long long total;
602  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
603  long long totalB;
604  totalB = b.day * 24 * 60 * 60 * 1000 + b.hour * 60 * 60 * 1000 + b.min * 60 * 1000 + b.sec * 1000 + b.msec;
605  if (total >= totalB)
606  return true;
607  else
608  return false;
609  }
615  bool operator<=(const Duration &b)
616  {
617  long long total;
618  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
619  long long totalB;
620  totalB = b.day * 24 * 60 * 60 * 1000 + b.hour * 60 * 60 * 1000 + b.min * 60 * 1000 + b.sec * 1000 + b.msec;
621  if (total <= totalB)
622  return true;
623  else
624  return false;
625  }
632  {
633  long long dayy = day;
634  int hourr = hour;
635  int minn = min;
636  int secc = sec;
637  int msecc = msec;
638 
639  msecc += b.msec;
640  secc += b.sec;
641  minn += b.min;
642  hourr += b.hour;
643  dayy += b.day;
644 
645  if (msecc / 1000 != 0)
646  {
647  secc += msecc / 1000;
648  msecc = msecc % 1000;
649  }
650 
651  if (secc / 60 != 0)
652  {
653  minn += secc / 60;
654  secc = secc % 60;
655  }
656 
657  if (minn / 60 != 0)
658  {
659  hourr += minn / 60;
660  minn = minn % 60;
661  }
662 
663  if (hourr / 24 != 0)
664  {
665  dayy += hourr / 24;
666  hourr = hourr % 24;
667  }
668  return time::Duration(dayy, hourr, minn, secc, msecc);
669  }
676  {
677  long long dayy = day;
678  int hourr = hour;
679  int minn = min;
680  int secc = sec;
681  int msecc = msec;
682 
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;
684  secc = 0;
685  minn = 0;
686  hourr = 0;
687  dayy = 0;
688 
689  if (msecc / 1000 != 0)
690  {
691  secc += msecc / 1000;
692  msecc = msecc % 1000;
693  }
694 
695  if (secc / 60 != 0)
696  {
697  minn += secc / 60;
698  secc = secc % 60;
699  }
700 
701  if (minn / 60 != 0)
702  {
703  hourr += minn / 60;
704  minn = minn % 60;
705  }
706 
707  if (hourr / 24 != 0)
708  {
709  dayy += hourr / 24;
710  hourr = hourr % 24;
711  }
712  return time::Duration(dayy, hourr, minn, secc, msecc);
713  }
714 
718  double convertToDay()
719  {
720  long long total;
721  total = hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
722  double k = day + total / 86400000.0000;
723  return k;
724  }
728  double convertToHour()
729  {
730  long long total;
731  total = min * 60 * 1000 + sec * 1000 + msec;
732  double k = day * 24 + hour + total / 36000000.0000;
733  return k;
734  }
738  double convertToMin()
739  {
740  long long total;
741  total = sec * 1000 + msec;
742  double k = day * 24 * 60 + hour * 60 + min + total / 60000.0000;
743  return k;
744  }
748  double convertToSec()
749  {
750  long long total;
751  total = msec;
752  double k = day * 24 * 60 * 60 + hour * 60 * 60 + min * 60 + sec + total / 1000.0000;
753  return k;
754  }
758  long long convertToMsec()
759  {
760  long long total;
761  total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
762  return total;
763  }
769  Duration recoverForm(const long long &t)
770  {
771  msec = t;
772  sec = 0;
773  min = 0;
774  hour = 0;
775  day = 0;
776 
777  if (msec / 1000 != 0)
778  {
779  sec += msec / 1000;
780  msec = msec % 1000;
781  }
782 
783  if (sec / 60 != 0)
784  {
785  min += sec / 60;
786  sec = sec % 60;
787  }
788 
789  if (min / 60 != 0)
790  {
791  hour += min / 60;
792  min = min % 60;
793  }
794 
795  if (hour / 24 != 0)
796  {
797  day += hour / 24;
798  hour = hour % 24;
799  }
800  return Duration(day, hour, min, sec, msec);
801  }
802 };
816 std::ostream& operator<<(std::ostream &os, const Duration &a);
817 
818 using Milliseconds = std::chrono::duration<uint64_t, std::milli>;
819 using Seconds = std::chrono::duration<uint64_t>;
823 #define ISO8086A "yyyy-mm-ddThh:mi:ss"
824 
827 #define ISO8086B "yyyy-mm-ddThh:mi:ss.sss"
828 
829 
836 class DateTime
837 {
838 private:
839  static Duration& dTOD(const Milliseconds& d1, Duration &D1);
840  static Milliseconds& DTOd(const Duration &D1, Milliseconds& d1);
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);
844 public:
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);
871  static Duration& calculateTime(const std::string &time1, const std::string &time2, Duration &result, const std::string &format1 = ISO8086A, const std::string &format2 = 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);
893 private:
894  Duration dt{-1, -1, -1, -1, -1};
895  bool flag = false;
896  std::chrono::steady_clock::time_point start;
897  std::chrono::steady_clock::time_point end;
898 public:
903  bool startTiming();
915 public:
920  Duration getDt() { return dt; }
925  bool isStart() { return flag; }
926 };
927 }
928 namespace file
929 {
934 class LogFile : private time::DateTime, protected file::File
935 {
936 private:
937  std::string timeFormat;
938  std::string contentFormat;
939 public:
949  bool openFile(const std::string &fileName, const std::string &timeFormat = ISO8086A, const std::string &contentFormat = " ");
954  bool isOpen() { return File::isOpen(); }
959  std::string getFileName() { return File::getFileName(); }
965  bool closeFile(const bool &del = false);
971  bool writeLog(const std::string &data);
976  bool clearLog();
984  bool deleteLogByTime(const std::string &date1 = "1", const std::string &date2 = "2");
985 };
986 }
992  namespace data
993  {
998  {
999  public:
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);
1048  };
1052  class BitUtil
1053  {
1054  public:
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);
1114  };
1119  {
1120  public:
1128  static long getRandomNumber(const long &a, const long &b);
1135  static std::string& getRandomStr_base64(std::string &str, const int &length);
1149  static std::string& generateMask_4(std::string &mask);
1150  };
1155  {
1156  public:
1168  static unsigned long& htonl_ntohl_64(unsigned long &data); // 64-bit unsigned number conversion to big/little endian (network byte order)
1169  };
1170 
1175  {
1176  public:
1177 
1186  static std::string& getPreciesFloat(const float &number, const int &bit, std::string &str);
1194  static float& getPreciesFloat(float &number, const int &bit);
1203  static std::string& getPreciesDouble(const double &number, const int &bit, std::string &str);
1211  static double& getPreciesDouble(double &number, const int &bit);
1223  static float& getValidFloat(float &number, const int &bit);
1224  };
1230  {
1231  public:
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 &para);
1298 
1299 
1300 
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 &para);
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)
1421  {
1422  std::string cf = first + ": " + second + "\r\n" + createHeader(args...);
1423  return cf;
1424  }
1425  };
1430  {
1431  public:
1443  static std::string& transfer_websocket_key(std::string &str);
1444  };
1449  {
1450  public:
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); // String to hexadecimal string (Not needed for now) (To be fixed)
1513  };
1518  {
1519  public:
1528  static std::string base64_encode(const std::string &input);
1537  static std::string base64_decode(const std::string &input);
1549  static std::string& transfer_websocket_key(std::string &str);
1563  static std::string& generateMask_4(std::string &mask);
1574  static std::string& maskCalculate(std::string &data, const std::string &mask);
1575  };
1580  {
1581  public:
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);
1595 
1601  static std::string toString(const Json::Value &val);
1607  static Json::Value toJsonArray(const std::string & str);
1617  template<class T1, class T2>
1618  static std::string createJson(T1 first, T2 second)
1619  {
1620  Json::Value root;
1621  root[first] = second;
1622  Json::StreamWriterBuilder builder;
1623  std::string jsonString = Json::writeString(builder, root);
1624  return jsonString;
1625  }
1637  template<class T1, class T2, class... Args>
1638  static std::string createJson(T1 first, T2 second, Args... args)
1639  {
1640  Json::Value root;
1641  root[first] = second;
1642  std::string kk = createJson(args...);
1643  Json::StreamWriterBuilder builder;
1644  std::string jsonString = Json::writeString(builder, root);
1645  jsonString = jsonString.erase(jsonString.length() - 2);
1646  kk = kk.substr(1);
1647  return jsonString + "," + kk;
1648 
1649  }
1657  template<class T>
1658  static std::string createArray(T first)
1659  {
1660  Json::Value root(Json::arrayValue);
1661  root.append(first);
1662  Json::StreamWriterBuilder builder;
1663  std::string jsonString = Json::writeString(builder, root);
1664  return jsonString;
1665  }
1675  template<class T, class... Args>
1676  static std::string createArray(T first, Args... args)
1677  {
1678  Json::Value root(Json::arrayValue);
1679  root.append(first);
1680  std::string kk = createArray(args...);
1681  Json::StreamWriterBuilder builder;
1682  std::string jsonString = Json::writeString(builder, root);
1683  jsonString = jsonString.erase(jsonString.length() - 2);
1684  kk = kk.substr(1);
1685  return jsonString + "," + kk;
1686 
1687  }
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);
1709  };
1710  }
1711 
1715  namespace security
1716  {
1721  {
1723  std::deque<std::chrono::steady_clock::time_point> connectionTimeQueue;
1724  };
1731  {
1732  private:
1733  int connectionLimit;
1734  int connectionRateLimit;
1735  std::unordered_map<std::string,IPInformation> connectionTable;
1736 
1737  public:
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);
1755  };
1756  }
1757 
1763  namespace network
1764  {
1769  {
1770  protected:
1771  int fd = -1;
1772  bool flag1 = false;
1773  bool flag2 = false;
1774  SSL *ssl = nullptr;
1775  int sec=-1;
1776  public:
1780  bool flag3 = false;
1781  public:
1792  void setFD(const int &fd, SSL *ssl, const bool &flag1 = false, const bool &flag2 = false,const int &sec=-1);
1797  int getFD() { return fd; }
1802  SSL *getSSL() { return ssl; }
1807  void close(const bool &cle = true);
1812  void blockSet(const int &sec = -1);
1816  void unblockSet();
1820  bool multiUseSet();
1825  bool isConnect() { if (fd == -1) return false; else return true; }
1826  public:
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);
1889  int recvDataByLength(std::string &data, const uint64_t &length, const int &sec = 2);
1905  int recvDataByLength(char *data, const uint64_t &length, const int &sec = 2);
1918  int recvData(std::string &data, const uint64_t &length);
1931  int recvData(char *data, const uint64_t &length);
1932  };
1933 
1938  class TcpClient : public TcpFDHandler
1939  {
1940  private:
1941  std::string serverIP = "";
1942  int serverPort = -1;
1943  bool flag = false;
1944  bool TLS;
1945  SSL_CTX *ctx = nullptr;
1946  const char *ca;
1947  const char *cert;
1948  const char *key;
1949  const char *passwd;
1950  private:
1951  bool createFD();
1952  void closeAndUnCreate();
1953  bool initCTX(const char *ca, const char *cert = "", const char *key = "", const char *passwd = "");
1954  public:
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 = "");
1993  bool close();
1997  ~TcpClient() { closeAndUnCreate(); }
1998  public:
2003  std::string getServerIP() { return serverIP; }
2008  int getServerPort() { return serverPort; }
2013  bool isConnect() { return flag; }
2014  };
2015 
2023  class HttpClient : private TcpClient
2024  {
2025  private:
2026  bool flag = false;
2027  public:
2040  HttpClient(const bool &TLS = false, const char *ca = "", const char *cert = "", const char *key = "", const char *passwd = "") : TcpClient(TLS, ca, cert, key, passwd) {}
2041  public:
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);
2120  public:
2125  bool isReturn() { return flag; }
2129  std::string header = "";
2133  std::string body = "";
2134  };
2135 
2140  {
2141  private:
2142  int fd;
2143  bool flag = true;
2144  std::function<bool(const int &fd)> fc = [](const int &fd)->bool
2145  {return true;};
2146  std::function<void(const int &fd)> fcEnd = [](const int &fd)->void
2147  {};
2148  std::function<bool(const int &fd)> fcTimeOut = [](const int &fd)->bool
2149  {return true;};
2150  bool flag1 = true;
2151  bool flag2 = false;
2152  time::Duration dt{0,20,0,0,0};
2153  bool flag3 = false;
2154  time::Duration t;
2155  private:
2156  void epolll();
2157  public:
2164  void startListen(const int &fd, const bool &flag = true, const time::Duration &dt = time::Duration{0,0,20,0,0});
2165  public:
2170  bool isListen() { return flag2; }
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; };
2198  void setTimeOutFunction(std::function<bool(const int &fd)> fcTimeOut) { this->fcTimeOut = fcTimeOut; };
2204  bool endListen();
2209  void endListenWithSignal() { flag1 = false; }
2215  void waitAndQuit(const time::Duration &t = time::Duration{0,0,0,10,10}) { flag3 = true; this->t = t; }
2221  };
2222 
2228  class WebSocketClient : private TcpClient
2229  {
2230  private:
2231  bool flag4 = false;
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;};
2234  std::string url;
2235  EpollSingle k;
2236  bool flag5 = false;
2237  private:
2238  bool close1();
2239  public:
2252  WebSocketClient(const bool &TLS = false, const char *ca = "", const char *cert = "", const char *key = "", const char *passwd = "") : TcpClient(TLS, ca, cert, key, passwd) {}
2263  void setFunction(std::function<bool(const std::string &message, WebSocketClient &k)> fc) { this->fc = fc; }
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);
2325  public:
2330  bool isConnect() { return flag4; }
2335  std::string getUrl() { return url; }
2340  std::string getServerIp() { return TcpClient::getServerIP(); }
2345  std::string getServerPort() { return TcpClient::getServerIP(); }
2349  ~WebSocketClient();
2350  };
2351 
2356  {
2360  std::string_view type;
2364  std::string_view locPara;
2368  std::string_view loc;
2372  std::string_view para;
2376  std::string_view header;
2380  std::string_view body;
2384  std::string body_chunked;
2385 
2386  };
2387 
2388  struct TcpFDInf;
2394  {
2395  public:
2403  void setFD(const int &fd, SSL *ssl = nullptr, const bool &flag1 = false, const bool &flag2 = true) { TcpFDHandler::setFD(fd, ssl, flag1, flag2); }
2418  int solveRequest(TcpFDInf &TcpInf,const unsigned long &buffer_size,const int &times=1);
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);
2443  };
2444 
2449  {
2453  int fd;
2461  std::string locPara;
2465  std::string header;
2469  time_t HBTime = 0;
2473  time_t response;
2477  size_t recv_length;
2485  std::string message="";
2489  bool fin;
2493  std::string mask;
2494 
2495  };
2496 
2500  struct TcpFDInf
2501  {
2505  int fd;
2509  std::string ip;
2513  std::string port;
2517  int status;
2521  std::string_view data;
2529  SSL* ssl;
2530 
2534  char *buffer;
2538  unsigned long p_buffer_now;
2539  //unsigned long p_request_now;
2547  std::deque<std::chrono::steady_clock::time_point> requestSpeedQueue;
2548  };
2549 
2553  struct QueueFD
2554  {
2558  int fd;
2562  bool close;
2563  };
2564 
2569  class TcpServer
2570  {
2571  protected:
2572  unsigned long buffer_size;
2573  int maxFD;
2575  //std::unordered_map<int,TcpFDInf> clientfd;
2576  //std::mutex lc1;
2578  int flag1 = true;
2579  std::queue<QueueFD> *fdQueue;
2580  std::mutex *lq1;
2581  //std::condition_variable cv1;
2582  std::condition_variable *cv;
2584  std::mutex lco1;
2585  bool unblock;
2586  SSL_CTX *ctx = nullptr;
2587  bool TLS = false;
2588  //std::unordered_map<int,SSL*> tlsfd;
2589  //std::mutex ltl1;
2594  protected:
2595  bool allowRequest(const int &cclientfd);
2596  void connectionDetect();
2597  private:
2598  std::function<bool(TcpFDHandler &k,TcpFDInf &inf)> fc;
2599  int fd = -1;
2600  int port = -1;
2601  int flag = false;
2602  bool flag2 = false;
2603  private:
2604  void epolll(const int &evsNum);
2605  virtual void consumer(const int &threadID);
2606  public:
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);
2658  void redrawTLS();
2669  bool setFunction(std::function<bool(TcpFDHandler &k,TcpFDInf &inf)> fc) { this->fc = fc; return true; }
2675  bool stopListen();
2682  bool close();
2688  bool close(const int &fd);
2689  public:
2694  bool isListen() { return flag; }
2699  SSL* getSSL(const int &fd);
2705  };
2706 
2707 
2708 
2713  class HttpServer : public TcpServer
2714  {
2715  private:
2716  std::function<bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc;
2717  private:
2718  void consumer(const int &threadID);
2719  public:
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){}
2743  bool setFunction(std::function<bool(const HttpRequestInformation &inf, HttpServerFDHandler &k)> fc) { this->fc = fc; return true; }
2744  };
2750  {
2751  public:
2759  void setFD(const int &fd, SSL *ssl = nullptr, const bool &flag1 = false, const bool &flag2 = true) { TcpFDHandler::setFD(fd, ssl, flag1, flag2); }
2781  int getMessage(TcpFDInf &Tcpinf,WebSocketFDInformation &Websocketinf,const int &ii=1);
2796  bool sendMessage(const std::string &msg, const std::string &type = "0001");
2797 
2798  };
2799 
2804  {
2805  private:
2806  std::unordered_map<int, WebSocketFDInformation> wbclientfd;
2807  std::mutex lwb;
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;};
2810  std::function<bool(const WebSocketFDInformation &k)> fcc = [](const WebSocketFDInformation &k)
2811  {return true;};
2812  std::function<void(const WebSocketFDInformation &inf, WebSocketServer &k)> fccc = [](const WebSocketFDInformation &inf, WebSocketServer &k)
2813  {
2814 
2815  };
2816  int seca = 20*60;
2817  int secb = 30;
2818  bool HBflag;
2819  bool HBflag1;
2820  private:
2821  void consumer(const int &threadID);
2822 
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");
2825  void HB();
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");
2828  public:
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){}
2847  void setStartFunction(std::function<void(const WebSocketFDInformation &inf, WebSocketServer &k)> fccc) { this->fccc = fccc; }
2857  void setJudgeFunction(std::function<bool(const WebSocketFDInformation &k)> fcc) { this->fcc = fcc; }
2869  void setFunction(std::function<bool(const std::string &msg, WebSocketServer &k,const WebSocketFDInformation &inf)> fc) { this->fc = fc; }
2874  void setTimeOutTime(const int &seca) { this->seca = seca * 60; }
2880  void setHBTimeOutTime(const int &secb) { this->secb = secb; }
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");
2937  bool sendMessage(const int &fd, const std::string &msg, const std::string &type = "0001") { WebSocketServerFDHandler k; k.setFD(fd, getSSL(fd), unblock); return k.sendMessage(msg, type); }
2942  bool close();
2949  bool startListen(const int &port, const int &threads = 8)
2950  {
2951  std::thread(&WebSocketServer::HB, this).detach();
2952  return TcpServer::startListen(port, threads);
2953  }
2975  void sendMessage(const std::string &msg, const std::string &type = "0001");
2980  ~WebSocketServer() { HBflag1 = false; while(HBflag); }
2981  };
2982 
2988  {
2989  protected:
2990  int fd = -1;
2991  bool flag1 = false;
2992  bool flag2 = false;
2993  int sec = -1;
2994  public:
3002  void setFD(const int &fd, const bool &flag1 = false, const int &sec = -1, const bool &flag2 = false);
3007  void blockSet(const int &sec = -1);
3011  void unblockSet();
3016  bool multiUseSet();
3020  int getFD() { return fd; }
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);
3098 
3099  };
3103  class UdpClient : public UdpFDHandler
3104  {
3105  public:
3111  UdpClient(const bool &flag1 = false, const int &sec = -1);
3117  bool createFD(const bool &flag1 = false, const int &sec = -1);
3122  };
3126  class UdpServer : public UdpFDHandler
3127  {
3128  public:
3136  UdpServer(const int &port, const bool &flag1 = false, const int &sec = -1, const bool &flag2 = true);
3143  bool createFD(const int &port, const bool &flag1 = false, const int &sec = -1, const bool &flag2 = true);
3148  };
3149  }
3155  namespace system
3156  {
3166  {
3167  public:
3175  static std::string language;
3176  private:
3177  static void signalterminated(){std::cout<<"Terminated by uncaught exception"<<std::endl;if(ServerSetting::logfile!=nullptr){if(ServerSetting::language=="Chinese")ServerSetting::logfile->writeLog("未捕获的异常终止");else ServerSetting::logfile->writeLog("end for uncaught exception");}kill(getpid(),15);}
3178  static void signalSIGSEGV(int signal){std::cout<<"SIGSEGV"<<std::endl;if(ServerSetting::logfile!=nullptr){if(ServerSetting::language=="Chinese")ServerSetting::logfile->writeLog("信号SIGSEGV");else ServerSetting::logfile->writeLog("signal SIGSEGV");}kill(getpid(),15);}
3179  static void signalSIGABRT(int signal){std::cout<<"SIGABRT"<<std::endl;if(ServerSetting::logfile!=nullptr){if(ServerSetting::language=="Chinese")ServerSetting::logfile->writeLog("信号SIGABRT");else ServerSetting::logfile->writeLog("signal SIGABRT");}kill(getpid(),15);}
3180  public:
3189  static void setExceptionHandling();
3199  static void setLogFile(file::LogFile *logfile = nullptr, const std::string &language = "");
3206  static void init(file::LogFile *logfile = nullptr, const std::string &language = "");
3207  };
3208 
3217  class csemp
3218  {
3219  private:
3225  union semun
3226  {
3227  int val;
3228  struct semid_ds *buf;
3229  unsigned short *arry;
3230  };
3231 
3232  int m_semid;
3233  short m_sem_flg;
3234 
3235  csemp(const csemp &) = delete;
3236  csemp &operator=(const csemp &) = delete;
3237 
3238  public:
3242  csemp():m_semid(-1){}
3243 
3254  bool init(key_t key, unsigned short value = 1, short sem_flg = SEM_UNDO);
3255 
3264  bool wait(short value = -1);
3265 
3274  bool post(short value = 1);
3275 
3281  int getvalue();
3282 
3290  bool destroy();
3291 
3295  ~csemp();
3296  };
3297 
3301  #define MAX_PROCESS_NAME 100
3302 
3305  #define MAX_PROCESS_INF 1000
3306 
3309  #define SHARED_MEMORY_KEY 0x5095
3310 
3313  #define SHARED_MEMORY_LOCK_KEY 0x5095
3314 
3318  struct ProcessInf
3319  {
3323  pid_t pid;
3327  time_t lastTime;
3335  char argv0[20];
3339  char argv1[20];
3343  char argv2[20];
3344  };
3345 
3353  class HBSystem
3354  {
3355  private:
3356 
3357  static ProcessInf *p;
3358  static csemp plock;
3359  static bool isJoin;
3360  public:
3369  bool join(const char *name, const char *argv0 = "", const char *argv1 = "", const char *argv2 = "");
3374  bool renew();
3378  static void list();
3385  static bool HBCheck(const int &sec);
3390  bool deleteFromHBS();
3395  ~HBSystem();
3396  };
3397 
3401  class Process
3402  {
3403  public:
3404 
3405 
3426  template<class... Args>
3427  static bool startProcess(const std::string &name, const int &sec = -1, Args ...args)
3428  {
3429  std::vector<const char *> paramList={args...,nullptr};
3430  if(sec==-1)
3431  {
3432  pid_t pid=fork();
3433  if(pid==-1)
3434  return false;
3435  if(pid>0)
3436  return true;
3437  else
3438  {
3439  execv(name.c_str(),const_cast<char* const*>(paramList.data()));
3440  return false;
3441  }
3442  }
3443  for(int ii=1;ii<=64;ii++)
3444  signal(ii,SIG_IGN);
3445  pid_t pid=fork();
3446  if(pid==-1)
3447  return false;
3448  if(pid>0)
3449  {
3450  return true;
3451  }
3452  else
3453  {
3454  signal(SIGCHLD,SIG_DFL);
3455  signal(15,SIG_DFL);
3456  while(1)
3457  {
3458  pid=fork();
3459  if(fork()==0)
3460  {
3461  execv(name.c_str(),const_cast<char* const*>(paramList.data()));
3462  exit(0);
3463  }
3464  else if(pid>0)
3465  {
3466  int sts;
3467  wait(&sts);
3468  sleep(sec);
3469  }
3470  else
3471  continue;
3472  }
3473  }
3474  }
3496  template<class Fn, class... Args>
3497  static typename std::enable_if<!std::is_convertible<Fn, std::string>::value, bool>::type
3498  startProcess(Fn&& fn, const int &sec = -1, Args &&...args)
3499  {
3500  if(sec==-1)
3501  {
3502  pid_t pid=fork();
3503  if(pid==-1)
3504  return false;
3505  if(pid>0)
3506  return true;
3507  else
3508  {
3509  auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
3510  f();
3511  return true;
3512  }
3513  }
3514  for(int ii=1;ii<=64;ii++)
3515  signal(ii,SIG_IGN);
3516  pid_t pid=fork();
3517  if(pid==-1)
3518  return false;
3519  if(pid>0)
3520  {
3521  return true;
3522  }
3523  else
3524  {
3525  signal(SIGCHLD,SIG_DFL);
3526  signal(15,SIG_DFL);
3527  while(1)
3528  {
3529  pid=fork();
3530  if(pid==0)
3531  {
3532  auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
3533  f();
3534  return true;
3535  }
3536  else if(pid>0)
3537  {
3538  int sts;
3539  wait(&sts);
3540  sleep(sec);
3541  }
3542  else
3543  continue;
3544  }
3545  }
3546  }
3547  };
3548  }
3549 
3550 
3551 }
3552 
3553 
3554 #endif
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.
time_t response
Time of last received message.
Definition: sttnet_English.h:2473
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
bool fin
state of fin
Definition: sttnet_English.h:2489
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.
std::string header
Http/Https request header during the handshake phase.
Definition: sttnet_English.h:2465
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 size_t get_file_size(const std::string &fileName)
Get the size of a file.
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.
std::string_view locPara
Path and parameters in the url.
Definition: sttnet_English.h:2364
static int & str16toInt(const std::string_view &ori_str, int &result, const int &i=-1)
Convert a hexadecimal number&#39;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
std::string body_chunked
Request body(chunked)
Definition: sttnet_English.h:2384
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 &lt;-&gt; 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.
A structure that records IP information, such as the number of connections, connection rate...
Definition: sttnet_English.h:1720
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 &#39;=&#39; 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 &quot;yyyy-mm-ddThh:mi:ss&quot;.
Definition: sttnet_English.h:823
std::string message
Message.
Definition: sttnet_English.h:2485
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&#39;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.
static bool createFile(const std::string &filePath, const mode_t &mode=0666)
Create a new file.
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
std::string locPara
Http/Https path and parameters during the handshake phase.
Definition: sttnet_English.h:2461
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.
std::string_view body
Request body.
Definition: sttnet_English.h:2380
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.
std::string_view type
request&#39;s type
Definition: sttnet_English.h:2360
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.
std::string_view loc
Path in the url.
Definition: sttnet_English.h:2368
bool close()
If the object has a socket connection, close and release the connection and socket, and create a new socket.
std::deque< std::chrono::steady_clock::time_point > connectionTimeQueue
Definition: sttnet_English.h:1723
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...
Structure to save HTTP/HTTPS request information.
Definition: sttnet_English.h:2355
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 &quot;01&quot; 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
size_t recv_length
Length to be received.
Definition: sttnet_English.h:2477
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.
std::string_view header
Request header.
Definition: sttnet_English.h:2376
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
Structure to save client WS/WSS request information.
Definition: sttnet_English.h:2448
std::condition_variable * cv
Definition: sttnet_English.h:2582
std::string_view para
Parameters in the url.
Definition: sttnet_English.h:2372
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
static bool copy(const std::string &sourceFile, const std::string &objectFile)
Copy a file.
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 &para)
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&#39;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
static bool createDir(const std::string &ddir, const mode_t &mode=0775)
Create a new directory.
int message_type
Message type.
Definition: sttnet_English.h:2481
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 &quot;01&quot; 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
time_t HBTime
Time of sending heartbeat (fill in 0 if not sent) (should be cleared to 0 after checking) ...
Definition: sttnet_English.h:2469
#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&#39;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
int connectionNum
Definition: sttnet_English.h:1722
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 &times=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
std::string mask
mask
Definition: sttnet_English.h:2493
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
bool closeflag
true: Close frame sent, false: Close frame not sent
Definition: sttnet_English.h:2457
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
int fd
Underlying socket descriptor.
Definition: sttnet_English.h:2453
void setHBTimeOutTime(const int &secb)
Set the waiting time after sending a heartbeat.
Definition: sttnet_English.h:2880
A utility class that provides static functions for file operations.
Definition: sttnet_English.h:66
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 &#39;1&#39; or &#39;0&#39;...
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.