MCPcopy Create free account
hub / github.com/acl-dev/acl / OnBnClickedStartGet

Method OnBnClickedStartGet

lib_fiber/samples-gui/HttpGet/HttpGetDlg.cpp:202–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202void CHttpGetDlg::OnBnClickedStartGet()
203{
204 // TODO: 在此添加控件通知处理程序代码
205 CString* url = new CString;
206 GetDlgItem(IDC_URL)->GetWindowText(*url);
207 if (url->IsEmpty()) {
208 MessageBox("Please input http url first!");
209 GetDlgItem(IDC_URL)->SetFocus();
210 delete url;
211 return;
212 }
213
214 CString filePath;
215 GetDlgItem(IDC_FILE)->GetWindowText(filePath);
216
217 m_progress.SetPos(0);
218 m_lastPos = 0;
219
220 if (m_downType == HTTP_DOWNLOAD_FIBER) {
221 go[=] {
222 CHttpClient client(*this, *url);
223 delete url;
224 client.run(m_usePost, filePath.IsEmpty() ? NULL : filePath.GetString());
225 };
226 } else if (m_downType == HTTP_DOWNLOAD_THREAD) {
227 go[=] {
228 acl::fiber_tbox<CHttpMsg> box;
229 std::thread thread([&] {
230 CHttpClient client(box, *url);
231 delete url;
232 client.run(m_usePost, filePath.IsEmpty() ? NULL : filePath.GetString());
233 });
234
235 thread.detach();
236
237 while (true) {
238 CHttpMsg* msg = box.pop();
239 if (msg == NULL) {
240 break;
241 }
242 switch (msg->m_type) {
243 case HTTP_MSG_ERR:
244 SetError("%s", msg->m_buf.GetString());
245 break;
246 case HTTP_MSG_REQ:
247 SetRequestHead(msg->m_buf.GetString());
248 break;
249 case HTTP_MSG_RES:
250 SetResponseHead(msg->m_buf.GetString());
251 break;
252 case HTTP_MSG_TOTAL_LENGTH:
253 SetBodyTotalLength(msg->m_length);
254 break;
255 case HTTP_MSG_LENGTH:
256 SetBodyLength(msg->m_length);
257 break;
258 default:
259 break;

Callers

nothing calls this directly

Calls 5

IsEmptyMethod · 0.80
SetPosMethod · 0.45
runMethod · 0.45
detachMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected