Fix infinite loop on premature end-of-file.
When files end early, read() will return with a zero return code. Before this patch, this would result in an infinite loop as no progress is ever made. Treat this gracefully and finish copying. (This came up reading generated files from a fuse-filesystem whose initial predicted stat() filesise didn't match the final size)
This commit is contained in:
parent
ca6dbba183
commit
630ccd27d5
@ -1289,6 +1289,10 @@ send_file(struct upnphttp * h, int sendfd, off_t offset, off_t end_offset)
|
||||
else if( errno != EAGAIN )
|
||||
break;
|
||||
}
|
||||
else if( ret == 0 )
|
||||
{
|
||||
break; /* Premature end of file */
|
||||
}
|
||||
else
|
||||
{
|
||||
//DPRINTF(E_DEBUG, L_HTTP, "sent %lld bytes to %d. offset is now %lld.\n", ret, h->socket, offset);
|
||||
@ -1309,6 +1313,10 @@ send_file(struct upnphttp * h, int sendfd, off_t offset, off_t end_offset)
|
||||
else
|
||||
break;
|
||||
}
|
||||
else if( ret == 0 )
|
||||
{
|
||||
break; /* premature end of file */
|
||||
}
|
||||
ret = write(h->ev.fd, buf, ret);
|
||||
if( ret == -1 ) {
|
||||
DPRINTF(E_DEBUG, L_HTTP, "write error :: error no. %d [%s]\n", errno, strerror(errno));
|
||||
|
Loading…
x
Reference in New Issue
Block a user