CURLOPT_IOCTLFUNCTION.3 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .\" generated by cd2nroff 0.1 from CURLOPT_IOCTLFUNCTION.md
  2. .TH CURLOPT_IOCTLFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_IOCTLFUNCTION \- callback for I/O operations
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. typedef enum {
  9. CURLIOE_OK, /* I/O operation successful */
  10. CURLIOE_UNKNOWNCMD, /* command was unknown to callback */
  11. CURLIOE_FAILRESTART, /* failed to restart the read */
  12. CURLIOE_LAST /* never use */
  13. } curlioerr;
  14. typedef enum {
  15. CURLIOCMD_NOP, /* no operation */
  16. CURLIOCMD_RESTARTREAD, /* restart the read stream from start */
  17. CURLIOCMD_LAST /* never use */
  18. } curliocmd;
  19. curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp);
  20. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_IOCTLFUNCTION, ioctl_callback);
  21. .fi
  22. .SH DESCRIPTION
  23. Pass a pointer to your callback function, which should match the prototype
  24. shown above.
  25. This callback function gets called by libcurl when something special
  26. I/O\-related needs to be done that the library cannot do by itself. For now,
  27. rewinding the read data stream is the only action it can request. The
  28. rewinding of the read data stream may be necessary when doing an HTTP PUT or
  29. POST with a multi\-pass authentication method.
  30. The callback MUST return \fICURLIOE_UNKNOWNCMD\fP if the input \fIcmd\fP is
  31. not \fICURLIOCMD_RESTARTREAD\fP.
  32. The \fIclientp\fP argument to the callback is set with the
  33. \fICURLOPT_IOCTLDATA(3)\fP option.
  34. \fBThis option is deprecated\fP. Do not use it. Use \fICURLOPT_SEEKFUNCTION(3)\fP
  35. instead to provide seeking! If \fICURLOPT_SEEKFUNCTION(3)\fP is set, this
  36. parameter is ignored when seeking.
  37. .SH DEFAULT
  38. NULL
  39. .SH PROTOCOLS
  40. This functionality affects all supported protocols
  41. .SH EXAMPLE
  42. .nf
  43. #include <unistd.h> /* for lseek */
  44. struct data {
  45. int fd; /* our file descriptor */
  46. };
  47. static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp)
  48. {
  49. struct data *io = (struct data *)clientp;
  50. if(cmd == CURLIOCMD_RESTARTREAD) {
  51. lseek(io->fd, 0, SEEK_SET);
  52. return CURLIOE_OK;
  53. }
  54. return CURLIOE_UNKNOWNCMD;
  55. }
  56. int main(void)
  57. {
  58. struct data ioctl_data;
  59. CURL *curl = curl_easy_init();
  60. if(curl) {
  61. curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
  62. curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data);
  63. }
  64. }
  65. .fi
  66. .SH DEPRECATED
  67. Deprecated since 7.18.0.
  68. .SH AVAILABILITY
  69. Added in curl 7.12.3
  70. .SH RETURN VALUE
  71. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  72. .SH SEE ALSO
  73. .BR CURLOPT_IOCTLDATA (3),
  74. .BR CURLOPT_SEEKFUNCTION (3)