-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.h
More file actions
57 lines (49 loc) · 1.06 KB
/
utils.h
File metadata and controls
57 lines (49 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef UTILS_H_
#define UTILS_H_
#include<string>
#include<sstream>
#ifdef LINUX
#include<assert.h>
#include<netinet/in.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/tcp.h>
using SockInt = int;
#else
#include <stdint.h>
#include <stdio.h>
#include <Winsock2.h>
#pragma comment(lib, "ws2_32.lib")
using SockInt = SOCKET;
#endif
template<typename T>
std::string Type2String(T& t){
std::ostringstream os;
os << t;
return os.str();
}
template<typename T>
T String2Type(std::string& str){
std::istringstream ss(str);
T result;
ss >> result;
return result;
}
std::string GetLocalTime();
//for socket use
void InitSocketAddr(std::string& ip, uint16_t port, sockaddr_in* addr);
int SetNonBlock(int fd);
int SetReuseAddr(int fd);
int SetRecvSendBufSize(int fd, int size);
int SetKeepLive(int fd, int idle, int interval, int count);
#endif