CURLOPT_IOCTLFUNCTION.md (2585B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_IOCTLFUNCTION 5 Section: 3 6 Source: libcurl 7 Protocol: 8 - All 9 See-also: 10 - CURLOPT_IOCTLDATA (3) 11 - CURLOPT_SEEKFUNCTION (3) 12 Added-in: 7.12.3 13 --- 14 15 # NAME 16 17 CURLOPT_IOCTLFUNCTION - callback for I/O operations 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 typedef enum { 25 CURLIOE_OK, /* I/O operation successful */ 26 CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ 27 CURLIOE_FAILRESTART, /* failed to restart the read */ 28 CURLIOE_LAST /* never use */ 29 } curlioerr; 30 31 typedef enum { 32 CURLIOCMD_NOP, /* no operation */ 33 CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ 34 CURLIOCMD_LAST /* never use */ 35 } curliocmd; 36 37 curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp); 38 39 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_IOCTLFUNCTION, ioctl_callback); 40 ~~~ 41 42 # DESCRIPTION 43 44 Pass a pointer to your callback function, which should match the prototype 45 shown above. 46 47 This callback function gets called by libcurl when something special 48 I/O-related needs to be done that the library cannot do by itself. For now, 49 rewinding the read data stream is the only action it can request. The 50 rewinding of the read data stream may be necessary when doing an HTTP PUT or 51 POST with a multi-pass authentication method. 52 53 The callback MUST return *CURLIOE_UNKNOWNCMD* if the input *cmd* is 54 not *CURLIOCMD_RESTARTREAD*. 55 56 The *clientp* argument to the callback is set with the 57 CURLOPT_IOCTLDATA(3) option. 58 59 **This option is deprecated**. Do not use it. Use CURLOPT_SEEKFUNCTION(3) 60 instead to provide seeking. If CURLOPT_SEEKFUNCTION(3) is set, this 61 parameter is ignored when seeking. 62 63 # DEFAULT 64 65 NULL 66 67 # %PROTOCOLS% 68 69 # EXAMPLE 70 71 ~~~c 72 #include <unistd.h> /* for lseek */ 73 74 struct data { 75 int fd; /* our file descriptor */ 76 }; 77 78 static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp) 79 { 80 struct data *io = (struct data *)clientp; 81 if(cmd == CURLIOCMD_RESTARTREAD) { 82 lseek(io->fd, 0, SEEK_SET); 83 return CURLIOE_OK; 84 } 85 return CURLIOE_UNKNOWNCMD; 86 } 87 int main(void) 88 { 89 struct data ioctl_data; 90 CURL *curl = curl_easy_init(); 91 if(curl) { 92 curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback); 93 curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data); 94 } 95 } 96 ~~~ 97 98 # DEPRECATED 99 100 Deprecated since 7.18.0. 101 102 # %AVAILABILITY% 103 104 # RETURN VALUE 105 106 curl_easy_setopt(3) returns a CURLcode indicating success or error. 107 108 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 109 libcurl-errors(3).