MCPcopy Create free account
hub / github.com/Tencent/phxsql / CreateTcpSocket

Function CreateTcpSocket

phxsqlproxy/phxsqlproxyutil.cpp:96–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96int CreateTcpSocket(const unsigned short port /* = 0 */, const char *ip /* = "*" */, bool is_reuse /* = false */) {
97 int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
98 if (fd >= 0) {
99 if (port != 0) {
100 if (is_reuse) {
101 int reuse_addr = 1;
102 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
103 }
104 struct sockaddr_in addr;
105 if (SetAddr(ip, port, addr) != 0) {
106 return -1;
107 }
108 int ret = bind(fd, (struct sockaddr*) &addr, sizeof(addr));
109 if (ret != 0) {
110 close(fd);
111 return -1;
112 }
113 }
114 }
115 return fd;
116}
117
118bool IsAuthReqPkg(const char * buf, int len) {
119 if (len < 5) {

Callers 1

StartWorkerFunction · 0.85

Calls 1

SetAddrFunction · 0.85

Tested by

no test coverage detected