Address review
This commit is contained in:
parent
d718a22ace
commit
a29797999b
@ -87,13 +87,4 @@ static inline void uv__queue_remove(struct uv__queue* q) {
|
||||
q->next->prev = q->prev;
|
||||
}
|
||||
|
||||
static inline int uv__queue_contains(const struct uv__queue* h,
|
||||
const struct uv__queue* q) {
|
||||
const struct uv__queue* p;
|
||||
uv__queue_foreach(p, h)
|
||||
if (p == q)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* QUEUE_H_ */
|
||||
|
||||
@ -1409,20 +1409,24 @@ size_t uv_write_nwritten(const uv_write_t* req) {
|
||||
|
||||
|
||||
int uv_write_cancel(uv_write_t* req) {
|
||||
struct uv__queue* q;
|
||||
uv_stream_t* stream;
|
||||
|
||||
stream = req->handle;
|
||||
|
||||
/* Already completed, return success, callback will return success as well */
|
||||
if (!uv__queue_contains(&stream->write_queue, &req->queue))
|
||||
return 0;
|
||||
/* N.B.: If the request already completed, we still return 0, but the callback
|
||||
will not return ECANCELED - nothing to do here. */
|
||||
uv__queue_foreach(q, &stream->write_queue) {
|
||||
if (q == &req->queue) {
|
||||
uv__queue_remove(&req->queue);
|
||||
req->error = UV_ECANCELED;
|
||||
|
||||
uv__queue_remove(&req->queue);
|
||||
req->error = UV_ECANCELED;
|
||||
|
||||
/* uv__write_callbacks will handle write_queue_size and freeing bufs. */
|
||||
uv__queue_insert_tail(&stream->write_completed_queue, &req->queue);
|
||||
uv__io_feed(stream->loop, &stream->io_watcher);
|
||||
/* uv__write_callbacks will handle write_queue_size and freeing bufs. */
|
||||
uv__queue_insert_tail(&stream->write_completed_queue, &req->queue);
|
||||
uv__io_feed(stream->loop, &stream->io_watcher);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
SET_REQ_STATUS((req), NTSTATUS_FROM_WIN32((error)))
|
||||
|
||||
#define SET_REQ_NWRITTEN(req, nwritten) \
|
||||
(req)->u.io.overlapped.InternalHigh = (ULONG_PTR) (nwritten);
|
||||
(req)->u.io.overlapped.InternalHigh = (nwritten);
|
||||
|
||||
/* Note: used open-coded in UV_REQ_INIT() because of a circular dependency
|
||||
* between src/uv-common.h and src/win/internal.h.
|
||||
|
||||
@ -284,7 +284,6 @@ int uv_write_cancel(uv_write_t* req) {
|
||||
* is not applicable - the callback has already been queued. */
|
||||
return 0;
|
||||
default:
|
||||
assert(0);
|
||||
return UV_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +48,8 @@ static void connection_cb(uv_stream_t* tcp, int status) {
|
||||
ASSERT_OK(status);
|
||||
ASSERT_OK(uv_tcp_init(tcp->loop, &incoming));
|
||||
ASSERT_OK(uv_accept(tcp, (uv_stream_t*) &incoming));
|
||||
connected = 1;
|
||||
connected++;
|
||||
ASSERT_EQ(1, connected);
|
||||
}
|
||||
|
||||
static void write_cb(uv_write_t* req, int status) {
|
||||
@ -123,7 +124,13 @@ TEST_IMPL(tcp_write_cancel) {
|
||||
&client,
|
||||
(struct sockaddr*) &addr,
|
||||
connect_cb));
|
||||
/* Set the send buffer size small to ensure that writes get queued in
|
||||
* userspace rather than fitting entirely in the kernel's send buffer.
|
||||
* Also set the receive buffer small so the receiver doesn't drain data
|
||||
* and relieve backpressure. Note: Linux sets the actual buffer to twice
|
||||
* the requested size. */
|
||||
ASSERT_OK(uv_send_buffer_size((uv_handle_t*) &client, &buffer_size));
|
||||
ASSERT_OK(uv_recv_buffer_size((uv_handle_t*) &client, &buffer_size));
|
||||
|
||||
ASSERT_OK(uv_run(loop, UV_RUN_DEFAULT));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user