Tue, 09 Jan 2018 15:02:24 +0100
fixes async sendfile
--- a/src/server/public/nsapi.h Sat Feb 18 13:27:25 2017 +0100 +++ b/src/server/public/nsapi.h Tue Jan 09 15:02:24 2018 +0100 @@ -1140,7 +1140,7 @@ // new types typedef struct aiocb_s { - SYS_FILE filedes; + SYS_FILE filedes; void *buf; size_t nbytes; off_t offset;
--- a/src/server/safs/service.c Sat Feb 18 13:27:25 2017 +0100 +++ b/src/server/safs/service.c Tue Jan 09 15:02:24 2018 +0100 @@ -43,7 +43,6 @@ #include <errno.h> - /* * prepares servicing a file * @@ -318,12 +317,17 @@ static int send_bytes(AsyncSendRange *asr, WSBool *completed) { *completed = FALSE; - if(send_buf(asr->out, asr->header, asr->headerlen, &asr->headerpos)) { - if(net_errno(asr->out) == EAGAIN) { - return 0; - } else { - asr->error = TRUE; - return 1; + if(asr->header) { + if(send_buf(asr->out, asr->header, asr->headerlen, &asr->headerpos)) { + if(net_errno(asr->out) == EAGAIN) { + return 0; + } else { + asr->error = TRUE; + return 1; + } + } + if(asr->headerpos >= asr->headerlen) { + asr->header = NULL; } } @@ -339,6 +343,8 @@ if(!asr->read_complete) { // write completed => new asynchronous read asr->aio->offset += asr->aio->result; + size_t length = asr->end - asr->offset; + asr->aio->nbytes = AIO_BUF_SIZE < length ? AIO_BUF_SIZE : length; if(system_aio_read(asr->aio)) { asr->error = TRUE; return 1; @@ -352,12 +358,13 @@ AsyncSendRange *asr = event->cookie; asr->read_inprogress = FALSE; asr->wpos = 0; - if(asr->error) { + asr->offset += asr->aio->result; + if(asr->error || asr->aio->result < 0) { return 0; } int ret = 1; - if(asr->aio->result == 0) { + if(asr->aio->result == 0 || asr->offset >= asr->end) { asr->read_complete = TRUE; ret = 0; } @@ -380,16 +387,15 @@ static int send_range_writeevent(EventHandler *ev, Event *event) { AsyncSendRange *asr = event->cookie; if(asr->error) { - return 0; + return 1; } WSBool completed; if(send_bytes(asr, &completed)) { - return 0; + return 1; } - if(completed && asr->read_complete) { - // everything completed + if(completed) { return 0; } @@ -433,7 +439,8 @@ asr->in = fd; asr->out = sn->csd; asr->offset = offset; - asr->length = length; + asr->end = offset + length; + //asr->length = length; asr->pos = offset; asr->read_complete = FALSE; asr->read_inprogress = FALSE;