Blame test/test-tcp-write-after-connect.c

Packit b5b901
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
Packit b5b901
 *
Packit b5b901
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
 * of this software and associated documentation files (the "Software"), to
Packit b5b901
 * deal in the Software without restriction, including without limitation the
Packit b5b901
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
 * sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
 * furnished to do so, subject to the following conditions:
Packit b5b901
 *
Packit b5b901
 * The above copyright notice and this permission notice shall be included in
Packit b5b901
 * all copies or substantial portions of the Software.
Packit b5b901
 *
Packit b5b901
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
 * IN THE SOFTWARE.
Packit b5b901
 */
Packit b5b901
Packit b5b901
#ifndef _WIN32
Packit b5b901
Packit b5b901
#include "uv.h"
Packit b5b901
#include "task.h"
Packit b5b901
Packit b5b901
uv_loop_t loop;
Packit b5b901
uv_tcp_t tcp_client;
Packit b5b901
uv_connect_t connection_request;
Packit b5b901
uv_write_t write_request;
Packit b5b901
uv_buf_t buf = { "HELLO", 4 };
Packit b5b901
Packit b5b901
Packit b5b901
static void write_cb(uv_write_t *req, int status) {
Packit b5b901
  ASSERT(status == UV_ECANCELED);
Packit b5b901
  uv_close((uv_handle_t*) req->handle, NULL);
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
static void connect_cb(uv_connect_t *req, int status) {
Packit b5b901
  ASSERT(status == UV_ECONNREFUSED);
Packit b5b901
}
Packit b5b901
Packit b5b901
Packit b5b901
TEST_IMPL(tcp_write_after_connect) {
Packit Service e08953
/* TODO(gengjiawen): Fix test on QEMU. */
Packit Service e08953
#if defined(__QEMU__)
Packit Service e08953
  RETURN_SKIP("Test does not currently work in QEMU");
Packit Service e08953
#endif
Packit Service e08953
Packit b5b901
  struct sockaddr_in sa;
Packit b5b901
  ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &sa);;
Packit b5b901
  ASSERT(0 == uv_loop_init(&loop);;
Packit b5b901
  ASSERT(0 == uv_tcp_init(&loop, &tcp_client));
Packit b5b901
Packit b5b901
  ASSERT(0 == uv_tcp_connect(&connection_request,
Packit b5b901
                             &tcp_client,
Packit b5b901
                             (const struct sockaddr *)
Packit b5b901
                             &sa,
Packit b5b901
                             connect_cb));
Packit b5b901
Packit b5b901
  ASSERT(0 == uv_write(&write_request,
Packit b5b901
                       (uv_stream_t *)&tcp_client,
Packit b5b901
                       &buf, 1,
Packit b5b901
                       write_cb));
Packit b5b901
Packit b5b901
  uv_run(&loop, UV_RUN_DEFAULT);
Packit b5b901
Packit b5b901
  MAKE_VALGRIND_HAPPY();
Packit b5b901
  return 0;
Packit b5b901
}
Packit b5b901
Packit Service e08953
#else
Packit Service e08953
Packit Service e08953
typedef int file_has_no_tests; /* ISO C forbids an empty translation unit. */
Packit Service e08953
Packit Service e08953
#endif /* !_WIN32 */