Partial Write
PengZheng opened this issue · comments
PengZheng commented
evt__tls__op
failed to deal with partial write of evt__send_pending
, which makes the whole library unusable.
dlmeetei commented
Can you elaborate or some test case to reproduce?
PengZheng commented
Can you elaborate or some test case to reproduce?
case EVT_TLS_OP_WRITE: {
assert( sz > 0 && "number of bytes to write should be positive");
r = SSL_write(conn->ssl, buf, sz);
if ( 0 == r) goto handle_shutdown;
bytes = evt__send_pending(conn);
if ( r > 0 && conn->write_cb) {
conn->write_cb(conn, r);
}
break;
}
evt__tls__op
does not use return value bytes
, i.e. the API doesn't keep track of how much data has been actually sent, which becomes conn->writer
's responsibility. The reference implementation given by uv_tls_writer
fails to do that.
int uv_tls_writer(evt_tls_t *t, void *bfr, int sz) {
int rv = 0;
uv_buf_t b;
b.base = bfr;
b.len = sz;
uv_tls_t *uvt = t->data;
if(uv_is_writable((uv_stream_t*)(uvt->tcp_hdl)) ) {
rv = uv_try_write((uv_stream_t*)(uvt->tcp_hdl), &b, 1);
}
return rv;
}
When conn->write_cb
invoked, it's possible that data has not been actually written into the underlying socket. At its best, the API is very awkward to use.