about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-07-21 09:56:30 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-07-21 09:56:30 +0000
commited56df9e56228b22b4b99ab3a52059d9fbef8e43 (patch)
tree4678a45bfac7bf0c492d79082af1d9abaa71729c
parent368bafd8a65b626031e6ef055bb8b492f77f31c6 (diff)
downloadbtpd-ed56df9e56228b22b4b99ab3a52059d9fbef8e43.tar.gz
btpd-ed56df9e56228b22b4b99ab3a52059d9fbef8e43.zip
Use the new functions btpd_ev_(add|del) instead of calling event_(add|del)
directly. Failure to add or delete an event is treated as a fatal error.

-rw-r--r--btpd/btpd.c6
-rw-r--r--btpd/btpd.h4
-rw-r--r--btpd/cli_if.c6
-rw-r--r--btpd/content.c6
-rw-r--r--btpd/net.c12
-rw-r--r--btpd/peer.c10
-rw-r--r--btpd/tracker_req.c10
-rw-r--r--btpd/upload.c4
-rw-r--r--btpd/util.c15
9 files changed, 45 insertions, 28 deletions
diff --git a/btpd/btpd.c b/btpd/btpd.c
index ccc2e20..4345303 100644
--- a/btpd/btpd.c
+++ b/btpd/btpd.c
@@ -169,7 +169,7 @@ td_init(void)
         btpd_err("Couldn't create mutex (%s).\n", strerror(err));
 
     event_set(&m_td_ev, m_td_rd, EV_READ|EV_PERSIST, td_cb, NULL);
-    event_add(&m_td_ev, NULL);
+    btpd_ev_add(&m_td_ev, NULL);
 }
 
 void ipc_init(void);
@@ -193,7 +193,7 @@ btpd_init(void)
     signal(SIGPIPE, SIG_IGN);
 
     signal_set(&m_sigint, SIGINT, signal_cb, NULL);
-    signal_add(&m_sigint, NULL);
+    btpd_ev_add(&m_sigint, NULL);
     signal_set(&m_sigterm, SIGTERM, signal_cb, NULL);
-    signal_add(&m_sigterm, NULL);
+    btpd_ev_add(&m_sigterm, NULL);
 }
diff --git a/btpd/btpd.h b/btpd/btpd.h
index c567c4e..9c64b51 100644
--- a/btpd/btpd.h
+++ b/btpd/btpd.h
@@ -42,12 +42,14 @@
 void btpd_init(void);
 
 void btpd_log(uint32_t type, const char *fmt, ...);
-
 void btpd_err(const char *fmt, ...);
 
 void *btpd_malloc(size_t size);
 void *btpd_calloc(size_t nmemb, size_t size);
 
+void btpd_ev_add(struct event *ev, struct timeval *tv);
+void btpd_ev_del(struct event *ev);
+
 void btpd_shutdown(int grace_seconds);
 int btpd_is_stopping(void);
 
diff --git a/btpd/cli_if.c b/btpd/cli_if.c
index 71e9ca2..017a386 100644
--- a/btpd/cli_if.c
+++ b/btpd/cli_if.c
@@ -221,7 +221,7 @@ cli_read_cb(int sd, short type, void *arg)
         goto error;
 
     free(msg);
-    event_add(&cli->read, NULL);
+    btpd_ev_add(&cli->read, NULL);
     return;
 
 error:
@@ -249,7 +249,7 @@ client_connection_cb(int sd, short type, void *arg)
     struct cli *cli = btpd_calloc(1, sizeof(*cli));
     cli->sd = nsd;
     event_set(&cli->read, cli->sd, EV_READ, cli_read_cb, cli);
-    event_add(&cli->read, NULL);
+    btpd_ev_add(&cli->read, NULL);
 }
 
 void
@@ -281,5 +281,5 @@ ipc_init(void)
 
     event_set(&m_cli_incoming, sd, EV_READ | EV_PERSIST,
         client_connection_cb, NULL);
-    event_add(&m_cli_incoming, NULL);
+    btpd_ev_add(&m_cli_incoming, NULL);
 }
diff --git a/btpd/content.c b/btpd/content.c
index 9521610..31c526b 100644
--- a/btpd/content.c
+++ b/btpd/content.c
@@ -191,7 +191,7 @@ cm_write_done(struct torrent *tp)
         btpd_err("Error closing write stream for '%s' (%s).\n",
             torrent_name(tp), strerror(errno));
     cm->wrs = NULL;
-    event_del(&cm->save_timer);
+    btpd_ev_del(&cm->save_timer);
     cm_save(tp);
 }
 
