Fix offset after EAGAIN if buffer is locked

This commit is contained in:
ruti 2024-10-18 12:30:15 +03:00
parent a067afe6e4
commit 2240039377
3 changed files with 17 additions and 13 deletions

View File

@ -489,7 +489,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize,
return -1; return -1;
} }
#endif #endif
long lp = offset; long lp = 0;
struct part part; struct part part;
int i = 0, r = 0; 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); pos += part.s * (part.r - r);
if (!(part.flag & OFFSET_START) && offset && pos <= offset) { if (!(part.flag & OFFSET_START) && offset && pos <= offset) {
LOG(LOG_S, "offset: %zd, skip\n", offset);
continue; continue;
} }
if (pos < 0 || pos > n || pos < lp) { if (pos < 0 || pos > n || pos < lp) {

View File

@ -166,6 +166,7 @@ static int reconnect(struct poolhd *pool, struct eval *val, int m)
client->attempt = m; client->attempt = m;
client->cache = 1; client->cache = 1;
client->buff.offset = 0; client->buff.offset = 0;
client->round_sent = 0;
return 0; return 0;
} }
@ -367,7 +368,7 @@ ssize_t tcp_send_hook(struct poolhd *pool, struct eval *remote,
int m = client->attempt; int m = client->attempt;
LOG((m ? LOG_S : LOG_L), "desync params index: %d\n", m); 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; if (!offset && remote->round_count) offset = -1;
sn = desync(remote->fd, buffer, bfsize, n, sn = desync(remote->fd, buffer, bfsize, n,

24
proxy.c
View File

@ -651,13 +651,13 @@ int on_tunnel(struct poolhd *pool, struct eval *val,
ssize_t sn = tcp_send_hook(pool, pair, ssize_t sn = tcp_send_hook(pool, pair,
val->buff.data + val->buff.offset, n, n); val->buff.data + val->buff.offset, n, n);
if (sn < 0) {
uniperror("send");
return -1;
}
val->round_sent += sn;
if (sn < n) { if (sn < n) {
if (sn < 0) { val->buff.offset += sn;
uniperror("send");
return -1;
}
if (sn > 0)
val->buff.offset += sn;
return 0; return 0;
} }
if (!val->buff.locked) { 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); 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 < n) {
if (sn < 0) {
uniperror("send");
return -1;
}
LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd); LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd);
assert(val->buff.locked assert(val->buff.locked
|| !(val->buff.size || val->buff.offset)); || !(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); memcpy(val->buff.data, buffer + sn, n - sn);
} }
else val->buff.offset += sn;
if (mod_etype(pool, val, 0) || if (mod_etype(pool, val, 0) ||
mod_etype(pool, pair, POLLOUT)) { mod_etype(pool, pair, POLLOUT)) {
uniperror("mod_etype"); uniperror("mod_etype");