bool InitializeNetwork(bool silent) { #ifdef HW_RVL StopNetworkThread(); if(networkInit && net_gethostip() > 0) return true; networkInit = false; #else if(networkInit) return true; #endif int retry = 1; while(retry) { ShowAction("Initializing network..."); #ifdef HW_RVL u64 start = gettime(); StartNetworkThread(); while (!LWP_ThreadIsSuspended(networkthread)) { usleep(50 * 1000); if(diff_sec(start, gettime()) > 10) // wait for 10 seconds max for net init break; } #else networkInit = !(if_config(wiiIP, NULL, NULL, true) < 0); #endif CancelAction(); if(networkInit || silent) break; retry = ErrorPromptRetry("Unable to initialize network!"); #ifdef HW_RVL if(networkInit && net_gethostip() > 0) #else if(networkInit) #endif return true; } return networkInit; }
/**************************************************************************** * InitializeNetwork * Initializes the Wii/GameCube network interface ***************************************************************************/ bool InitializeNetwork(bool silent) { StopNetworkThread(); if(networkInit && net_gethostip() > 0) return true; networkInit = false; int retry = 1; while(retry) { ShowAction("Initializing network..."); u64 start = gettime(); StartNetworkThread(); while (!LWP_ThreadIsSuspended(networkthread)) { usleep(50 * 1000); if(diff_sec(start, gettime()) > 10) // wait for 10 seconds max for net init break; } CancelAction(); if(networkInit || silent) break; retry = ErrorPromptRetry("Unable to initialize network!"); if(networkInit && net_gethostip() > 0) return true; } return networkInit; }
void initialise_network() { printf("Waiting for network to initialise...\n"); s32 result = -1; while (!check_reset_synchronous() && result < 0) { net_deinit(); while (!check_reset_synchronous() && (result = net_init()) == -EAGAIN); if (result < 0) printf("net_init() failed: [%i] %s, retrying...\n", result, strerror(-result)); } if (result >= 0) { u32 ip = 0; do { ip = net_gethostip(); if (!ip) printf("net_gethostip() failed, retrying...\n"); } while (!check_reset_synchronous() && !ip); if (ip) { struct in_addr addr; addr.s_addr = ip; printf("Network initialised. Wii IP address: %s\n", inet_ntoa(addr)); } } }
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; }