libuv-svace-build
98 строк · 2.8 Кб
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy
4* of this software and associated documentation files (the "Software"), to
5* deal in the Software without restriction, including without limitation the
6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7* sell copies of the Software, and to permit persons to whom the Software is
8* furnished to do so, subject to the following conditions:
9*
10* The above copyright notice and this permission notice shall be included in
11* all copies or substantial portions of the Software.
12*
13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19* IN THE SOFTWARE.
20*/
21
22#include "uv.h"23#include "task.h"24
25#include <stdio.h>26#include <stdlib.h>27#include <string.h>28
29static int connect_cb_called;30static int write_cb_called;31static int close_cb_called;32
33
34static void close_cb(uv_handle_t* handle) {35close_cb_called++;36}
37
38
39static void connect_cb(uv_connect_t* req, int status) {40ASSERT_LT(status, 0);41connect_cb_called++;42uv_close((uv_handle_t*)req->handle, close_cb);43}
44
45
46static void write_cb(uv_write_t* req, int status) {47ASSERT_LT(status, 0);48write_cb_called++;49}
50
51
52/*
53* Try to connect to an address on which nothing listens, get ECONNREFUSED
54* (uv errno 12) and get connect_cb() called once with status != 0.
55* Related issue: https://github.com/joyent/libuv/issues/443
56*/
57TEST_IMPL(tcp_connect_error_after_write) {58#ifdef _WIN3259RETURN_SKIP("This test is disabled on Windows for now. "60"See https://github.com/joyent/libuv/issues/444\n");61#else62
63uv_connect_t connect_req;64struct sockaddr_in addr;65uv_write_t write_req;66uv_tcp_t conn;67uv_buf_t buf;68int r;69
70ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));71buf = uv_buf_init("TEST", 4);72
73r = uv_tcp_init(uv_default_loop(), &conn);74ASSERT_OK(r);75
76r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb);77ASSERT_EQ(r, UV_EBADF);78
79r = uv_tcp_connect(&connect_req,80&conn,81(const struct sockaddr*) &addr,82connect_cb);83ASSERT_OK(r);84
85r = uv_write(&write_req, (uv_stream_t*)&conn, &buf, 1, write_cb);86ASSERT_OK(r);87
88r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);89ASSERT_OK(r);90
91ASSERT_EQ(1, connect_cb_called);92ASSERT_EQ(1, write_cb_called);93ASSERT_EQ(1, close_cb_called);94
95MAKE_VALGRIND_HAPPY(uv_default_loop());96return 0;97#endif98}
99