CURLOPT_SEEKFUNCTION.3 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_SEEKFUNCTION 3 "16 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_SEEKFUNCTION \- user callback for seeking in input stream
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. /* These are the return codes for the seek callbacks */
  30. #define CURL_SEEKFUNC_OK 0
  31. #define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */
  32. #define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking cannot be done, so
  33. libcurl might try other means instead */
  34. int seek_callback(void *userp, curl_off_t offset, int origin);
  35. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_callback);
  36. .SH DESCRIPTION
  37. Pass a pointer to your callback function, which should match the prototype
  38. shown above.
  39. This function gets called by libcurl to seek to a certain position in the
  40. input stream and can be used to fast forward a file in a resumed upload
  41. (instead of reading all uploaded bytes with the normal read
  42. function/callback). It is also called to rewind a stream when data has already
  43. been sent to the server and needs to be sent again. This may happen when doing
  44. an HTTP PUT or POST with a multi-pass authentication method, or when an
  45. existing HTTP connection is reused too late and the server closes the
  46. connection. The function shall work like fseek(3) or lseek(3) and it gets
  47. SEEK_SET, SEEK_CUR or SEEK_END as argument for \fIorigin\fP, although libcurl
  48. currently only passes SEEK_SET.
  49. \fIuserp\fP is the pointer you set with \fICURLOPT_SEEKDATA(3)\fP.
  50. The callback function must return \fICURL_SEEKFUNC_OK\fP on success,
  51. \fICURL_SEEKFUNC_FAIL\fP to cause the upload operation to fail or
  52. \fICURL_SEEKFUNC_CANTSEEK\fP to indicate that while the seek failed, libcurl
  53. is free to work around the problem if possible. The latter can sometimes be
  54. done by instead reading from the input or similar.
  55. If you forward the input arguments directly to fseek(3) or lseek(3), note that
  56. the data type for \fIoffset\fP is not the same as defined for curl_off_t on
  57. many systems!
  58. .SH DEFAULT
  59. By default, this is NULL and unused.
  60. .SH PROTOCOLS
  61. HTTP, FTP, SFTP
  62. .SH EXAMPLE
  63. .nf
  64. static int seek_cb(void *userp, curl_off_t offset, int origin)
  65. {
  66. struct data *d = (struct data *)userp;
  67. lseek(our_fd, offset, origin);
  68. return CURL_SEEKFUNC_OK;
  69. }
  70. {
  71. struct data seek_data;
  72. curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
  73. curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
  74. }
  75. .fi
  76. .SH AVAILABILITY
  77. Added in 7.18.0
  78. .SH RETURN VALUE
  79. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  80. .SH "SEE ALSO"
  81. .BR CURLOPT_SEEKDATA "(3), " CURLOPT_IOCTLFUNCTION "(3), "