libuv-svace-build
93 строки · 2.5 Кб
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
29
30TEST_IMPL(udp_bind) {31struct sockaddr_in addr;32uv_loop_t* loop;33uv_udp_t h1, h2;34int r;35
36ASSERT_OK(uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));37
38loop = uv_default_loop();39
40r = uv_udp_init(loop, &h1);41ASSERT_OK(r);42
43r = uv_udp_init(loop, &h2);44ASSERT_OK(r);45
46r = uv_udp_bind(&h1, (const struct sockaddr*) &addr, 0);47ASSERT_OK(r);48
49r = uv_udp_bind(&h2, (const struct sockaddr*) &addr, 0);50ASSERT_EQ(r, UV_EADDRINUSE);51
52uv_close((uv_handle_t*) &h1, NULL);53uv_close((uv_handle_t*) &h2, NULL);54
55r = uv_run(loop, UV_RUN_DEFAULT);56ASSERT_OK(r);57
58MAKE_VALGRIND_HAPPY(loop);59return 0;60}
61
62
63TEST_IMPL(udp_bind_reuseaddr) {64struct sockaddr_in addr;65uv_loop_t* loop;66uv_udp_t h1, h2;67int r;68
69ASSERT_OK(uv_ip4_addr("0.0.0.0", TEST_PORT, &addr));70
71loop = uv_default_loop();72
73r = uv_udp_init(loop, &h1);74ASSERT_OK(r);75
76r = uv_udp_init(loop, &h2);77ASSERT_OK(r);78
79r = uv_udp_bind(&h1, (const struct sockaddr*) &addr, UV_UDP_REUSEADDR);80ASSERT_OK(r);81
82r = uv_udp_bind(&h2, (const struct sockaddr*) &addr, UV_UDP_REUSEADDR);83ASSERT_OK(r);84
85uv_close((uv_handle_t*) &h1, NULL);86uv_close((uv_handle_t*) &h2, NULL);87
88r = uv_run(loop, UV_RUN_DEFAULT);89ASSERT_OK(r);90
91MAKE_VALGRIND_HAPPY(loop);92return 0;93}
94