MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / resolver_task

Function resolver_task

modules/network/socket/qca4020/modSocket.c:300–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

298}
299
300void resolver_task(void *pvParameter)
301{
302 xsSocket xss = (xsSocket)pvParameter;
303 xsMachine *the = xss->the;
304 uint8_t pass = 0; // 0 = resolve host, 1 = connect to host
305
306 while (pass < 2) {
307 if (0 == pass) {
308 struct qapi_hostent_s *host;
309 host = gethostbyname(xss->host);
310 if (host && (host->h_addrtype == AF_INET)) {
311 char ip[20];
312 struct in_addr addr;
313 addr.s_addr = *(u_long *)host->h_addr_list[0];
314 inet_ntop(AF_INET, &addr, ip, 20);
315 if (c_strlen(ip) > 0) {
316 struct sockaddr_in to = {0};
317 to.sin_addr.s_addr = addr.s_addr;
318 to.sin_port = htons(xss->port);
319 to.sin_family = AF_INET;
320 connect(xss->skt, (struct sockaddr*)&to, sizeof(struct sockaddr_in));
321 ++pass;
322 }
323 else {
324 modMessagePostToMachine(xss->the, NULL, 0, socketError, xss);
325 break;
326 }
327 }
328 else {
329 modMessagePostToMachine(xss->the, NULL, 0, socketError, xss);
330 break;
331 }
332 }
333 else if (1 == pass) {
334 if (!xss->done && !xss->connected) {
335 int32_t result;
336 qapi_fd_set_t rset;
337 qapi_fd_zero(&rset);
338 qapi_fd_set(xss->skt, &rset);
339 result = qapi_select(&rset, NULL, NULL, 20);
340 if (result < 0) {
341 xss->done = true; // socket no longer valid
342 modMessagePostToMachine(the, NULL, 0, socketDisconnected, xss);
343 ++pass;
344 }
345 else {
346 xss->connected = true;
347 modMessagePostToMachine(the, NULL, 0, socketConnected, xss);
348 ++pass;
349 }
350 }
351 else
352 break;
353 }
354 }
355
356 qurt_thread_stop();
357}

Callers

nothing calls this directly

Calls 2

connectFunction · 0.50
modMessagePostToMachineFunction · 0.50

Tested by

no test coverage detected