static void * WiiloadThread(void *arg) { int netInit = 0; int netReady = 0; int wc24cleared = 0; stopNetworkThread = 0; errors = 0; strcpy(wiiload.ip, "<unknown>"); printopt("Net thread running, ready !"); while (!stopNetworkThread) { if (!netInit) { s32 res; res = net_init_async(NULL, NULL); Debug ("net_init_async %d", res); if (res != 0) { errors ++; continue; } netInit = 1; } if (netInit) { if (errors > 5 && !wc24cleared) { Debug ("Cleareing net_wc24cleanup"); net_deinit (); net_wc24cleanup(); errors = 0; netInit = 0; wc24cleared = 1; } s32 res; res = net_get_status(); Debug ("net_get_status %d", res); if (res == 0) { struct in_addr hostip; hostip.s_addr = net_gethostip(); if (hostip.s_addr) { strcpy(wiiload.ip, inet_ntoa(hostip)); netReady = 1; } } else errors ++; } if (netReady) { if (!StartWiiLoadServer ()) errors ++; } sleep (1); if (errors > 10) { Debug ("too many errors"); stopNetworkThread = 1; } } stopNetworkThread = 2; wiiload.status = WIILOAD_STOPPED; net_deinit(); return NULL; }
static void * netcb (void *arg) { s32 res=-1; int retry; int wait; static bool prevInit = false; while(netHalt != 2) { retry = 5; while (retry>0 && (netHalt != 2)) { if(prevInit) { int i; net_deinit(); for(i=0; i < 400 && (netHalt != 2); i++) // 10 seconds to try to reset { res = net_get_status(); if(res != -EBUSY) // trying to init net so we can't kill the net { usleep(2000); net_wc24cleanup(); //kill the net prevInit=false; // net_wc24cleanup is called only once usleep(20000); break; } usleep(20000); } } usleep(2000); res = net_init_async(NULL, NULL); if(res != 0) { sleep(1); retry--; continue; } res = net_get_status(); wait = 400; // only wait 8 sec while (res == -EBUSY && wait > 0 && (netHalt != 2)) { usleep(20000); res = net_get_status(); wait--; } if(res==0) break; retry--; usleep(2000); } if (res == 0) { struct in_addr hostip; hostip.s_addr = net_gethostip(); if (hostip.s_addr) { strcpy(wiiIP, inet_ntoa(hostip)); networkInit = true; prevInit = true; } } if(netHalt != 2) LWP_SuspendThread(networkthread); } return NULL; }