mirror of
https://github.com/omar-polo/gmid.git
synced 2024-09-28 13:31:48 +02:00
put back the missing lseek, and change variables name
(I know, changing variables names AND introducing changes is better done in more commits, but…) Added back an lseek that was missing. If TLS_WANT_POLL{IN,OUT}, we need to re-send that block, but we need also to rewind the file, in order to read(2) that chunk again. This doesn’t solve the corruption in transferring big files, but reduces them. I still haven’t tracked down the corruption :/
This commit is contained in:
parent
cc68fe70fc
commit
09a1b97896
32
gmid.c
32
gmid.c
@ -281,8 +281,8 @@ send_file(char *path, struct pollfd *fds, struct client *client)
|
||||
{
|
||||
char fpath[PATHBUF];
|
||||
char buf[FILEBUF];
|
||||
size_t i;
|
||||
ssize_t t, w;
|
||||
size_t off;
|
||||
ssize_t ret, len;
|
||||
|
||||
if (client->fd == -1) {
|
||||
assert(path != NULL);
|
||||
@ -314,20 +314,18 @@ send_file(char *path, struct pollfd *fds, struct client *client)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
w = read(client->fd, buf, sizeof(buf));
|
||||
if (w == -1)
|
||||
len = read(client->fd, buf, sizeof(buf));
|
||||
if (len == -1)
|
||||
warn("read");
|
||||
if (w == 0 || w == -1) {
|
||||
if (len == 0 || len == -1) {
|
||||
goodbye(fds, client);
|
||||
return;
|
||||
}
|
||||
|
||||
t = w;
|
||||
i = 0;
|
||||
|
||||
while (w > 0) {
|
||||
t = tls_write(client->ctx, buf+i, w);
|
||||
switch (t) {
|
||||
off = 0;
|
||||
while (len > 0) {
|
||||
ret = tls_write(client->ctx, buf+off, len);
|
||||
switch (ret) {
|
||||
case -1:
|
||||
warnx("tls_write: %s", tls_error(client->ctx));
|
||||
goodbye(fds, client);
|
||||
@ -335,14 +333,16 @@ send_file(char *path, struct pollfd *fds, struct client *client)
|
||||
|
||||
case TLS_WANT_POLLIN:
|
||||
case TLS_WANT_POLLOUT:
|
||||
fds->events = (t == TLS_WANT_POLLIN)
|
||||
? POLLIN
|
||||
: POLLOUT;
|
||||
fds->events = ret == TLS_WANT_POLLIN ? POLLIN : POLLOUT;
|
||||
if (lseek(client->fd, -1 * len, SEEK_CUR) == -1) {
|
||||
warnx("lseek");
|
||||
goodbye(fds, client);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
w -= t;
|
||||
i += t;
|
||||
off += ret;
|
||||
len -= ret;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user