mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-11-29 16:14:16 +01:00
Restart server when network drops
This commit is contained in:
parent
2ff33ca398
commit
d38cea4e7b
@ -1,5 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
int ftp_init(void);
|
||||
int ftp_loop(void);
|
||||
void ftp_exit(void);
|
||||
/*! Loop status */
|
||||
typedef enum
|
||||
{
|
||||
LOOP_CONTINUE, /*!< Continue looping */
|
||||
LOOP_RESTART, /*!< Reinitialize */
|
||||
LOOP_EXIT, /*!< Terminate looping */
|
||||
} loop_status_t;
|
||||
|
||||
int ftp_init(void);
|
||||
loop_status_t ftp_loop(void);
|
||||
void ftp_exit(void);
|
||||
|
11
source/ftp.c
11
source/ftp.c
@ -1266,7 +1266,7 @@ ftp_exit(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
loop_status_t
|
||||
ftp_loop(void)
|
||||
{
|
||||
int rc;
|
||||
@ -1280,8 +1280,11 @@ ftp_loop(void)
|
||||
rc = poll(&pollinfo, 1, 0);
|
||||
if(rc < 0)
|
||||
{
|
||||
if(errno == ENETDOWN)
|
||||
return LOOP_RESTART;
|
||||
|
||||
console_print(RED "poll: %d %s\n" RESET, errno, strerror(errno));
|
||||
return -1;
|
||||
return LOOP_EXIT;
|
||||
}
|
||||
else if(rc > 0)
|
||||
{
|
||||
@ -1302,10 +1305,10 @@ ftp_loop(void)
|
||||
#ifdef _3DS
|
||||
hidScanInput();
|
||||
if(hidKeysDown() & KEY_B)
|
||||
return -1;
|
||||
return LOOP_EXIT;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return LOOP_CONTINUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -10,18 +10,24 @@
|
||||
/*! looping mechanism
|
||||
*
|
||||
* @param[in] callback function to call during each iteration
|
||||
*
|
||||
* @returns loop status
|
||||
*/
|
||||
static void
|
||||
loop(int (*callback)(void))
|
||||
static loop_status_t
|
||||
loop(loop_status_t (*callback)(void))
|
||||
{
|
||||
loop_status_t status = LOOP_CONTINUE;
|
||||
|
||||
#ifdef _3DS
|
||||
while(aptMainLoop())
|
||||
{
|
||||
if(callback() == 0)
|
||||
console_render();
|
||||
else
|
||||
return;
|
||||
status = callback();
|
||||
console_render();
|
||||
if(status != LOOP_CONTINUE)
|
||||
return status;
|
||||
}
|
||||
|
||||
return LOOP_EXIT;
|
||||
#else
|
||||
for(;;)
|
||||
callback();
|
||||
@ -30,9 +36,9 @@ loop(int (*callback)(void))
|
||||
|
||||
/*! wait until the B button is pressed
|
||||
*
|
||||
* @returns -1 if B was pressed
|
||||
* @returns loop status
|
||||
*/
|
||||
static int
|
||||
static loop_status_t
|
||||
wait_for_b(void)
|
||||
{
|
||||
#ifdef _3DS
|
||||
@ -41,12 +47,12 @@ wait_for_b(void)
|
||||
|
||||
/* check if B was pressed */
|
||||
if(hidKeysDown() & KEY_B)
|
||||
return -1;
|
||||
return LOOP_EXIT;
|
||||
|
||||
/* B was not pressed */
|
||||
return 0;
|
||||
return LOOP_CONTINUE;
|
||||
#else
|
||||
return -1;
|
||||
return LOOP_EXIT;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -61,6 +67,8 @@ int
|
||||
main(int argc,
|
||||
char *argv[])
|
||||
{
|
||||
loop_status_t status = LOOP_RESTART;
|
||||
|
||||
#ifdef _3DS
|
||||
/* initialize needed 3DS services */
|
||||
acInit();
|
||||
@ -73,14 +81,17 @@ main(int argc,
|
||||
console_init();
|
||||
console_set_status("\n" GREEN STATUS_STRING RESET);
|
||||
|
||||
/* initialize ftp subsystem */
|
||||
if(ftp_init() == 0)
|
||||
while(status == LOOP_RESTART)
|
||||
{
|
||||
/* ftp loop */
|
||||
loop(ftp_loop);
|
||||
/* initialize ftp subsystem */
|
||||
if(ftp_init() == 0)
|
||||
{
|
||||
/* ftp loop */
|
||||
status = loop(ftp_loop);
|
||||
|
||||
/* done with ftp */
|
||||
ftp_exit();
|
||||
/* done with ftp */
|
||||
ftp_exit();
|
||||
}
|
||||
}
|
||||
|
||||
console_print("Press B to exit\n");
|
||||
|
Loading…
Reference in New Issue
Block a user