Exemplo n.º 1
0
int JNetwork::connect(const string& serverIP) {
#ifdef NETWORK_SUPPORT
    int err;
    char buffer[4096];
    if(netthread) return 0;


    sceUtilityLoadNetModule(1);
    sceUtilityLoadNetModule(3);

    if((err = pspSdkInetInit())) {
        sprintf(buffer, "JGE Error, could not initialise the network %08X", err);
        printf(buffer);
        printf("\n");
        error = buffer;
        return err;
    }

    if(JNetwork::connect_to_apctl(1)) {
        JNetwork::serverIP = serverIP;
        /* Create a user thread to do the real work */
        netthread = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);

        if(netthread < 0)
        {
            printf("Error, could not create thread\n");
            sceKernelSleepThread();
        }

        sceKernelStartThread(netthread, 0, NULL);
        return netthread;
    }
#endif
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    #ifdef X_MODULE_WIFI
    pspSdkLoadInetModules();
    pspSdkInetInit();
    #endif
    #ifdef X_MODULE_MP3
    //Reserved
    #endif
    xSetupCallbacks();
    int user_thid = sceKernelCreateThread("xUserThread", xUserThread, 0x18, 0x10000, PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU, 0);
    if (user_thid >= 0) sceKernelStartThread(user_thid, 0, 0);
    sceKernelExitDeleteThread(0);
    return 0;
}
Exemplo n.º 3
0
int CSocket::socketSystemInit()
{
//	errorOut("debuglog.txt", ":: Initializing socket system...");
#if defined(_WIN32) || defined(_WIN64)
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	wVersionRequested = MAKEWORD(2, 2);

	err = WSAStartup(wVersionRequested, &wsaData);
	if (err != 0)
	{
		SLOG("Failed to initialize winsocks!\n");
		return 1;
	}

	if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
	{
		SLOG("Failed to initialize winsocks!  Wasn't version 2.2!\n");
		WSACleanup();
		return 1;
	}
#elif defined(PSPSDK)
	if (sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON) < 0)
		return -1;
	if (sceUtilityLoadNetModule(PSP_NET_MODULE_INET) < 0)
		return -1;
	if (pspSdkInetInit() != 0)
		return -2; // false
	if (sceNetApctlConnect(1) != 0)
		return -3;

	while (true)
	{
		int state = 0;
		if (sceNetApctlGetState(&state) != 0)
			return -3;
		if (state == 4)
			break;

		sceKernelDelayThread(1000 * 50); // 50ms
	}
#endif

	CSocket::was_initiated = 1;
	return 0;
}
Exemplo n.º 4
0
static void* xpnet_cb_thread(void* argp)
{
	XPNETCTX*	pxpnctx = (XPNETCTX*)argp;
#endif	//XTPF_Linux
#ifdef	XTPF_PSP
static xjse_int_t xpnet_cb_thread(SceSize args, void* argp)
{
	XPNETCTX*	pxpnctx = *((XPNETCTX**)argp);
#endif	//XTPF_PSP
	xjse_result_t	xr1;
	xjse_int_t		i;
	xjse_time_t		tnow;
	XJSE_TRACE("(*) XXXX xpnet thread started. thread id: (%d, %p)",
		(xjse_int_t)pxpnctx->threadid, pxpnctx);

	if((pxpnctx->flags & XPNETFLAG_INITDONE) == 0) {
#if	XTPF_PSP
		int	nsceerr = pspSdkInetInit();
		if(nsceerr != 0) {
			XJSE_TRACE("(E) pspSdkInetInit() failed! (%d)", nsceerr);
			goto	failed;
		}
#endif
	}
	pxpnctx->flags |= XPNETFLAG_INITDONE;

//pxpnctx->flags |= XPNETFLAG_INITCONN;	//TODO: read from .conf (for debug)
	if((pxpnctx->flags & XPNETFLAG_INITCONN) != 0
		&& pxpnctx->nap != 0
		&& pxpnctx->napconstatus == XPNETAPCTLSTAT_NOTCONN) {
		xr1 = xpnet_apctl_connect(pxpnctx);
		if(!XJSE_IS_SUCCESS(xr1))
			goto	failed;
	}

	while(1) {
		for(i = 0; i < XPNETC_NMAXREQQITEMS; i++) {
			XPNETREQQITEM*	pitem = &(pxpnctx->xpnetreqq[i]);
			//XJSE_TRACE("(X) state (%d, %p)[%d]", i, pitem, pitem->state);

			switch(pitem->state) {
			case XPNREQQITEMSTATE_SENDREADY:
//XJSE_TRACE("(X) xxx 1.0 state (%d, %p)[%d]", i, pitem, pitem->state);
				// do apcon if not connected yet
				if(pxpnctx->nap == 0) {
					XJSE_TRACE("(X) http req (%d) is canceled (offline)", i);
					pitem->state = XPNREQQITEMSTATE_EMPTY;
					continue;
				}

				if(pxpnctx->napconstatus == XPNETAPCTLSTAT_NOTCONN) {
					xr1 = xpnet_apctl_connect(pxpnctx);
					if(!XJSE_IS_SUCCESS(xr1))
						goto	failed;
				}
//XJSE_TRACE("(X) xxx 1.1 state (%d, %p)[%d]", i, pitem, pitem->state);
				xr1 = xpnet_pollwait_apcon(pxpnctx);
				if(!XJSE_IS_SUCCESS(xr1))
					goto	failed;

//XJSE_TRACE("(X) xxx 1.2 state (%d, %p)[%d]", i, pitem, pitem->state);
				{	//TODO: critical section
					if(pitem->state == XPNREQQITEMSTATE_OBSOLETED) {
						pitem->state = XPNREQQITEMSTATE_EMPTY;
						continue;
					}
					// (state might be changed until here, by main thread)
//XJSE_TRACE("(X) xxx 2 state (%d, %p)[%d]", i, pitem, pitem->state);
					pitem->state = XPNREQQITEMSTATE_SENT;
				}

				XJSE_XPNET_CALLBACKS	afcbs = {
					xjse_xpnet_cb_header, xjse_xpnet_cb_data,
				};
				xr1 = xjse_xpnet_httprequest(pitem->pszurl, &afcbs, pitem);
				if(!XJSE_IS_SUCCESS(xr1)) {
					XJSE_TRACE("xjse_xpnet_httprequest failed!");
					pitem->state = XPNREQQITEMSTATE_EMPTY;
					goto	failed;
				}
				XPNET_UPDATELASTCOMM(pxpnctx);
				break;
			}
		}

		// wait exit (flag will be set by main thread)
		if((pxpnctx->flags & XPNETFLAG_EXIT) != 0)
			break;

		// apcon timeout? (specified time elapsed after last comm?)
		xjse_time_now(&tnow);
		if(pxpnctx->napconstatus == XPNETAPCTLSTAT_CONNED &&
			pxpnctx->tlastcomm + 5 * 1000 < tnow) {	//TODO: read from .config
			//XJSE_TRACE("(X) apc timed out. going offline... [%d](%lld, %lld)",
			//	pxpnctx->napconstatus, pxpnctx->tlastcomm, tnow);
			XPNET_UPDATELASTCOMM(pxpnctx);
			xr1 = xpnet_apctl_disconnect(pxpnctx);
		}

		xjse_sleep(400);
	}

	XJSE_TRACE("(X) xpnet thread is being shut down...");
	pxpnctx->flags ^= XPNETFLAG_EXIT;	// main thread waits this

failed:
	XJSE_TRACE("(E) xpnet thread is being shut down with error...");

	return	0;
}