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
|
#pragma once
|
||||||
|
|
||||||
int ftp_init(void);
|
/*! Loop status */
|
||||||
int ftp_loop(void);
|
typedef enum
|
||||||
void ftp_exit(void);
|
{
|
||||||
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
loop_status_t
|
||||||
ftp_loop(void)
|
ftp_loop(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -1280,8 +1280,11 @@ ftp_loop(void)
|
|||||||
rc = poll(&pollinfo, 1, 0);
|
rc = poll(&pollinfo, 1, 0);
|
||||||
if(rc < 0)
|
if(rc < 0)
|
||||||
{
|
{
|
||||||
|
if(errno == ENETDOWN)
|
||||||
|
return LOOP_RESTART;
|
||||||
|
|
||||||
console_print(RED "poll: %d %s\n" RESET, errno, strerror(errno));
|
console_print(RED "poll: %d %s\n" RESET, errno, strerror(errno));
|
||||||
return -1;
|
return LOOP_EXIT;
|
||||||
}
|
}
|
||||||
else if(rc > 0)
|
else if(rc > 0)
|
||||||
{
|
{
|
||||||
@ -1302,10 +1305,10 @@ ftp_loop(void)
|
|||||||
#ifdef _3DS
|
#ifdef _3DS
|
||||||
hidScanInput();
|
hidScanInput();
|
||||||
if(hidKeysDown() & KEY_B)
|
if(hidKeysDown() & KEY_B)
|
||||||
return -1;
|
return LOOP_EXIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return LOOP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -10,18 +10,24 @@
|
|||||||
/*! looping mechanism
|
/*! looping mechanism
|
||||||
*
|
*
|
||||||
* @param[in] callback function to call during each iteration
|
* @param[in] callback function to call during each iteration
|
||||||
|
*
|
||||||
|
* @returns loop status
|
||||||
*/
|
*/
|
||||||
static void
|
static loop_status_t
|
||||||
loop(int (*callback)(void))
|
loop(loop_status_t (*callback)(void))
|
||||||
{
|
{
|
||||||
|
loop_status_t status = LOOP_CONTINUE;
|
||||||
|
|
||||||
#ifdef _3DS
|
#ifdef _3DS
|
||||||
while(aptMainLoop())
|
while(aptMainLoop())
|
||||||
{
|
{
|
||||||
if(callback() == 0)
|
status = callback();
|
||||||
console_render();
|
console_render();
|
||||||
else
|
if(status != LOOP_CONTINUE)
|
||||||
return;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return LOOP_EXIT;
|
||||||
#else
|
#else
|
||||||
for(;;)
|
for(;;)
|
||||||
callback();
|
callback();
|
||||||
@ -30,9 +36,9 @@ loop(int (*callback)(void))
|
|||||||
|
|
||||||
/*! wait until the B button is pressed
|
/*! 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)
|
wait_for_b(void)
|
||||||
{
|
{
|
||||||
#ifdef _3DS
|
#ifdef _3DS
|
||||||
@ -41,12 +47,12 @@ wait_for_b(void)
|
|||||||
|
|
||||||
/* check if B was pressed */
|
/* check if B was pressed */
|
||||||
if(hidKeysDown() & KEY_B)
|
if(hidKeysDown() & KEY_B)
|
||||||
return -1;
|
return LOOP_EXIT;
|
||||||
|
|
||||||
/* B was not pressed */
|
/* B was not pressed */
|
||||||
return 0;
|
return LOOP_CONTINUE;
|
||||||
#else
|
#else
|
||||||
return -1;
|
return LOOP_EXIT;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +67,8 @@ int
|
|||||||
main(int argc,
|
main(int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
|
loop_status_t status = LOOP_RESTART;
|
||||||
|
|
||||||
#ifdef _3DS
|
#ifdef _3DS
|
||||||
/* initialize needed 3DS services */
|
/* initialize needed 3DS services */
|
||||||
acInit();
|
acInit();
|
||||||
@ -73,14 +81,17 @@ main(int argc,
|
|||||||
console_init();
|
console_init();
|
||||||
console_set_status("\n" GREEN STATUS_STRING RESET);
|
console_set_status("\n" GREEN STATUS_STRING RESET);
|
||||||
|
|
||||||
/* initialize ftp subsystem */
|
while(status == LOOP_RESTART)
|
||||||
if(ftp_init() == 0)
|
|
||||||
{
|
{
|
||||||
/* ftp loop */
|
/* initialize ftp subsystem */
|
||||||
loop(ftp_loop);
|
if(ftp_init() == 0)
|
||||||
|
{
|
||||||
|
/* ftp loop */
|
||||||
|
status = loop(ftp_loop);
|
||||||
|
|
||||||
/* done with ftp */
|
/* done with ftp */
|
||||||
ftp_exit();
|
ftp_exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console_print("Press B to exit\n");
|
console_print("Press B to exit\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user