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

Method InputNotify

adapter/micro_thread/mt_notify.cpp:129–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129int UdpSessionNtfy::InputNotify()
130{
131 while (1)
132 {
133 int ret = 0;
134 int have_rcv_len = 0;
135
136 if (!_msg_buff) {
137 _msg_buff = MsgBuffPool::Instance()->GetMsgBuf(this->GetMsgBuffSize());
138 if (NULL == _msg_buff) {
139 MTLOG_ERROR("Get memory failed, size %d, wait next time", this->GetMsgBuffSize());
140 return 0;
141 }
142 _msg_buff->SetBuffType(BUFF_RECV);
143 }
144 char* buff = (char*)_msg_buff->GetMsgBuff();
145
146 int osfd = this->GetOsfd();
147 struct sockaddr_in from;
148 socklen_t fromlen = sizeof(from);
149 mt_hook_syscall(recvfrom);
150 ret = ff_hook_recvfrom(osfd, buff, _msg_buff->GetMaxLen(),
151 0, (struct sockaddr*)&from, &fromlen);
152 if (ret < 0)
153 {
154 if ((errno == EINTR) || (errno == EAGAIN) || (errno == EINPROGRESS))
155 {
156 return 0;
157 }
158 else
159 {
160 MTLOG_ERROR("recv error, fd %d", osfd);
161 return 0;
162 }
163 }
164 else if (ret == 0)
165 {
166 MTLOG_DEBUG("remote close connection, fd %d", osfd);
167 return 0;
168 }
169 else
170 {
171 have_rcv_len = ret;
172 _msg_buff->SetHaveRcvLen(have_rcv_len);
173 _msg_buff->SetMsgLen(have_rcv_len);
174 }
175
176 int sessionid = 0;
177 ret = this->GetSessionId(buff, have_rcv_len, sessionid);
178 if (ret <= 0)
179 {
180 MTLOG_ERROR("recv get session failed, len %d, fd %d, drop it",
181 have_rcv_len, osfd);
182 MsgBuffPool::Instance()->FreeMsgBuf(_msg_buff);
183 _msg_buff = NULL;
184 return 0;
185 }
186

Callers

nothing calls this directly

Calls 15

GetSessionIdMethod · 0.95
SetBuffTypeMethod · 0.80
GetMsgBuffMethod · 0.80
GetOsfdMethod · 0.80
GetMaxLenMethod · 0.80
SetHaveRcvLenMethod · 0.80
SetMsgLenMethod · 0.80
GetSessionConnMethod · 0.80
GetMtMsgBuffMethod · 0.80
SetMtMsgBuffMethod · 0.80
SetRcvEventsMethod · 0.80
HasFlagMethod · 0.80

Tested by

no test coverage detected