1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_IOCTLFUNCTION 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerProtocol: 8*6236dae4SAndroid Build Coastguard Worker - All 9*6236dae4SAndroid Build Coastguard WorkerSee-also: 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_IOCTLDATA (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_SEEKFUNCTION (3) 12*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.12.3 13*6236dae4SAndroid Build Coastguard Worker--- 14*6236dae4SAndroid Build Coastguard Worker 15*6236dae4SAndroid Build Coastguard Worker# NAME 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard WorkerCURLOPT_IOCTLFUNCTION - callback for I/O operations 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker~~~c 22*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Workertypedef enum { 25*6236dae4SAndroid Build Coastguard Worker CURLIOE_OK, /* I/O operation successful */ 26*6236dae4SAndroid Build Coastguard Worker CURLIOE_UNKNOWNCMD, /* command was unknown to callback */ 27*6236dae4SAndroid Build Coastguard Worker CURLIOE_FAILRESTART, /* failed to restart the read */ 28*6236dae4SAndroid Build Coastguard Worker CURLIOE_LAST /* never use */ 29*6236dae4SAndroid Build Coastguard Worker} curlioerr; 30*6236dae4SAndroid Build Coastguard Worker 31*6236dae4SAndroid Build Coastguard Workertypedef enum { 32*6236dae4SAndroid Build Coastguard Worker CURLIOCMD_NOP, /* no operation */ 33*6236dae4SAndroid Build Coastguard Worker CURLIOCMD_RESTARTREAD, /* restart the read stream from start */ 34*6236dae4SAndroid Build Coastguard Worker CURLIOCMD_LAST /* never use */ 35*6236dae4SAndroid Build Coastguard Worker} curliocmd; 36*6236dae4SAndroid Build Coastguard Worker 37*6236dae4SAndroid Build Coastguard Workercurlioerr ioctl_callback(CURL *handle, int cmd, void *clientp); 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_IOCTLFUNCTION, ioctl_callback); 40*6236dae4SAndroid Build Coastguard Worker~~~ 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerPass a pointer to your callback function, which should match the prototype 45*6236dae4SAndroid Build Coastguard Workershown above. 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard WorkerThis callback function gets called by libcurl when something special 48*6236dae4SAndroid Build Coastguard WorkerI/O-related needs to be done that the library cannot do by itself. For now, 49*6236dae4SAndroid Build Coastguard Workerrewinding the read data stream is the only action it can request. The 50*6236dae4SAndroid Build Coastguard Workerrewinding of the read data stream may be necessary when doing an HTTP PUT or 51*6236dae4SAndroid Build Coastguard WorkerPOST with a multi-pass authentication method. 52*6236dae4SAndroid Build Coastguard Worker 53*6236dae4SAndroid Build Coastguard WorkerThe callback MUST return *CURLIOE_UNKNOWNCMD* if the input *cmd* is 54*6236dae4SAndroid Build Coastguard Workernot *CURLIOCMD_RESTARTREAD*. 55*6236dae4SAndroid Build Coastguard Worker 56*6236dae4SAndroid Build Coastguard WorkerThe *clientp* argument to the callback is set with the 57*6236dae4SAndroid Build Coastguard WorkerCURLOPT_IOCTLDATA(3) option. 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard Worker**This option is deprecated**. Do not use it. Use CURLOPT_SEEKFUNCTION(3) 60*6236dae4SAndroid Build Coastguard Workerinstead to provide seeking. If CURLOPT_SEEKFUNCTION(3) is set, this 61*6236dae4SAndroid Build Coastguard Workerparameter is ignored when seeking. 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker# DEFAULT 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard WorkerNULL 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker~~~c 72*6236dae4SAndroid Build Coastguard Worker#include <unistd.h> /* for lseek */ 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Workerstruct data { 75*6236dae4SAndroid Build Coastguard Worker int fd; /* our file descriptor */ 76*6236dae4SAndroid Build Coastguard Worker}; 77*6236dae4SAndroid Build Coastguard Worker 78*6236dae4SAndroid Build Coastguard Workerstatic curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp) 79*6236dae4SAndroid Build Coastguard Worker{ 80*6236dae4SAndroid Build Coastguard Worker struct data *io = (struct data *)clientp; 81*6236dae4SAndroid Build Coastguard Worker if(cmd == CURLIOCMD_RESTARTREAD) { 82*6236dae4SAndroid Build Coastguard Worker lseek(io->fd, 0, SEEK_SET); 83*6236dae4SAndroid Build Coastguard Worker return CURLIOE_OK; 84*6236dae4SAndroid Build Coastguard Worker } 85*6236dae4SAndroid Build Coastguard Worker return CURLIOE_UNKNOWNCMD; 86*6236dae4SAndroid Build Coastguard Worker} 87*6236dae4SAndroid Build Coastguard Workerint main(void) 88*6236dae4SAndroid Build Coastguard Worker{ 89*6236dae4SAndroid Build Coastguard Worker struct data ioctl_data; 90*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 91*6236dae4SAndroid Build Coastguard Worker if(curl) { 92*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback); 93*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &ioctl_data); 94*6236dae4SAndroid Build Coastguard Worker } 95*6236dae4SAndroid Build Coastguard Worker} 96*6236dae4SAndroid Build Coastguard Worker~~~ 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard Worker# DEPRECATED 99*6236dae4SAndroid Build Coastguard Worker 100*6236dae4SAndroid Build Coastguard WorkerDeprecated since 7.18.0. 101*6236dae4SAndroid Build Coastguard Worker 102*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 103*6236dae4SAndroid Build Coastguard Worker 104*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 105*6236dae4SAndroid Build Coastguard Worker 106*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. 107