test-socket-buffer-size.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "uv.h"
  22. #include "task.h"
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. static uv_udp_t udp;
  27. static uv_tcp_t tcp;
  28. static int close_cb_called;
  29. static void close_cb(uv_handle_t* handle) {
  30. close_cb_called++;
  31. }
  32. static void check_buffer_size(uv_handle_t* handle) {
  33. int value;
  34. value = 0;
  35. ASSERT(0 == uv_recv_buffer_size(handle, &value));
  36. ASSERT(value > 0);
  37. value = 10000;
  38. ASSERT(0 == uv_recv_buffer_size(handle, &value));
  39. value = 0;
  40. ASSERT(0 == uv_recv_buffer_size(handle, &value));
  41. /* linux sets double the value */
  42. ASSERT(value == 10000 || value == 20000);
  43. }
  44. TEST_IMPL(socket_buffer_size) {
  45. struct sockaddr_in addr;
  46. ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
  47. ASSERT(0 == uv_tcp_init(uv_default_loop(), &tcp));
  48. ASSERT(0 == uv_tcp_bind(&tcp, (struct sockaddr*) &addr, 0));
  49. check_buffer_size((uv_handle_t*) &tcp);
  50. uv_close((uv_handle_t*) &tcp, close_cb);
  51. ASSERT(0 == uv_udp_init(uv_default_loop(), &udp));
  52. ASSERT(0 == uv_udp_bind(&udp, (struct sockaddr*) &addr, 0));
  53. check_buffer_size((uv_handle_t*) &udp);
  54. uv_close((uv_handle_t*) &udp, close_cb);
  55. ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
  56. ASSERT(close_cb_called == 2);
  57. MAKE_VALGRIND_HAPPY();
  58. return 0;
  59. }