MCPcopy Create free account
hub / github.com/F-Stack/f-stack / mt_tcp_create_sock

Function mt_tcp_create_sock

adapter/micro_thread/mt_api.cpp:87–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87int mt_tcp_create_sock(void)
88{
89 int fd;
90 int flag;
91
92 fd = ::socket(AF_INET, SOCK_STREAM, 0);
93 if (fd < 0)
94 {
95 MTLOG_ERROR("create tcp socket failed, error: %m");
96 return -1;
97 }
98
99 flag = fcntl(fd, F_GETFL, 0);
100 if (flag == -1)
101 {
102 ::close(fd);
103 MTLOG_ERROR("get fd flags failed, error: %m");
104 return -2;
105 }
106
107 if (flag & O_NONBLOCK)
108 return fd;
109
110 if (fcntl(fd, F_SETFL, flag | O_NONBLOCK | O_NDELAY) == -1)
111 {
112 ::close(fd);
113 MTLOG_ERROR("set fd flags failed, error: %m");
114 return -3;
115 }
116
117 return fd;
118}
119
120static TcpKeepConn* mt_tcp_get_keep_conn(struct sockaddr_in* dst, int& sock)
121{

Callers 2

mt_tcpsendrcv_shortFunction · 0.85
mt_tcpsend_shortFunction · 0.85

Calls 3

socketFunction · 0.70
fcntlFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected