Beispiel #1
0
void listener_thread(void *unused)
{
    struct sockaddr_in sa;
    memset(&sa, 0, sizeof(sa));

    sa.sin_family = AF_INET;
    sa.sin_port = htons(ftp_port);
    sa.sin_addr.s_addr = htonl(INADDR_ANY);

    int list_s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

    if(bind(list_s, (struct sockaddr *)&sa, sizeof(sa)) == -1
    || listen(list_s, OFTP_LISTEN_BACKLOG) == -1)
    {
        appstate = 1;
    }

    int conn_s;
    sys_ppu_thread_t id;

    while(appstate != 1)
    {
        if((conn_s = accept(list_s, NULL, NULL)) > 0)
        {
            sysThreadCreate(&id, client_thread, (void *)&conn_s, 1337, 0x2000, THREAD_JOINABLE, "client");
            sysThreadYield();
        } else sysUsleep(250000);
    }

    closesocket(list_s);

    sysThreadExit(0);
}
Beispiel #2
0
void listener_thread(void *unused)
{
	sys_ppu_thread_t id; 
	struct sockaddr_in sa;
	memset(&sa, 0, sizeof(sa));
	
	sa.sin_family = AF_INET;
	sa.sin_port = htons(2002);
	sa.sin_addr.s_addr = htonl(INADDR_ANY);
	
	int list_s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	
	// only 1 socket connection is allowed at once
	if(bind(list_s, (struct sockaddr *)&sa, sizeof(sa)) == -1 || listen(list_s, 1) == -1)
	{
	    sysThreadExit(0);
	}
	
	int conn_s;
	
	while (!user_requested_exit())
	{
		if((conn_s = accept(list_s, NULL, NULL)) > 0)
		{
			sysThreadCreate(&id, client_thread, (void *)&conn_s, 1337, 0x2000, 0, "client");
			sysThreadYield();
		}
	}
	
	closesocket(list_s);
	
	sysThreadExit(0);
}
Beispiel #3
0
/*
 * This has to be cancellable, so we can't just call sceKernelWaitThreadEnd.
 * Instead, poll on this in a loop, like we do for a cancellable semaphore.
 */
pte_osResult pte_osThreadWaitForEnd(pte_osThreadHandle threadHandle)
{
    pte_osResult osResult;
    psl1ghtThreadData *pThreadData;
    u64 result;

    pThreadData = getThreadData(threadHandle);

    if (pThreadData == NULL)
    {
        sysThreadJoin (threadHandle, &result);
        osResult = PTE_OS_OK;
    }
    else
    {
        while (1)
        {
            if (pThreadData->ended == 1)
            {
                /* Thread has ended */
                osResult = PTE_OS_OK;
                break;
            }
            else
            {
                s32 count;

                if (sysSemGetValue (pThreadData->cancelSem, &count) == 0)
                {
                    if (count > 0)
                    {
                        osResult = PTE_OS_INTERRUPTED;
                        break;
                    }
                    else
                    {
                        /* Nothing found and not timed out yet; let's yield so we're not
                         * in busy loop.
                         */
                        sysThreadYield ();
                    }
                }
                else
                {
                    osResult = PTE_OS_GENERAL_FAILURE;
                    break;
                }
            }
        }
    }


    return osResult;
}
Beispiel #4
0
static void thread_start(void *arg)
{
	s32 running = 0;
	sys_ppu_thread_t id;
	sys_ppu_thread_stack_t stackinfo;

	sysThreadGetId(&id);
	sysThreadGetStackInformation(&stackinfo);

	printf("stack\naddr: %p, size: %d\n",stackinfo.addr,stackinfo.size);
	while(running<5) {
		printf("Thread: %08llX\n",(unsigned long long int)id);

		sysThreadYield();
		sleep(2);
		running++;
	}

	sysThreadExit(0);
}
Beispiel #5
0
/*
 * Pend on a semaphore- and allow the pend to be cancelled.
 *
 * PS3 OS provides no functionality to asynchronously interrupt a blocked call.  We simulte
 * this by polling on the main semaphore and the cancellation semaphore and sleeping in a loop.
 */
pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, unsigned int *pTimeout)
{
    psl1ghtThreadData *pThreadData;
    sys_ppu_thread_t threadId;

    sysThreadGetId (&threadId);
    pThreadData = getThreadData(threadId);

    clock_t start_time;
    s32 result =  0;
    u64 timeout;
    unsigned char timeoutEnabled;

    start_time = clock();

    // clock() is in microseconds, timeout as passed in was in milliseconds
    if (pTimeout == NULL)
    {
        timeout = 0;
        timeoutEnabled = 0;
    }
    else
    {
        timeout = *pTimeout * 1000;
        timeoutEnabled = 1;
    }

    while (1)
    {
        int status;

        /* Poll semaphore */
        status = sysSemTryWait(semHandle);

        if (status == 0)
        {
            /* User semaphore posted to */
            result = PTE_OS_OK;
            break;
        }
        else if ((timeoutEnabled) && ((clock() - start_time) > timeout))
        {
            /* Timeout expired */
            result = PTE_OS_TIMEOUT;
            break;
        }
        else
        {

            if (pThreadData != NULL)
            {
                s32 count;
                s32 osResult;

                osResult = sysSemGetValue (pThreadData->cancelSem, &count);

                if (osResult == 0)
                {
                    if (count > 0)
                    {
                        result = PTE_OS_INTERRUPTED;
                        break;
                    }
                    else
                    {
                        /* Nothing found and not timed out yet; let's yield so we're not
                         * in busy loop.
                         */
                        sysThreadYield ();
                    }
                }
                else
                {
                    result = PTE_OS_GENERAL_FAILURE;
                    break;
                }
            }
        }
    }

    return result;
}