diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-09 22:35:04 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-02-09 22:35:04 +0000 |
| commit | 31f0e727dfee03dd1cea50afd8f1d966fa714650 (patch) | |
| tree | 3721a621bfa5c0bbc28cd95bd0052591092ea80e | |
| parent | c069f03a8e6e93f3e16b236990c4893a9d9d2bf8 (diff) | |
| download | btpd-31f0e727dfee03dd1cea50afd8f1d966fa714650.tar.gz btpd-31f0e727dfee03dd1cea50afd8f1d966fa714650.zip | |
Add torrent_name function and use it.
| -rw-r--r-- | btpd/content.c | 13 | ||||
| -rw-r--r-- | btpd/torrent.c | 11 | ||||
| -rw-r--r-- | btpd/torrent.h | 1 | ||||
| -rw-r--r-- | btpd/tracker_req.c | 8 |
4 files changed, 20 insertions, 13 deletions
diff --git a/btpd/content.c b/btpd/content.c index 10c3181..d60d09e 100644 --- a/btpd/content.c +++ b/btpd/content.c @@ -183,12 +183,11 @@ cm_save(struct torrent *tp) static void cm_write_done(struct torrent *tp) { - int err; struct content *cm = tp->cm; - if ((err = bts_close(cm->wrs)) != 0) - btpd_err("Error closing write stream for %s (%s).\n", tp->relpath, - strerror(err)); + if ((errno = bts_close(cm->wrs)) != 0) + btpd_err("Error closing write stream for '%s' (%s).\n", + torrent_name(tp), strerror(errno)); cm->wrs = NULL; event_del(&cm->save_timer); cm_save(tp); @@ -243,7 +242,7 @@ cm_td_cb(void *arg) struct content *cm = tp->cm; if (op->error) - btpd_err("IO error for %s.\n", tp->relpath); + btpd_err("IO error for '%s'.\n", torrent_name(tp)); switch (op->type) { case CM_ALLOC: @@ -255,8 +254,8 @@ cm_td_cb(void *arg) assert(!op->u.start.cancel); if (!cm_full(tp)) { if ((err = bts_open(&cm->wrs, &tp->meta, fd_cb_wr, tp)) != 0) - btpd_err("Couldn't open write stream for %s (%s).\n", - tp->relpath, strerror(err)); + btpd_err("Couldn't open write stream for '%s' (%s).\n", + torrent_name(tp), strerror(err)); event_add(&cm->save_timer, SAVE_INTERVAL); } torrent_on_cm_started(tp); diff --git a/btpd/torrent.c b/btpd/torrent.c index 500c66a..4d40c3d 100644 --- a/btpd/torrent.c +++ b/btpd/torrent.c @@ -43,6 +43,12 @@ torrent_get(const uint8_t *hash) return tp; } +const char * +torrent_name(struct torrent *tp) +{ + return tp->meta.name; +} + off_t torrent_piece_size(struct torrent *tp, uint32_t index) { @@ -120,13 +126,12 @@ torrent_start(const uint8_t *hash) return error; } - btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", mi->name); - tp = btpd_calloc(1, sizeof(*tp)); bcopy(relpath, tp->relpath, RELPATH_SIZE); tp->meta = *mi; free(mi); + btpd_log(BTPD_L_BTPD, "Starting torrent '%s'.\n", torrent_name(tp)); if ((error = tr_create(tp)) == 0) { net_create(tp); cm_create(tp); @@ -161,7 +166,7 @@ torrent_stop(struct torrent *tp) static void torrent_kill(struct torrent *tp) { - btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", tp->meta.name); + btpd_log(BTPD_L_BTPD, "Removed torrent '%s'.\n", torrent_name(tp)); assert(m_ntorrents > 0); m_ntorrents--; BTPDQ_REMOVE(&m_torrents, tp, entry); diff --git a/btpd/torrent.h b/btpd/torrent.h index c9a942b..2b1cf19 100644 --- a/btpd/torrent.h +++ b/btpd/torrent.h @@ -38,6 +38,7 @@ off_t torrent_piece_size(struct torrent *tp, uint32_t piece); uint32_t torrent_piece_blocks(struct torrent *tp, uint32_t piece); uint32_t torrent_block_size(struct torrent *tp, uint32_t piece, uint32_t nblocks, uint32_t block); +const char *torrent_name(struct torrent *tp); void torrent_on_cm_stopped(struct torrent *tp); void torrent_on_cm_started(struct torrent *tp); diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c index 155a03c..8d6018b 100644 --- a/btpd/tracker_req.c +++ b/btpd/tracker_req.c @@ -77,7 +77,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse) goto bad_data; if ((buf = benc_dget_mem(content, "failure reason", &len)) != NULL) { - btpd_log(BTPD_L_ERROR, "Tracker failure: %.*s.\n", (int)len, buf); + btpd_log(BTPD_L_ERROR, "Tracker failure: '%.*s' for '%s'.\n", + (int)len, buf, torrent_name(tp)); return 1; } @@ -109,7 +110,8 @@ parse_reply(struct torrent *tp, const char *content, size_t size, int parse) return 0; bad_data: - btpd_log(BTPD_L_ERROR, "Bad data from tracker.\n"); + btpd_log(BTPD_L_ERROR, "Bad data from tracker for '%s'.\n", + torrent_name(tp)); return 1; } @@ -155,7 +157,7 @@ timer_cb(int fd, short type, void *arg) switch (tr->ttype) { case TIMER_TIMEOUT: btpd_log(BTPD_L_ERROR, "Tracker request timed out for '%s'.\n", - tp->meta.name); + torrent_name(tp)); tr->nerrors++; if (tr->event == TR_EV_STOPPED && tr->nerrors >= 5) { tr_set_stopped(tp); |