diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2005-10-06 08:16:43 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2005-10-06 08:16:43 +0000 |
| commit | 28fcbed3c5e917a42883412ebbb5a6600a7f40b8 (patch) | |
| tree | 48b9a6cc670418d9b8113eef921d0336ac5635ab | |
| parent | 2dc98c39b6034f11daafa74d92d86fd5e6beeb12 (diff) | |
| download | btpd-28fcbed3c5e917a42883412ebbb5a6600a7f40b8.tar.gz btpd-28fcbed3c5e917a42883412ebbb5a6600a7f40b8.zip | |
#include <limits.h> to be sure to get IOV_MAX.
Use the net_state enum and change some state names from NET_ to BTP_. Some minor type fixes.
| -rw-r--r-- | btpd/btpd.h | 1 | ||||
| -rw-r--r-- | btpd/net.c | 26 | ||||
| -rw-r--r-- | btpd/net.h | 10 | ||||
| -rw-r--r-- | btpd/peer.h | 2 |
4 files changed, 18 insertions, 21 deletions
diff --git a/btpd/btpd.h b/btpd/btpd.h index ef073a5..1a5c357 100644 --- a/btpd/btpd.h +++ b/btpd/btpd.h @@ -9,6 +9,7 @@ #include <errno.h> #include <event.h> #include <inttypes.h> +#include <limits.h> #include <stddef.h> #include <stdlib.h> diff --git a/btpd/net.c b/btpd/net.c index b6e47b8..5a47be6 100644 --- a/btpd/net.c +++ b/btpd/net.c @@ -18,10 +18,6 @@ #include "btpd.h" -#ifndef IOV_MAX -#define IOV_MAX 1024 -#endif - #define min(x, y) ((x) <= (y) ? (x) : (y)) void @@ -117,7 +113,7 @@ net_write(struct peer *p, unsigned long wmax) } void -net_set_state(struct peer *p, int state, size_t size) +net_set_state(struct peer *p, enum net_state state, size_t size) { p->net.state = state; p->net.st_bytes = size; @@ -213,7 +209,7 @@ net_mh_ok(struct peer *p) static void net_progress(struct peer *p, size_t length) { - if (p->net.state == NET_MSGBODY && p->net.msg_num == MSG_PIECE) { + if (p->net.state == BTP_MSGBODY && p->net.msg_num == MSG_PIECE) { p->tp->downloaded += length; p->rate_to_me[btpd.seconds % RATEHISTORY] += length; } @@ -245,28 +241,28 @@ net_state(struct peer *p, const char *buf) goto bad; bcopy(buf, p->id, 20); peer_on_shake(p); - net_set_state(p, NET_MSGSIZE, 4); + net_set_state(p, BTP_MSGSIZE, 4); break; - case NET_MSGSIZE: + case BTP_MSGSIZE: p->net.msg_len = net_read32(buf); if (p->net.msg_len != 0) - net_set_state(p, NET_MSGHEAD, 1); + net_set_state(p, BTP_MSGHEAD, 1); break; - case NET_MSGHEAD: + case BTP_MSGHEAD: p->net.msg_num = buf[0]; if (!net_mh_ok(p)) goto bad; else if (p->net.msg_len == 1) { if (net_dispatch_msg(p, buf) != 0) goto bad; - net_set_state(p, NET_MSGSIZE, 4); + net_set_state(p, BTP_MSGSIZE, 4); } else - net_set_state(p, NET_MSGBODY, p->net.msg_len - 1); + net_set_state(p, BTP_MSGBODY, p->net.msg_len - 1); break; - case NET_MSGBODY: + case BTP_MSGBODY: if (net_dispatch_msg(p, buf) != 0) goto bad; - net_set_state(p, NET_MSGSIZE, 4); + net_set_state(p, BTP_MSGSIZE, 4); break; default: abort(); @@ -332,7 +328,7 @@ net_read(struct peer *p, unsigned long rmax) iov[1].iov_len = nread - rest; while (p->net.st_bytes <= iov[1].iov_len) { - ssize_t consumed = p->net.st_bytes; + size_t consumed = p->net.st_bytes; net_progress(p, consumed); if (net_state(p, iov[1].iov_base) != 0) return nread; diff --git a/btpd/net.h b/btpd/net.h index e9f563c..4f77900 100644 --- a/btpd/net.h +++ b/btpd/net.h @@ -15,16 +15,16 @@ #define SHAKE_LEN 68 -enum shake_state { +enum net_state { SHAKE_PSTR, SHAKE_INFO, SHAKE_ID, - NET_MSGSIZE, - NET_MSGHEAD, - NET_MSGBODY + BTP_MSGSIZE, + BTP_MSGHEAD, + BTP_MSGBODY }; -void net_set_state(struct peer *p, int state, size_t size); +void net_set_state(struct peer *p, enum net_state state, size_t size); void net_connection_cb(int sd, short type, void *arg); void net_bw_rate(void); diff --git a/btpd/peer.h b/btpd/peer.h index 4bf046b..16e7747 100644 --- a/btpd/peer.h +++ b/btpd/peer.h @@ -52,7 +52,7 @@ struct peer { struct { uint32_t msg_len; uint8_t msg_num; - uint8_t state; + enum net_state state; size_t st_bytes; char *buf; size_t off; |