test: simplify test-tcp-try-write

Use a smaller buffer thus making sure that uv_try_write will succeed at
least once
This commit is contained in:
Saúl Ibarra Corretgé 2014-07-05 10:47:39 +02:00
parent 40ad12e5be
commit b018dc5b72

View File

@ -54,22 +54,18 @@ static void close_cb(uv_handle_t* handle) {
static void connect_cb(uv_connect_t* req, int status) { static void connect_cb(uv_connect_t* req, int status) {
static char zeroes[1024];
int r; int r;
uv_buf_t buf; uv_buf_t buf;
ASSERT(status == 0); ASSERT(status == 0);
connect_cb_called++; connect_cb_called++;
do { do {
buf = uv_buf_init(zeroes, sizeof(zeroes)); buf = uv_buf_init("PING", 4);
r = uv_try_write((uv_stream_t*) &client, &buf, 1); r = uv_try_write((uv_stream_t*) &client, &buf, 1);
ASSERT(r > 0 || r == UV_EAGAIN); ASSERT(r > 0 || r == UV_EAGAIN);
if (r > 0) { if (r > 0) {
bytes_written += r; bytes_written += r;
break;
/* Partial write */
if (r != (int) sizeof(zeroes))
break;
} }
} while (1); } while (1);
uv_close((uv_handle_t*) &client, close_cb); uv_close((uv_handle_t*) &client, close_cb);