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

Method CreateSocket

adapter/micro_thread/mt_notify.cpp:75–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75int UdpSessionNtfy::CreateSocket()
76{
77 int osfd = socket(AF_INET, SOCK_DGRAM, 0);
78 if (osfd < 0)
79 {
80 MTLOG_ERROR("socket create failed, errno %d(%s)", errno, strerror(errno));
81 return -1;
82 }
83
84 int flags = 1;
85 if (ioctl(osfd, FIONBIO, &flags) < 0)
86 {
87 MTLOG_ERROR("socket unblock failed, errno %d(%s)", errno, strerror(errno));
88 close(osfd);
89 osfd = -1;
90 return -2;
91 }
92
93 if (_local_addr.sin_port != 0)
94 {
95 int ret = bind(osfd, (struct sockaddr *)&_local_addr, sizeof(_local_addr));
96 if (ret < 0)
97 {
98 MTLOG_ERROR("socket bind(%s:%d) failed, errno %d(%s)", inet_ntoa(_local_addr.sin_addr),
99 ntohs(_local_addr.sin_port), errno, strerror(errno));
100 close(osfd);
101 osfd = -1;
102 return -3;
103 }
104 }
105
106 this->SetOsfd(osfd);
107 this->EnableInput();
108 MtFrame* frame = MtFrame::Instance();
109 frame->KqueueNtfyReg(osfd, this);
110 frame->KqueueCtrlAdd(osfd, KQ_EVENT_READ);
111
112 return osfd;
113}
114
115void UdpSessionNtfy::CloseSocket()
116{

Callers 2

mt_multi_newsockMethod · 0.45
mt_tcp_get_keep_connFunction · 0.45

Calls 8

SetOsfdMethod · 0.80
EnableInputMethod · 0.80
KqueueNtfyRegMethod · 0.80
KqueueCtrlAddMethod · 0.80
socketFunction · 0.70
ioctlFunction · 0.70
closeFunction · 0.70
bindFunction · 0.70

Tested by

no test coverage detected