66 #define MSG_OUT g_print 67 #define SHOW_VERBOSE 0 68 #define SHOW_PROGRESS 0 109 default: s =
"CURLM_unknown";
111 MSG_OUT(
"ERROR: %s returns %s\n", where, s);
133 MSG_OUT(
"DONE: %s => (%d) %s\n", eff_url, res, conn->
error);
160 timeout.
tv_sec = timeout_ms/1000;
161 timeout.
tv_usec = (timeout_ms%1000)*1000;
163 MSG_OUT(
"*** update_timeout_cb %ld => %ld:%ld ***\n",
175 g->timer_event = g_timeout_add(timeout_ms,
timer_cb, g);
180 static gboolean
event_cb(GIOChannel *ch, GIOCondition condition, gpointer
data)
184 int fd = g_io_channel_unix_get_fd(ch);
198 MSG_OUT(
"last transfer done, kill timeout\n");
213 g_source_remove(f->
ev);
229 g_source_remove(f->
ev);
240 fdp->
ch = g_io_channel_unix_new(s);
241 setsock(fdp, s, easy, action, g);
250 static const char *whatstr[]={
"none",
"IN",
"OUT",
"INOUT",
"REMOVE" };
252 MSG_OUT(
"socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
266 "Changing action from %d to %d\n", fdp->
action, what);
276 size_t realsize = size * nmemb;
284 static int prog_cb(
void *
p,
double dltotal,
double dlnow,
double ult,
288 MSG_OUT(
"Progress: %s (%g/%g)\n", conn->
url, dlnow, dltotal);
302 MSG_OUT(
"curl_easy_init() failed, exiting!\n");
306 conn->
url = g_strdup(url);
330 static gboolean
fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer
data)
332 #define BUF_SIZE 1024 334 gchar *
buf, *tmp, *all = NULL;
339 rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err);
351 g_io_channel_read_chars(ch, buf,
BUF_SIZE, &len, &err);
356 all = g_strdup_printf(
"%s%s", tmp, buf);
374 g_error(
"fifo_cb: %s", err->message);
378 }
while((len) && (rv == G_IO_STATUS_NORMAL));
385 const char *
fifo =
"hiper.fifo";
388 if(lstat (fifo, &st) == 0) {
389 if((st.st_mode & S_IFMT) == S_IFREG) {
397 if(mkfifo (fifo, 0600) == -1) {
402 socket = open(fifo, O_RDWR | O_NONBLOCK, 0);
408 MSG_OUT(
"Now, pipe some URL's into > %s\n", fifo);
413 int main(
int argc,
char **argv)
423 ch = g_io_channel_unix_new(fd);
424 g_io_add_watch(ch, G_IO_IN,
fifo_cb, g);
425 gmain = g_main_loop_new(NULL,
FALSE);
435 g_main_loop_run(gmain);
static int prog_cb(void *p, double dltotal, double dlnow, double ult, double uln)
struct ev_timer timer_event
CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle)
int main(int argc, char **argv)
int stat(const char *path, struct stat *buffer)
CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd, void *sockp)
static void remsock(SockInfo *f)
UNITTEST_START char * ptr
static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
static void setsock(SockInfo *f, curl_socket_t s, CURL *e, int act, GlobalInfo *g)
#define curl_easy_setopt(handle, option, value)
struct _SockInfo SockInfo
CURL_EXTERN CURLM * curl_multi_init(void)
static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
static void check_multi_info(GlobalInfo *g)
static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp)
#define curl_multi_setopt(handle, opt, param)
#define curl_easy_getinfo(handle, info, arg)
static void mcode_or_die(const char *where, CURLMcode code)
CURL_EXTERN CURL * curl_easy_init(void)
struct _ConnInfo ConnInfo
struct _GlobalInfo GlobalInfo
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle)
static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
#define CURL_SOCKET_TIMEOUT
char error[CURL_ERROR_SIZE]
static gboolean timer_cb(gpointer data)
CURL_EXTERN CURLMsg * curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue)
static void new_conn(char *url, GlobalInfo *g)
static CURL * easy[MAX_EASY_HANDLES]
CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, curl_socket_t s, int ev_bitmask, int *running_handles)
CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle)
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)