示例#1
0
/**
 * network_deinit:
 *
 * Deinitialize platform specific socket libraries.
 **/
void network_deinit(void)
{
#if defined(_WIN32)
   WSACleanup();
#elif defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
   cellNetCtlTerm();
   sys_net_finalize_network();
   cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
#elif defined(VITA)
   sceNetCtlTerm();
   sceNetTerm();

   if (_net_compat_net_memory)
   {
      free(_net_compat_net_memory);
      _net_compat_net_memory = NULL;
   }
#elif defined(GEKKO) && !defined(HW_DOL)
   net_deinit();
#elif defined(_3DS)
   socExit();
   
   if(_net_compat_net_memory)
   {
	  free(_net_compat_net_memory);
	  _net_compat_net_memory = NULL;
   }
#endif
}
示例#2
0
int socketShutdown(lua_State * L) {
	if (initializeSocket) {
		socExit();
		
		initializeSocket = false;
	}

	return 0;
}
示例#3
0
文件: soc.cpp 项目: Steveice10/citrus
void ctr::soc::exit() {
    if(socBuffer == NULL) {
        return;
    }

    socExit();

    free(socBuffer);
    socBuffer = NULL;
}
示例#4
0
void cleanup() {
    task_quit_all();

    ui_exit();
    screen_exit();

    socExit();
    if(soc_buffer != NULL) {
        free(soc_buffer);
        soc_buffer = NULL;
    }

    amExit();
    httpcExit();
    ptmuExit();
    acExit();
    cfguExit();
    romfsExit();
    gfxExit();
}
示例#5
0
文件: main.c 项目: masterhou/FBI
void cleanup() {
    clipboard_clear();

    task_exit();
    ui_exit();
    screen_exit();

    socExit();
    if(soc_buffer != NULL) {
        free(soc_buffer);
        soc_buffer = NULL;
    }

    amExit();
    httpcExit();
    ptmuExit();
    acExit();
    cfguExit();
    romfsExit();
    gfxExit();
}
示例#6
0
文件: main.c 项目: Jeflux/3DSC
int main(int argc, char **argv) {
	gfxInitDefault();
	socInit((u32 *)memalign(0x1000, 0x100000), 0x100000);

	// Check wifi status
	u32 wifiStatus = 0;
	ACU_GetWifiStatus(&wifiStatus);
	if (!wifiStatus) {
		printf("\x1b[1;1HNo WiFi! Is your wireless slider on?");
	}

	// Use printf on top screen
	consoleInit(GFX_TOP, NULL);

	// Stuff for network magic
	int recvlen;
	unsigned char buf[BUFSIZE];
	unsigned char IDBuf[BUFSIZE];

	// Try create socket
	int err = 0;
	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		err = 1;
	}

	// Setup socket addresses
	out.sin_family = in.sin_family = AF_INET;
	out.sin_port = in.sin_port = htons(PORT); // Set port
	in.sin_addr.s_addr = INADDR_ANY;

	// Try to bind socket to port
	if (err == 0 && bind(sock, (struct sockaddr *)&in, sizeof(in)) < 0)
		err = 2;

	// If any errors
	if (err != 0)
		printf("\x1b[4;1HError opening connection: %i", err);

	// Set socket receive to non-blocking to be able to exit while listening for broadcast
	fcntl(sock, F_SETFL, O_NONBLOCK);


	bool connected = false;

	// Main loop
	while (aptMainLoop()) {

		if (err == 0) {
			// If not connected, listen for broadcast
			if (!connected) {
				printf("\x1b[1;1HListening for broadcast on port %d", PORT);

				// Listen for packets. Returns packet size
				recvlen = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *)&out, &addrlen);

				// Check if correct packet. recvlen < 0 -> Error
				if (recvlen > 0) {
					printf("\x1b[2;1Hr"); // Debug print. Writes r for any packet received
					buf[recvlen] = 0; // Don't remember what this is for. Oops

									  // Check if message is connection port (Broadcast sends out port number as broadcast)
					int i = atoi(buf);
					if (i == PORT) {
						// If broadcast message, assign send address to received address
						in.sin_addr.s_addr = out.sin_addr.s_addr;

						// Prepare program; Setting flag, turning of backlight, etc
						connected = true;
						consoleClear();
						printf("\x1b[1;1HConnected");
						if (backlightOff == false)
							disableBacklight();
						backlightOff = true;
					}
				}
			}
		}

		printf("\x1b[28;1HPlayer ID: %i", playerID);
		printf("\x1b[29;1HPress START and SELECT to exit");

		// Scan input
		hidScanInput();
		// Save keystate
		u32 kDown = hidKeysHeld();

		if ((kDown & KEY_START) && (kDown & KEY_SELECT)) break; // break in order to return to hbmenu

		// If no errors and connected. Contruct input message
		if (err == 0 && connected) {
			// Get circle pad state
			circlePosition pos;
			hidCircleRead(&pos);

			// Construct message
			message.ID = playerID;
			message.pdx = pos.dx;
			message.pdy = pos.dy;
			message.btn = kDown;

			// Query for touchscreen information
			touchPosition touch;
			hidTouchRead(&touch);

			message.touch_px = touch.px;
			message.touch_py = touch.py;

			// Send packet to address broadcast came from
			sendto(sock, &message, sizeof(message), 0, (struct sockaddr *)&in, sizeof(in));

			int recv = 0;
			int count = 0;
			do {
				count++;
				// Send packet to address broadcast came from
				sendto(sock, &message, sizeof(message), 0, (struct sockaddr *)&in, sizeof(in));
				// Listen for packet to get player ID and check if server is alive
				//int recv = read(sock, IDBuf, sizeof(IDBuf));
				recv = recvfrom(sock, IDBuf, BUFSIZE, 0, (struct sockaddr *)&out, &addrlen);
			} while (atoi(IDBuf) == PORT && count < 5);

			if (count < 5 && recv > 0)
				playerID = IDBuf[0] | IDBuf[1] << 1;
			else {
				connected = false;
				playerID = 0;
				consoleClear();
				printf("\x1b[2;1HDisconnected");

				if (backlightOff == true) {
					enableBacklight();
					backlightOff = false;
				}
			}
		}

		u64 sleepDuration = 16000000ULL;
		svcSleepThread(sleepDuration);

		// Draw stuff
		gfxFlushBuffers();
		gfxSwapBuffers();
		gspWaitForVBlank();
	}

	// On exit
	if (backlightOff == true)
		enableBacklight();
	socExit();
	gfxExit();
	return 0;
}
示例#7
0
文件: main.c 项目: phijor/ctroller
int main(int argc, char **argv)
{
    (void) argc, (void) argv;

    Result res = MAKERESULT(RL_SUCCESS, RS_SUCCESS, 0, RD_SUCCESS);

    gfxInitDefault();

    PrintConsole top;
    consoleInit(GFX_TOP, &top);

    util_debug_init();
    consoleSelect(&top);

    if (R_FAILED(res = acInit())) {
        util_presult("acInit failed", res);
        goto ac_failure;
    }

    u32 wifi = 0;
    if (R_FAILED(res = ACU_GetWifiStatus(&wifi))) {
        util_presult("ACU_GetWifiStatus failed", res);
        fprintf(stderr, "Did you enable Wifi?\n");
        goto wifi_check_failure;
    }
    if (!wifi) {
        fprintf(stderr, "Wifi disabled.\n");
        goto wifi_check_failure;
    }

    if ((sock_ctx = memalign(SOCU_BUFSZ, SOCU_ALIGN)) == NULL) {
        util_perror("Allocating SOC buffer");
        res = MAKERESULT(
            RL_PERMANENT, RS_OUTOFRESOURCE, RM_SOC, RD_OUT_OF_MEMORY);
        goto soc_alloc_failure;
    }

    if (R_FAILED(res = socInit(sock_ctx, SOCU_BUFSZ))) {
        util_presult("socInit failed", res);
        goto soc_failure;
    }

    if (R_FAILED(res = hidInit())) {
        util_presult("hidInit failed", res);
        goto hid_failure;
    }
    if (R_FAILED(res = HIDUSER_EnableAccelerometer())) {
        util_presult("Failed to enable accelerometer", res);
        goto accel_failure;
    }

    if (R_FAILED(res = ctrollerInit())) {
        fprintf(stderr, "Do you have a valid IP in\n '" CFG_FILE "'?");
        goto failure;
    }

    bool isHomebrew = envIsHomebrew();
    printf("Press %s to exit.\n", isHomebrew ? EXIT_DESC : "HOME");
    fflush(stdout);

    while (aptMainLoop()) {

        if (isHomebrew) {
            if (hidKeysHeld() == EXIT_KEYS) {
                res = RL_SUCCESS;
                break;
            }
        }

        if (ctrollerSendHIDInfo()) {
            util_perror("Sending HID info");
            fflush(stderr);
            for (int i = 3; i > 0; i--) {
                util_debug_printf("\rRetrying in %ds... ", i);
                svcSleepThread(1000000000L);
            }
            util_debug_printf("\rRetrying now.\x1b[K\n");
        }

        gspWaitForVBlank();

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    puts("Exiting...");
failure:
    HIDUSER_DisableAccelerometer();
accel_failure:
    hidExit();
hid_failure:
    socExit();
soc_failure:
    free(sock_ctx);
soc_alloc_failure:
wifi_check_failure:
    acExit();
ac_failure:
    if (R_FAILED(res)) {
        util_hang(res);
    }
    gfxExit();
    return res;
}
示例#8
0
文件: main.cpp 项目: lavanoid/CIAngel
int main(int argc, const char* argv[])
{
    /* Sadly svchax crashes too much, so only allow install mode when running as a CIA
    // Trigger svchax so we can install CIAs
    if(argc > 0) {
        svchax_init(true);
        if(!__ctr_svchax || !__ctr_svchax_srv) {
            bSvcHaxAvailable = false;
            //printf("Failed to acquire kernel access. Install mode disabled.\n");
        }
    }
    */
    
    // argc is 0 when running as a CIA, and 1 when running as a 3dsx
    if (argc > 0)
    {
        bSvcHaxAvailable = false;
    }

    u32 *soc_sharedmem, soc_sharedmem_size = 0x100000;
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    httpcInit(0);
    soc_sharedmem = (u32 *)memalign(0x1000, soc_sharedmem_size);
    socInit(soc_sharedmem, soc_sharedmem_size);
    sslcInit(0);
    hidInit();
    acInit();
    cfguInit();

    if (bSvcHaxAvailable)
    {
        amInit();
        AM_InitializeExternalTitleDatabase(false);
    }

    init_menu(GFX_TOP);

    // Make sure all CIAngel directories exists on the SD card
    mkpath("/CIAngel", 0777);
    mkpath("/CIAngel/tmp/", 0777);
    loadConfig();
    
    // Set up the reading of json
    check_JSON();
    load_JSON_data();
    
    menu_main();

    if (bSvcHaxAvailable)
    {
        amExit();
    }

    cfguExit();
    acExit();
    gfxExit();
    hidExit();
    httpcExit();
    socExit();
    sslcExit();
}
示例#9
0
//---------------------------------------------------------------------------------
void socShutdown() {
//---------------------------------------------------------------------------------
	printf("waiting for socExit...\n");
	socExit();

}