diff --git a/desync.c b/desync.c index 7eac3f6..0259ba2 100644 --- a/desync.c +++ b/desync.c @@ -489,7 +489,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, return -1; } #endif - long lp = offset; + long lp = 0; struct part part; int i = 0, r = 0; @@ -504,6 +504,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, pos += part.s * (part.r - r); if (!(part.flag & OFFSET_START) && offset && pos <= offset) { + LOG(LOG_S, "offset: %zd, skip\n", offset); continue; } if (pos < 0 || pos > n || pos < lp) { diff --git a/extend.c b/extend.c index a642e92..802ab7a 100644 --- a/extend.c +++ b/extend.c @@ -166,6 +166,7 @@ static int reconnect(struct poolhd *pool, struct eval *val, int m) client->attempt = m; client->cache = 1; client->buff.offset = 0; + client->round_sent = 0; return 0; } @@ -367,7 +368,7 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote, int m = client->attempt; LOG((m ? LOG_S : LOG_L), "desync params index: %d\n", m); - ssize_t offset = client->round_sent + client->buff.offset; + ssize_t offset = client->round_sent; if (!offset && remote->round_count) offset = -1; sn = desync(remote->fd, buffer, bfsize, n, diff --git a/proxy.c b/proxy.c index c61ce50..6e33bdf 100644 --- a/proxy.c +++ b/proxy.c @@ -651,13 +651,13 @@ int on_tunnel(struct poolhd *pool, struct eval *val, ssize_t sn = tcp_send_hook(pool, pair, val->buff.data + val->buff.offset, n, n); + if (sn < 0) { + uniperror("send"); + return -1; + } + val->round_sent += sn; if (sn < n) { - if (sn < 0) { - uniperror("send"); - return -1; - } - if (sn > 0) - val->buff.offset += sn; + val->buff.offset += sn; return 0; } if (!val->buff.locked) { @@ -692,12 +692,12 @@ int on_tunnel(struct poolhd *pool, struct eval *val, } ssize_t sn = tcp_send_hook(pool, pair, buffer, bfsize, n); - val->round_sent += sn > 0 ? sn : 0; + if (sn < 0) { + uniperror("send"); + return -1; + } + val->round_sent += sn; if (sn < n) { - if (sn < 0) { - uniperror("send"); - return -1; - } LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd); assert(val->buff.locked || !(val->buff.size || val->buff.offset)); @@ -710,6 +710,8 @@ int on_tunnel(struct poolhd *pool, struct eval *val, } memcpy(val->buff.data, buffer + sn, n - sn); } + else val->buff.offset += sn; + if (mod_etype(pool, val, 0) || mod_etype(pool, pair, POLLOUT)) { uniperror("mod_etype");