Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
a95df824
Commit
a95df824
authored
21 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
Henrik Storner's rewrite that includes a nice usage of curl_multi_info_read()
parent
8feb5110
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/examples/multi-app.c
+40
-11
40 additions, 11 deletions
docs/examples/multi-app.c
with
40 additions
and
11 deletions
docs/examples/multi-app.c
+
40
−
11
View file @
a95df824
...
...
@@ -23,29 +23,38 @@
/*
* Download a HTTP file and upload an FTP file simultaneously.
*/
#define HANDLECOUNT 2
/* Number of simultaneous transfers */
#define HTTP_HANDLE 0
/* Index for the HTTP transfer */
#define FTP_HANDLE 1
/* Index for the FTP transfer */
int
main
(
int
argc
,
char
**
argv
)
{
CURL
*
http_handle
;
CURL
*
ftp_handle
;
CURL
*
handles
[
HANDLECOUNT
];
CURLM
*
multi_handle
;
int
still_running
;
/* keep number of running handles */
int
i
;
http_handle
=
curl_easy_init
();
ftp_handle
=
curl_easy_init
();
CURLMsg
*
msg
;
/* for picking up messages with the transfer status */
int
msgs_left
;
/* how many messages are left */
/* Allocate one CURL handle per transfer */
for
(
i
=
0
;
i
<
HANDLECOUNT
;
i
++
)
handles
[
i
]
=
curl_easy_init
();
/* set the options (I left out a few, you'll get the point anyway) */
curl_easy_setopt
(
h
ttp_h
andle
,
CURLOPT_URL
,
"http://website.com"
);
curl_easy_setopt
(
handle
s
[
HTTP_HANDLE
]
,
CURLOPT_URL
,
"http://website.com"
);
curl_easy_setopt
(
ftp_
handle
,
CURLOPT_URL
,
"ftp://ftpsite.com"
);
curl_easy_setopt
(
ftp_
handle
,
CURLOPT_UPLOAD
,
TRUE
);
curl_easy_setopt
(
handle
s
[
FTP_HANDLE
]
,
CURLOPT_URL
,
"ftp://ftpsite.com"
);
curl_easy_setopt
(
handle
s
[
FTP_HANDLE
]
,
CURLOPT_UPLOAD
,
TRUE
);
/* init a multi stack */
multi_handle
=
curl_multi_init
();
/* add the individual transfers */
curl_multi_add_handle
(
multi_handle
,
http_handle
);
curl_multi_add_handle
(
multi_handle
,
ftp_
handle
);
for
(
i
=
0
;
i
<
HANDLECOUNT
;
i
++
)
curl_multi_add_handle
(
multi_handle
,
handle
s
[
i
]
);
/* we start some action by calling perform right away */
while
(
CURLM_CALL_MULTI_PERFORM
==
...
...
@@ -91,9 +100,29 @@ int main(int argc, char **argv)
curl_multi_cleanup
(
multi_handle
);
curl_easy_cleanup
(
http_handle
);
curl_easy_cleanup
(
ftp_handle
);
/* See how the transfers went */
while
((
msg
=
curl_multi_info_read
(
multi_handle
,
&
msgs_left
)))
{
if
(
msg
->
msg
==
CURLMSG_DONE
)
{
int
idx
,
found
=
0
;
/* Find out which handle this message is about */
for
(
idx
=
0
;
(
!
found
&&
(
idx
<
HANDLECOUNT
));
idx
++
)
found
=
(
msg
->
easy_handle
==
handles
[
idx
]);
switch
(
idx
)
{
case
HTTP_HANDLE
:
printf
(
"HTTP transfer completed with status %d
\n
"
,
msg
->
data
.
result
);
break
;
case
FTP_HANDLE
:
printf
(
"FTP transfer completed with status %d
\n
"
,
msg
->
data
.
result
);
break
;
}
}
}
/* Free the CURL handles */
for
(
i
=
0
;
i
<
HANDLECOUNT
;
i
++
)
curl_easy_cleanup
(
handles
[
i
]);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment