Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / libtest / lib556.c
blob2394e736e4806b21c4726d8cc6e9bfc64daf212f
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib556.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
9 */
11 #include "test.h"
13 int test(char *URL)
15 CURLcode res;
16 CURL *curl;
18 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
19 fprintf(stderr, "curl_global_init() failed\n");
20 return TEST_ERR_MAJOR_BAD;
23 if ((curl = curl_easy_init()) == NULL) {
24 fprintf(stderr, "curl_easy_init() failed\n");
25 curl_global_cleanup();
26 return TEST_ERR_MAJOR_BAD;
29 curl_easy_setopt(curl, CURLOPT_URL, URL);
30 curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
32 res = curl_easy_perform(curl);
34 if(!res) {
35 /* we are connected, now get a HTTP document the raw way */
36 const char *request = "GET /556 HTTP/1.2\r\n"
37 "Host: ninja\r\n\r\n";
38 size_t iolen;
39 char buf[1024];
41 res = curl_easy_send(curl, request, strlen(request), &iolen);
43 if(!res) {
44 /* we assume that sending always work */
45 int total=0;
47 do {
48 /* busy-read like crazy */
49 res = curl_easy_recv(curl, buf, 1024, &iolen);
51 if(iolen)
52 /* send received stuff to stdout */
53 write(STDOUT_FILENO, buf, iolen);
55 total += iolen;
57 } while(((res == CURLE_OK) || (res == CURLE_AGAIN)) && (total < 129));
62 curl_easy_cleanup(curl);
63 curl_global_cleanup();
65 return (int)res;