* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* KIND, either express or implied.
*
***************************************************************************/
+/* <DESC>
+ * multi socket API usage with libevent 2
+ * </DESC>
+ */
/* Example application source code using the multi socket interface to
download many files at once.
/* Die if we get a bad CURLMcode somewhere */
static void mcode_or_die(const char *where, CURLMcode code)
{
- if ( CURLM_OK != code ) {
+ if(CURLM_OK != code) {
const char *s;
switch (code) {
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break;
CURLcode res;
fprintf(MSG_OUT, "REMAINING: %d\n", g->still_running);
- while ((msg = curl_multi_info_read(g->multi, &msgs_left))) {
- if (msg->msg == CURLMSG_DONE) {
+ while((msg = curl_multi_info_read(g->multi, &msgs_left))) {
+ if(msg->msg == CURLMSG_DONE) {
easy = msg->easy_handle;
res = msg->data.result;
curl_easy_getinfo(easy, CURLINFO_PRIVATE, &conn);
mcode_or_die("event_cb: curl_multi_socket_action", rc);
check_multi_info(g);
- if ( g->still_running <= 0 ) {
+ if(g->still_running <= 0) {
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
- if (evtimer_pending(g->timer_event, NULL)) {
+ if(evtimer_pending(g->timer_event, NULL)) {
evtimer_del(g->timer_event);
}
}
/* Clean up the SockInfo structure */
static void remsock(SockInfo *f)
{
- if (f) {
- if (f->evset)
+ if(f) {
+ if(f->evset)
event_free(f->ev);
free(f);
}
f->sockfd = s;
f->action = act;
f->easy = e;
- if (f->evset)
+ if(f->evset)
event_free(f->ev);
f->ev = event_new(g->evbase, f->sockfd, kind, event_cb, g);
f->evset = 1;
fprintf(MSG_OUT,
"socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
- if (what == CURL_POLL_REMOVE) {
+ if(what == CURL_POLL_REMOVE) {
fprintf(MSG_OUT, "\n");
remsock(fdp);
}
else {
- if (!fdp) {
+ if(!fdp) {
fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]);
addsock(s, e, what, g);
}
/* Create a new easy handle, and add it to the global curl_multi */
-static void new_conn(char *url, GlobalInfo *g )
+static void new_conn(char *url, GlobalInfo *g)
{
ConnInfo *conn;
CURLMcode rc;
conn->error[0]='\0';
conn->easy = curl_easy_init();
- if (!conn->easy) {
+ if(!conn->easy) {
fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n");
exit(2);
}
conn->url = strdup(url);
curl_easy_setopt(conn->easy, CURLOPT_URL, conn->url);
curl_easy_setopt(conn->easy, CURLOPT_WRITEFUNCTION, write_cb);
- curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, &conn);
+ curl_easy_setopt(conn->easy, CURLOPT_WRITEDATA, conn);
curl_easy_setopt(conn->easy, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(conn->easy, CURLOPT_ERRORBUFFER, conn->error);
curl_easy_setopt(conn->easy, CURLOPT_PRIVATE, conn);
s[0]='\0';
rv=fscanf(g->input, "%1023s%n", s, &n);
s[n]='\0';
- if ( n && s[0] ) {
- new_conn(s,arg); /* if we read a URL, go get it! */
- } else break;
- } while ( rv != EOF);
+ if(n && s[0]) {
+ new_conn(s, arg); /* if we read a URL, go get it! */
+ }
+ else
+ break;
+ } while(rv != EOF);
}
/* Create a named pipe and tell libevent to monitor it */
curl_socket_t sockfd;
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
- if (lstat (fifo, &st) == 0) {
- if ((st.st_mode & S_IFMT) == S_IFREG) {
+ if(lstat (fifo, &st) == 0) {
+ if((st.st_mode & S_IFMT) == S_IFREG) {
errno = EEXIST;
perror("lstat");
exit (1);
}
}
unlink(fifo);
- if (mkfifo (fifo, 0600) == -1) {
+ if(mkfifo (fifo, 0600) == -1) {
perror("mkfifo");
exit (1);
}
sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0);
- if (sockfd == -1) {
+ if(sockfd == -1) {
perror("open");
exit (1);
}