
fn worker(server: Server) {

    // TODO: check max connections
    // let max_connections = server.max_connections
    let sock = server.socket

    let worker = Worker {
        server: server
    }

    while true {

        let netcon = sock.accept() ! {
            if error_is(E, too_many_connections) {
                println("[x] Too many connections")
                continue
            }
            #if TEST
            panic("HTTP Server failed to accept a connection")
            #end
            println("[x] Failed to accept")
            continue
        }

        let fd = netcon.fd
        if server.show_info {
            println("[+] New connection: " + fd)
        }

        let http_con = Connection {
            worker: worker,
            netcon: netcon,
            fd: fd,
        }

        worker.connections++

        co http_con.handle()
    }
}

class Worker {
    server: Server
    connections: uint (0)
}
