the upcoming 2.0 version
https://redmine.lighttpd.net/projects/lighttpd2
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
|
|
#include <lighttpd/base.h> |
|
|
|
liNetworkStatus li_network_backend_write(liVRequest *vr, int fd, liChunkQueue *cq, goffset *write_max) { |
|
const ssize_t blocksize = 16*1024; /* 16k */ |
|
char *block_data; |
|
off_t block_len; |
|
ssize_t r; |
|
gboolean did_write_something = FALSE; |
|
liChunkIter ci; |
|
|
|
do { |
|
if (0 == cq->length) |
|
return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_FATAL_ERROR; |
|
|
|
ci = chunkqueue_iter(cq); |
|
/* TODO: handle SIGBUS */ |
|
switch (li_chunkiter_read_mmap(vr, ci, 0, blocksize, &block_data, &block_len)) { |
|
case LI_HANDLER_GO_ON: |
|
break; |
|
case LI_HANDLER_ERROR: |
|
default: |
|
return LI_NETWORK_STATUS_FATAL_ERROR; |
|
} |
|
|
|
if (-1 == (r = li_net_write(fd, block_data, block_len))) { |
|
switch (errno) { |
|
case EAGAIN: |
|
#if EWOULDBLOCK != EAGAIN |
|
case EWOULDBLOCK: |
|
#endif |
|
return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; |
|
case ECONNRESET: |
|
case EPIPE: |
|
return LI_NETWORK_STATUS_CONNECTION_CLOSE; |
|
default: |
|
VR_ERROR(vr, "oops, write to fd=%d failed: %s", fd, g_strerror(errno)); |
|
return LI_NETWORK_STATUS_FATAL_ERROR; |
|
} |
|
} else if (0 == r) { |
|
return did_write_something ? LI_NETWORK_STATUS_SUCCESS : LI_NETWORK_STATUS_WAIT_FOR_EVENT; |
|
} |
|
|
|
li_chunkqueue_skip(cq, r); |
|
did_write_something = TRUE; |
|
*write_max -= r; |
|
} while (r == block_len && *write_max > 0); |
|
|
|
return LI_NETWORK_STATUS_SUCCESS; |
|
}
|
|
|