unix: fix tcp-writealot
This commit is contained in:
parent
7124fc5eca
commit
17c568b235
22
oio-unix.c
22
oio-unix.c
@ -441,13 +441,10 @@ void oio__write(oio_handle* handle) {
|
||||
/* Cast to iovec. We had to have our own oio_buf instead of iovec
|
||||
* because Windows's WSABUF is not an iovec.
|
||||
*/
|
||||
struct iovec* iov = (struct iovec*) (req->read_bufs +
|
||||
req->write_index * sizeof(oio_buf));
|
||||
assert(sizeof(oio_buf) == sizeof(struct iovec));
|
||||
struct iovec* iov = (struct iovec*) &(req->read_bufs[req->write_index]);
|
||||
int iovcnt = req->read_bufcnt - req->write_index;
|
||||
|
||||
assert(iov);
|
||||
assert(iovcnt > 0);
|
||||
|
||||
/* Now do the actual writev. Note that we've been updating the pointers
|
||||
* inside the iov each time we write. So there is no need to offset it.
|
||||
*/
|
||||
@ -461,11 +458,11 @@ void oio__write(oio_handle* handle) {
|
||||
oio_err err = oio_err_new(handle, errno);
|
||||
|
||||
/* XXX How do we handle the error? Need test coverage here. */
|
||||
oio_close(handle);
|
||||
|
||||
if (cb) {
|
||||
cb(req, -1);
|
||||
}
|
||||
oio_close(handle);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -473,19 +470,24 @@ void oio__write(oio_handle* handle) {
|
||||
|
||||
/* The loop updates the counters. */
|
||||
while (n > 0) {
|
||||
char* base = req->read_bufs[req->write_index].base;
|
||||
size_t len = req->read_bufs[req->write_index].len;
|
||||
oio_buf* buf = &(req->read_bufs[req->write_index]);
|
||||
size_t len = buf->len;
|
||||
|
||||
assert(req->write_index < req->read_bufcnt);
|
||||
|
||||
if (n < len) {
|
||||
req->read_bufs[req->write_index].base += n;
|
||||
req->read_bufs[req->write_index].len -= n;
|
||||
buf->base += n;
|
||||
buf->len -= n;
|
||||
handle->write_queue_size -= n;
|
||||
n = 0;
|
||||
|
||||
assert(buf->base > 0x100);
|
||||
|
||||
/* There is more to write. Break and ensure the watcher is pending. */
|
||||
break;
|
||||
|
||||
} else {
|
||||
assert(buf->base > 0x100);
|
||||
/* Finished writing the buf at index req->write_index. */
|
||||
req->write_index++;
|
||||
|
||||
|
||||
@ -43,7 +43,11 @@ void on_accept(oio_handle* handle);
|
||||
void after_write(oio_req* req, int status) {
|
||||
write_req_t* wr;
|
||||
|
||||
ASSERT(status == 0);
|
||||
if (status) {
|
||||
oio_err err = oio_last_error();
|
||||
fprintf(stderr, "oio_write error: %s\n", oio_strerror(err));
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
wr = (write_req_t*) req;
|
||||
|
||||
|
||||
@ -80,7 +80,12 @@ static void read_cb(oio_handle* handle, int nread, oio_buf buf) {
|
||||
|
||||
static void write_cb(oio_req* req, int status) {
|
||||
ASSERT(req != NULL);
|
||||
ASSERT(status == 0);
|
||||
|
||||
if (status) {
|
||||
oio_err err = oio_last_error();
|
||||
fprintf(stderr, "oio_write error: %s\n", oio_strerror(err));
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
bytes_sent_done += CHUNKS_PER_WRITE * CHUNK_SIZE;
|
||||
write_cb_called++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user