@@ -231,7 +231,7 @@ static void
 save_timer_cb(int fd, short type, void *arg)
 {
     struct torrent *tp = arg;
-    event_add(&tp->cm->save_timer, SAVE_INTERVAL);
+    btpd_ev_add(&tp->cm->save_timer, SAVE_INTERVAL);
     cm_save(tp);
 }
 
@@ -258,7 +258,7 @@ cm_td_cb(void *arg)
                 if ((err = bts_open(&cm->wrs, &tp->meta, fd_cb_wr, tp)) != 0)
                     btpd_err("Couldn't open write stream for '%s' (%s).\n",
                         torrent_name(tp), strerror(err));
-                event_add(&cm->save_timer, SAVE_INTERVAL);
+                btpd_ev_add(&cm->save_timer, SAVE_INTERVAL);
             }
             torrent_on_cm_started(tp);
         }
diff --git a/btpd/net.c b/btpd/net.c
index 0c63776..66130b0 100644
--- a/btpd/net.c
+++ b/btpd/net.c
@@ -178,7 +178,7 @@ net_write(struct peer *p, unsigned long wmax)
     nwritten = writev(p->sd, iov, niov);
     if (nwritten < 0) {
         if (errno == EAGAIN) {
-            event_add(&p->out_ev, WRITE_TIMEOUT);
+            btpd_ev_add(&p->out_ev, WRITE_TIMEOUT);
             return 0;
         } else {
             btpd_log(BTPD_L_CONN, "write error: %s\n", strerror(errno));
@@ -218,7 +218,7 @@ net_write(struct peer *p, unsigned long wmax)
         }
     }
     if (!BTPDQ_EMPTY(&p->outq))
-        event_add(&p->out_ev, WRITE_TIMEOUT);
+        btpd_ev_add(&p->out_ev, WRITE_TIMEOUT);
 
     return nwritten;
 }
@@ -458,7 +458,7 @@ net_read(struct peer *p, unsigned long rmax)
     }
 
 out:
-    event_add(&p->in_ev, NULL);
+    btpd_ev_add(&p->in_ev, NULL);
     return nread > 0 ? nread : 0;
 }
 
@@ -575,7 +575,7 @@ net_bw_cb(int sd, short type, void *arg)
 {
     struct peer *p;
 
-    evtimer_add(&m_bw_timer, (& (struct timeval) { 1, 0 }));
+    btpd_ev_add(&m_bw_timer, (& (struct timeval) { 1, 0 }));
 
     compute_rates();
 
@@ -671,8 +671,8 @@ net_init(void)
 
     event_set(&m_net_incoming, sd, EV_READ | EV_PERSIST,
         net_connection_cb, NULL);
-    event_add(&m_net_incoming, NULL);
+    btpd_ev_add(&m_net_incoming, NULL);
 
     evtimer_set(&m_bw_timer, net_bw_cb, NULL);
-    evtimer_add(&m_bw_timer, (& (struct timeval) { 1, 0 }));
+    btpd_ev_add(&m_bw_timer, (& (struct timeval) { 1, 0 }));
 }
diff --git a/btpd/peer.c b/btpd/peer.c
index c8716a1..283200f 100644
--- a/btpd/peer.c
+++ b/btpd/peer.c
@@ -31,8 +31,8 @@ peer_kill(struct peer *p)
         BTPDQ_REMOVE(&net_bw_writeq, p, wq_entry);
 
     close(p->sd);
-    event_del(&p->in_ev);
-    event_del(&p->out_ev);
+    btpd_ev_del(&p->in_ev);
+    btpd_ev_del(&p->out_ev);
 
     nl = BTPDQ_FIRST(&p->outq);
     while (nl != NULL) {
@@ -66,7 +66,7 @@ peer_send(struct peer *p, struct net_buf *nb)
 
     if (BTPDQ_EMPTY(&p->outq)) {
         assert(p->outq_off == 0);
-        event_add(&p->out_ev, WRITE_TIMEOUT);
+        btpd_ev_add(&p->out_ev, WRITE_TIMEOUT);
     }
     BTPDQ_INSERT_TAIL(&p->outq, nl, entry);
 }
@@ -94,7 +94,7 @@ peer_unsend(struct peer *p, struct nb_link *nl)
                 BTPDQ_REMOVE(&net_bw_writeq, p, wq_entry);
                 p->flags &= ~PF_ON_WRITEQ;
             } else
-                event_del(&p->out_ev);
+                btpd_ev_del(&p->out_ev);
         }
         return 1;
     } else
