Esempio n. 1
0
Torrent *Torrent_new(size_t size, char *path)
{
    Torrent *torrent = malloc(size);
    check_mem(torrent);

    torrent->init = Torrent_init;
    torrent->destroy = Torrent_destroy;
    torrent->print= Torrent_print;

    torrent->parse = Torrent_parse;
    torrent->connect = Torrent_connect;
    torrent->announce = Torrent_announce;
    torrent->add_job = Torrent_add_job;
    torrent->add_piece = Torrent_add_piece;
    torrent->add_file = Torrent_add_file;
    torrent->get_next_piece = Torrent_get_next_piece;
    torrent->piece_finished = Torrent_piece_finished;
    torrent->piece_failed = Torrent_piece_failed;

    if(torrent->init(torrent, path) == EXIT_FAILURE) {
        throw("torrent init failed");
    } else {
        // all done, we made an object of any type
        return torrent;
    }

error:
    if(torrent) { torrent->destroy(torrent); };
    return NULL;
}