finished = 1;
finished++;
THREADFUNC(irc_sockeventloop) {    char *data;    int i = 0;    char finished = 0;    fd_set const_read, event_read;        FD_ZERO(&const_read);    FD_SET(bot.sock, &const_read);        data = (char*)callocm(MAX_LEN, sizeof(char));    if(data == NULL)        return 0;        eventloop_running = 1;    bot.connected = 1;    bot.current_try = 0;    irc_start(1);        while(!finished) {        event_read = const_read;        if(select(bot.sock+1, &event_read, NULL, NULL, NULL)) {            if(FD_ISSET(bot.sock, &event_read)) {                /* We've recieved some data, let's do something with it. */                i = irc_recv(data);                if(i == 1) {                    printf("RECV: %s\n", data);                    if(!irc_parseraw(data))                        make_warning("irc_parseraw failed.");                    clearstr(data, MAX_LEN);                    bot.current_try = 0;                    recieved_ping = 1;                }                else {                    /* We've been disconnected */                    bot.connected = 0;                    if(bot.current_try <= bot.maxretry) {                        bot.current_try++;                        irc_disconnect();                        make_notice("Disconnected. Reconnecting in...");                        for(i = 60;i > 0;i--) {                            printf("%d\n", i);                            waits(1);                        }                        clearstr(data, 513);                        printf("Connecting to %s:%d... ", bot.servaddr, bot.servport);                        eventloop_running = 0;                        if((i = irc_connect(bot.servaddr, bot.servport)) != 0) {                            printf("Failed to connect. ERROR %d:%d\n\n", WSAGetLastError(), i);                            log_write("Connecting failed with code: %d:%d", WSAGetLastError(), i);                            printf("Press Enter key to continue.\n");                            getchar();                            freem(data);                            clean_exit(1);                        }                        printf("Connected.\n");                        finished = 1;                    }                    else {                        freem(data);                        make_notice("The maximum retries have been exhausted, application ending.");                        printf("Press Enter key to continue.");                        getchar();                        clean_exit(0);                    }                }            }        }    }        freem(data);    return 0;}