MCPcopy Create free account
hub / github.com/aldostools/webMAN-MOD / ftpd_thread

Function ftpd_thread

include/ftp.h:1531–1600  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1529}
1530
1531static void ftpd_thread(__attribute__((unused)) u64 arg)
1532{
1533 int list_s = NONE;
1534 ftp_active = 0;
1535 ftp_working = 1;
1536
1537 if(g_sem_transfer_limit == SYS_SEMAPHORE_ID_INVALID)
1538 {
1539 sys_semaphore_attribute_t sem_attr;
1540 sys_semaphore_attribute_initialize(sem_attr);
1541 sys_semaphore_attribute_name_set(sem_attr.name, "FTP_MCT");
1542
1543 sys_semaphore_create(&g_sem_transfer_limit, &sem_attr, MAX_FTP_TRANSFERS, MAX_FTP_TRANSFERS);
1544 }
1545
1546relisten:
1547 if(!working) goto end;
1548
1549 if(ftp_working) list_s = slisten(webman_config->ftp_port, FTP_BACKLOG);
1550
1551 if(list_s < 0)
1552 {
1553 sys_ppu_thread_sleep(1);
1554 goto relisten;
1555 }
1556
1557 active_socket[0] = list_s;
1558
1559 //if(list_s >= 0)
1560 {
1561 while(ftp_working)
1562 {
1563 sys_ppu_thread_usleep(ftp_active ? 5000 : 50000);
1564 if(!working || !ftp_working) break;
1565
1566 if(ftp_active > MAX_FTP_THREADS) continue;
1567
1568 int conn_s_ftp;
1569 if(sys_admin && ((conn_s_ftp = accept(list_s, NULL, NULL)) >= 0))
1570 {
1571 if(!working) {sclose(&conn_s_ftp); break;}
1572
1573 sys_ppu_thread_t t_id;
1574 sys_ppu_thread_create(&t_id, handleclient_ftp, (u64)conn_s_ftp, THREAD_PRIO_FTP, THREAD_STACK_SIZE_FTP_CLIENT, SYS_PPU_THREAD_CREATE_NORMAL, THREAD_NAME_FTPD);
1575 }
1576 else if((sys_net_errno == SYS_NET_EBADF) || (sys_net_errno == SYS_NET_ENETDOWN))
1577 {
1578 sclose(&list_s);
1579 goto relisten;
1580 }
1581 }
1582 }
1583end:
1584 sclose(&list_s);
1585
1586 if(g_sem_transfer_limit != SYS_SEMAPHORE_ID_INVALID)
1587 {
1588 // No threads can block for the semaphore to get deallocated

Callers

nothing calls this directly

Calls 3

sys_ppu_thread_sleepFunction · 0.85
slistenFunction · 0.50
scloseFunction · 0.50

Tested by

no test coverage detected