ares_set_socket_functions.3 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. .\"
  2. .TH ARES_SET_SOCKET_FUNCTIONS 3 "13 Dec 2016"
  3. .SH NAME
  4. ares_set_socket_functions \- Set socket io callbacks
  5. .SH SYNOPSIS
  6. .nf
  7. .B #include <ares.h>
  8. .PP
  9. .B struct ares_socket_functions {
  10. ares_socket_t(*\fIasocket\fP)(int, int, int, void *);
  11. int(*\fIaclose\fP)(ares_socket_t, void *);
  12. int(*\fIaconnect\fP)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
  13. ares_ssize_t(*\fIarecvfrom\fP)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
  14. ares_ssize_t(*\fIasendv\fP)(ares_socket_t, const struct iovec *, int, void *);
  15. };
  16. .PP
  17. .B void ares_set_socket_functions(ares_channel \fIchannel\fP,
  18. const struct ares_socket_functions * \fIfunctions\fP,
  19. void *\fIuser_data\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. .PP
  23. This function sets a set of callback \fIfunctions\fP in the given ares channel handle.
  24. These callback functions will be invoked to create/destroy socket objects and perform
  25. io, instead of the normal system calls. A client application can override normal network
  26. operation fully through this functionality, and provide its own transport layer.
  27. .PP
  28. All callback functions are expected to operate like their system equivalents, and to
  29. set
  30. .BR errno(3)
  31. to an appropriate error code on failure. C-ares also expects all io functions to behave
  32. asynchronously, i.e. as if the socket object has been set to non-blocking mode. Thus
  33. read/write calls (for TCP connections) are expected to often generate
  34. .BR EAGAIN
  35. or
  36. .BR EWOULDBLOCK.
  37. .PP
  38. The \fIuser_data\fP value is provided to each callback function invocation to serve as
  39. context.
  40. .PP
  41. The
  42. .B ares_socket_functions
  43. must provide the following callbacks:
  44. .TP 18
  45. .B \fIasocket\fP
  46. .B ares_socket_t(*)(int \fIdomain\fP, int \fItype\fP, int \fIprotocol\fP, void * \fIuser_data\fP)
  47. .br
  48. Creates an endpoint for communication and returns a descriptor. \fIdomain\fP, \fItype\fP, and \fIprotocol\fP
  49. each correspond to the parameters of
  50. .BR socket(2).
  51. Returns ahandle to the newly created socket, or -1 on error.
  52. .TP 18
  53. .B \fIaclose\fP
  54. .B int(*)(ares_socket_t \fIfd\fP, void * \fIuser_data\fP)
  55. .br
  56. Closes the socket endpoint indicated by \fIfd\fP. See
  57. .BR close(2)
  58. .TP 18
  59. .B \fIaconnect\fP
  60. .B int(*)(ares_socket_t \fIfd\fP, const struct sockaddr * \fIaddr\fP, ares_socklen_t \fIaddr_len\fP, void * \fIuser_data\fP)
  61. .br
  62. Initiate a connection to the address indicated by \fIaddr\fP on a socket. See
  63. .BR connect(2)
  64. .TP 18
  65. .B \fIarecvfrom\fP
  66. .B ares_ssize_t(*)(ares_socket_t \fIfd\fP, void * \fIbuffer\fP, size_t \fIbuf_size\fP, int \fIflags\fP, struct sockaddr * \fIaddr\fP, ares_socklen_t * \fIaddr_len\fP, void * \fIuser_data\fP)
  67. .br
  68. Receives data from remote socket endpoint, if available. If the \fIaddr\fP parameter is not NULL and the connection protocol provides the source address, the callback should fill this in. See
  69. .BR recvfrom(2)
  70. .TP 18
  71. .B \fIasendv\fP
  72. .B ares_ssize_t(*)(ares_socket_t \fIfd\fP, const struct iovec * \fIdata\fP, int \fIlen\fP, void * \fIuser_data\fP)
  73. .br
  74. Send data, as provided by the iovec array \fIdata\fP, to the socket endpoint. See
  75. .BR writev(2),
  76. .PP
  77. The
  78. .B ares_socket_functions
  79. struct provided is not copied but directly referenced,
  80. and must thus remain valid through out the channels and any created socket's lifetime.
  81. .SH AVAILABILITY
  82. Added in c-ares 1.13.0
  83. .SH SEE ALSO
  84. .BR ares_init_options (3),
  85. .BR socket(2),
  86. .BR close(2),
  87. .BR connect(2),
  88. .BR recv(2),
  89. .BR recvfrom(2),
  90. .BR send(2),
  91. .BR writev(2)
  92. .SH AUTHOR
  93. Carl Wilund