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 | static uv_udp_t udp; |
30 | static uv_tcp_t tcp; |
31 | static int close_cb_called; |
32 | |
33 | |
34 | static void close_cb(uv_handle_t* handle) { |
35 | close_cb_called++; |
36 | } |
37 | |
38 | |
39 | static void check_buffer_size(uv_handle_t* handle) { |
40 | int value; |
41 | |
42 | value = 0; |
43 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); |
44 | ASSERT(value > 0); |
45 | |
46 | value = 10000; |
47 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); |
48 | |
49 | value = 0; |
50 | ASSERT(0 == uv_recv_buffer_size(handle, &value)); |
51 | /* linux sets double the value */ |
52 | ASSERT(value == 10000 || value == 20000); |
53 | } |
54 | |
55 | |
56 | TEST_IMPL(socket_buffer_size) { |
57 | struct sockaddr_in addr; |
58 | |
59 | ASSERT(0 == uv_ip4_addr("127.0.0.1" , TEST_PORT, &addr)); |
60 | |
61 | ASSERT(0 == uv_tcp_init(uv_default_loop(), &tcp)); |
62 | ASSERT(0 == uv_tcp_bind(&tcp, (struct sockaddr*) &addr, 0)); |
63 | check_buffer_size((uv_handle_t*) &tcp); |
64 | uv_close((uv_handle_t*) &tcp, close_cb); |
65 | |
66 | ASSERT(0 == uv_udp_init(uv_default_loop(), &udp)); |
67 | ASSERT(0 == uv_udp_bind(&udp, (struct sockaddr*) &addr, 0)); |
68 | check_buffer_size((uv_handle_t*) &udp); |
69 | uv_close((uv_handle_t*) &udp, close_cb); |
70 | |
71 | ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); |
72 | |
73 | ASSERT(close_cb_called == 2); |
74 | |
75 | MAKE_VALGRIND_HAPPY(); |
76 | return 0; |
77 | } |
78 | |