freem(data); clean_exit(1);
clean_exit(0);
THREADFUNC(irc_sockeventloop) {    char *data;    int i = 0;    char finished = 0;    fd_set const_read, const_error;    fd_set event_read, event_error;        FD_ZERO(&const_read);    FD_ZERO(&const_error);    FD_SET(bot.sock, &const_read);    FD_SET(bot.sock, &const_error);        data = (char*)callocm(MAX_LEN, sizeof(char));    if(data == NULL)        return 0;        bot.connected = 1;    bot.current_try = 0;    irc_start(1);        while(!finished) {        event_read = const_read;        event_error = const_error;        if(select(bot.sock+1, &event_read, NULL, &event_error, 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 if(i == -1) {                    make_error("Failed to allocate memory for recieved data.");                }            }            if(FD_ISSET(bot.sock, &event_error)) {                /* 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);                    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");                }                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;}