BPicture: Fix archive constructor.
[haiku.git] / src / kits / network / libnetapi / UrlSynchronousRequest.cpp
blob859484b993e1c527893958fd5e0db47a2f8c0743
1 /*
2 * Copyright 2010 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Christophe Huriaux, c.huriaux@gmail.com
7 */
9 #include <cstdio>
11 #include <UrlSynchronousRequest.h>
13 #define PRINT(x) printf x;
16 BUrlSynchronousRequest::BUrlSynchronousRequest(BUrlRequest& request)
18 BUrlRequest(request.Url(), NULL, request.Context(),
19 "BUrlSynchronousRequest", request.Protocol()),
20 fRequestComplete(false),
21 fWrappedRequest(request)
26 status_t
27 BUrlSynchronousRequest::Perform()
29 fWrappedRequest.SetListener(this);
30 fRequestComplete = false;
32 thread_id worker = fWrappedRequest.Run();
33 // TODO something to do with the thread_id maybe ?
35 if (worker < B_OK)
36 return worker;
37 else
38 return B_OK;
42 status_t
43 BUrlSynchronousRequest::WaitUntilCompletion()
45 while (!fRequestComplete)
46 snooze(10000);
48 return B_OK;
52 void
53 BUrlSynchronousRequest::ConnectionOpened(BUrlRequest*)
55 PRINT(("SynchronousRequest::ConnectionOpened()\n"));
59 void
60 BUrlSynchronousRequest::HostnameResolved(BUrlRequest*, const char* ip)
62 PRINT(("SynchronousRequest::HostnameResolved(%s)\n", ip));
66 void
67 BUrlSynchronousRequest::ResponseStarted(BUrlRequest*)
69 PRINT(("SynchronousRequest::ResponseStarted()\n"));
73 void
74 BUrlSynchronousRequest::HeadersReceived(BUrlRequest*)
76 PRINT(("SynchronousRequest::HeadersReceived()\n"));
80 void
81 BUrlSynchronousRequest::DataReceived(BUrlRequest*, const char*,
82 off_t, ssize_t size)
84 PRINT(("SynchronousRequest::DataReceived(%zd)\n", size));
88 void
89 BUrlSynchronousRequest::DownloadProgress(BUrlRequest*,
90 ssize_t bytesReceived, ssize_t bytesTotal)
92 PRINT(("SynchronousRequest::DownloadProgress(%zd, %zd)\n", bytesReceived,
93 bytesTotal));
97 void
98 BUrlSynchronousRequest::UploadProgress(BUrlRequest*, ssize_t bytesSent,
99 ssize_t bytesTotal)
101 PRINT(("SynchronousRequest::UploadProgress(%zd, %zd)\n", bytesSent,
102 bytesTotal));
106 void
107 BUrlSynchronousRequest::RequestCompleted(BUrlRequest* caller, bool success)
109 PRINT(("SynchronousRequest::RequestCompleted(%s) : %s\n", (success?"true":"false"),
110 strerror(caller->Status())));
111 fRequestComplete = true;