Esempio n. 1
0
/* Initialization for data that needs other units */
static void
conn_init1(void)
{
  set_var_str(&conn_unit, "version", rcsid);
  conn_main();
  add_event_handler(CE_DATA, &data_handler, "data_handler", NULL);
  add_event_handler(CE_TIMER, &timer_handler, "timer_handler", NULL);
  Debug_unit(&conn_unit, "Initialized.");
}
Esempio n. 2
0
/*----------------*/
int main(int argc, char *argv[])
{
    APP_STATUS status;

    srvInit();
    aptInit(APPID_APPLICATION);
    gfxInit();
    hidInit(NULL);
    fsInit();

    svcCreateEvent(&new_cmd_event, 0);
    svcCreateEvent(&cmd_done_event, 0);
    svcCreateThread(&thread, cmd_thread_func, 0x0,
                    (u32*)((char*)thread_stack + sizeof(thread_stack)),
                    0x31, 0xfffffffe);

    int where = 0;
    u32 ret = SOC_Initialize((u32*)0x08000000, 0x48000);

    if(ret == 0) {
        listen_socket = socket(AF_INET, SOCK_STREAM, 0);
        if(listen_socket == -1) {
            where = 1;
            ret = SOC_GetErrno();
        }
        else {
            u32 tmp = fcntl(listen_socket, F_GETFL);
            fcntl(listen_socket, F_SETFL, tmp | O_NONBLOCK);

            struct sockaddr_in addr;
            addr.sin_family = AF_INET;
            addr.sin_port = __swap16(PORT);
            addr.sin_addr.s_addr = INADDR_ANY;

            ret = bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr));
            if(ret != 0) {
                where = 2;
                ret = SOC_GetErrno();
            }
            else {
                ret = listen(listen_socket, 1);
                if(ret == -1) {
                    ret = SOC_GetErrno();
                    where = 3;
                }
            }
        }

    }

    u32 it = 0;
    int accept_errno = 0;
    int first = 1;


    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&top);

        print(&top, "newver\n");
        print(&top, "ret: %08x, where: %d\n", ret, where);
        print(&top, "frame: %08x\n", it);
        u32 ip = gethostid();
        print(&top, "ip: %d.%d.%d.%d\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
                
        if(accept_errno != 0) print(&top, "accept returned errno %d\n", accept_errno);

        if(!first) {
            int s = accept(listen_socket, NULL, NULL);
            if(s == -1) {
                int err = SOC_GetErrno();

                if(err != -EWOULDBLOCK)
                    accept_errno = err;
            }
            else {
                sock = s;
                conn_main();
                closesocket(sock);
            }
        }

        it++;
        first = 0;
        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A)
            break;
    }

    thread_exit = 1;
    svcSignalEvent(new_cmd_event);
    svcWaitSynchronization(thread, U64_MAX);
    svcCloseHandle(thread);

    svcCloseHandle(new_cmd_event);
    svcCloseHandle(cmd_done_event);

    SOC_Shutdown();
    fsExit();
    hidExit();
    gfxExit();
    aptExit();
    srvExit();
    return 0;
}