tcp.hpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef __ZMQ_TCP_HPP_INCLUDED__
  25. #define __ZMQ_TCP_HPP_INCLUDED__
  26. #include "fd.hpp"
  27. namespace zmq
  28. {
  29. class tcp_address_t;
  30. struct options_t;
  31. // Tunes the supplied TCP socket for the best latency.
  32. int tune_tcp_socket (fd_t s_);
  33. // Sets the socket send buffer size.
  34. int set_tcp_send_buffer (fd_t sockfd_, int bufsize_);
  35. // Sets the socket receive buffer size.
  36. int set_tcp_receive_buffer (fd_t sockfd_, int bufsize_);
  37. // Tunes TCP keep-alives
  38. int tune_tcp_keepalives (fd_t s_,
  39. int keepalive_,
  40. int keepalive_cnt_,
  41. int keepalive_idle_,
  42. int keepalive_intvl_);
  43. // Tunes TCP max retransmit timeout
  44. int tune_tcp_maxrt (fd_t sockfd_, int timeout_);
  45. // Writes data to the socket. Returns the number of bytes actually
  46. // written (even zero is to be considered to be a success). In case
  47. // of error or orderly shutdown by the other peer -1 is returned.
  48. int tcp_write (fd_t s_, const void *data_, size_t size_);
  49. // Reads data from the socket (up to 'size' bytes).
  50. // Returns the number of bytes actually read or -1 on error.
  51. // Zero indicates the peer has closed the connection.
  52. int tcp_read (fd_t s_, void *data_, size_t size_);
  53. void tcp_tune_loopback_fast_path (fd_t socket_);
  54. void tune_tcp_busy_poll (fd_t socket_, int busy_poll_);
  55. // Resolves the given address_ string, opens a socket and sets socket options
  56. // according to the passed options_. On success, returns the socket
  57. // descriptor and assigns the resolved address to out_tcp_addr_. In case of
  58. // an error, retired_fd is returned, and the value of out_tcp_addr_ is undefined.
  59. // errno is set to an error code describing the cause of the error.
  60. fd_t tcp_open_socket (const char *address_,
  61. const options_t &options_,
  62. bool local_,
  63. bool fallback_to_ipv4_,
  64. tcp_address_t *out_tcp_addr_);
  65. }
  66. #endif