@@ -270,7 +270,7 @@ peer_create_common(int sd)
 
     event_set(&p->out_ev, p->sd, EV_WRITE, net_write_cb, p);
     event_set(&p->in_ev, p->sd, EV_READ, net_read_cb, p);
-    event_add(&p->in_ev, NULL);
+    btpd_ev_add(&p->in_ev, NULL);
 
     BTPDQ_INSERT_TAIL(&net_unattached, p, p_entry);
     net_npeers++;
diff --git a/btpd/tracker_req.c b/btpd/tracker_req.c
index e55e0ed..8945a11 100644
--- a/btpd/tracker_req.c
+++ b/btpd/tracker_req.c
@@ -119,7 +119,7 @@ static void
 tr_set_stopped(struct torrent *tp)
 {
     struct tracker *tr = tp->tr;
-    event_del(&tr->timer);
+    btpd_ev_del(&tr->timer);
     tr->ttype = TIMER_NONE;
     if (tr->req != NULL) {
         http_cancel(tr->req);
@@ -139,14 +139,14 @@ http_cb(struct http *req, struct http_res *res, void *arg)
             tr->event != TR_EV_STOPPED) == 0) {
         tr->nerrors = 0;
         tr->ttype = TIMER_INTERVAL;
-        event_add(&tr->timer, (& (struct timeval) { tr->interval, 0 }));
+        btpd_ev_add(&tr->timer, (& (struct timeval) { tr->interval, 0 }));
     } else {
         if (res->res == HRES_FAIL)
             btpd_log(BTPD_L_BTPD, "Tracker request for '%s' failed (%s).\n",
                 torrent_name(tp), res->errmsg);
         tr->nerrors++;
         tr->ttype = TIMER_RETRY;
-        event_add(&tr->timer, RETRY_WAIT);
+        btpd_ev_add(&tr->timer, RETRY_WAIT);
     }
     if (tr->event == TR_EV_STOPPED && (tr->nerrors == 0 || tr->nerrors >= 5))
         tr_set_stopped(tp);
@@ -188,7 +188,7 @@ tr_send(struct torrent *tp, enum tr_event event)
     if (tr->ttype == TIMER_TIMEOUT)
         http_cancel(tr->req);
     tr->ttype = TIMER_TIMEOUT;
-    event_add(&tr->timer, REQ_TIMEOUT);
+    btpd_ev_add(&tr->timer, REQ_TIMEOUT);
 
     qc = (strchr(tp->meta.announce, '?') == NULL) ? '?' : '&';
 
@@ -225,7 +225,7 @@ tr_kill(struct torrent *tp)
 {
     struct tracker *tr = tp->tr;
     tp->tr = NULL;
-    event_del(&tr->timer);
+    btpd_ev_del(&tr->timer);
     if (tr->req != NULL)
         http_cancel(tr->req);
     free(tr);
diff --git a/btpd/upload.c b/btpd/upload.c
index f7c9866..e2ea30b 100644
--- a/btpd/upload.c
+++ b/btpd/upload.c
@@ -112,7 +112,7 @@ shuffle_optimists(void)
 static void
 choke_cb(int sd, short type, void *arg)
 {
-    evtimer_add(&m_choke_timer, CHOKE_INTERVAL);
+    btpd_ev_add(&m_choke_timer, CHOKE_INTERVAL);
     static int cb_count = 0;
     cb_count++;
     if (cb_count % 3 == 0)
@@ -193,5 +193,5 @@ ul_init(void)
     }
 
     evtimer_set(&m_choke_timer, choke_cb, NULL);
-    evtimer_add(&m_choke_timer, CHOKE_INTERVAL);
+    btpd_ev_add(&m_choke_timer, CHOKE_INTERVAL);
 }
diff --git a/btpd/util.c b/btpd/util.c
index 6a660d8..f667c02 100644
--- a/btpd/util.c
+++ b/btpd/util.c
@@ -1,5 +1,6 @@
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 #include <time.h>
 
 #include "btpd.h"
@@ -22,6 +23,20 @@ btpd_calloc(size_t nmemb, size_t size)
     return a;
 }
 
+void
+btpd_ev_add(struct event *ev, struct timeval *tv)
+{
+    if (event_add(ev, tv) != 0)
+        btpd_err("Failed to add event (%s).\n", strerror(errno));
+}
+
+void
+btpd_ev_del(struct event *ev)
+{
+    if (event_del(ev) != 0)
+        btpd_err("Failed to remove event (%s).\n", strerror(errno));
+}
+
 static const char *
 logtype_str(uint32_t type)
 {