1/* 2 * Copyright 2010 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Christophe Huriaux, c.huriaux@gmail.com 7 */ 8 9#include <cstdio> 10 11#include <UrlSynchronousRequest.h> 12 13#define PRINT(x) printf x; 14 15 16BUrlSynchronousRequest::BUrlSynchronousRequest(BUrl& url) 17 : 18 BUrlRequest(url, this), 19 fRequestComplete(false) 20{ 21} 22 23 24status_t 25BUrlSynchronousRequest::Perform() 26{ 27 SetProtocolListener(this); 28 fRequestComplete = false; 29 30 return BUrlRequest::Perform(); 31} 32 33 34status_t 35BUrlSynchronousRequest::WaitUntilCompletion() 36{ 37 while (!fRequestComplete) 38 snooze(10000); 39 40 return B_OK; 41} 42 43 44void 45BUrlSynchronousRequest::ConnectionOpened(BUrlProtocol*) 46{ 47 PRINT(("SynchronousRequest::ConnectionOpened()\n")); 48} 49 50 51void 52BUrlSynchronousRequest::HostnameResolved(BUrlProtocol*, const char* ip) 53{ 54 PRINT(("SynchronousRequest::HostnameResolved(%s)\n", ip)); 55} 56 57 58void 59BUrlSynchronousRequest::ResponseStarted(BUrlProtocol*) 60{ 61 PRINT(("SynchronousRequest::ResponseStarted()\n")); 62} 63 64 65void 66BUrlSynchronousRequest::HeadersReceived(BUrlProtocol*) 67{ 68 PRINT(("SynchronousRequest::HeadersReceived()\n")); 69} 70 71 72void 73BUrlSynchronousRequest::DataReceived(BUrlProtocol*, const char*, 74 ssize_t size) 75{ 76 PRINT(("SynchronousRequest::DataReceived(%zd)\n", size)); 77} 78 79 80void 81BUrlSynchronousRequest::DownloadProgress(BUrlProtocol*, 82 ssize_t bytesReceived, ssize_t bytesTotal) 83{ 84 PRINT(("SynchronousRequest::DownloadProgress(%zd, %zd)\n", bytesReceived, 85 bytesTotal)); 86} 87 88 89void 90BUrlSynchronousRequest::UploadProgress(BUrlProtocol*, ssize_t bytesSent, 91 ssize_t bytesTotal) 92{ 93 PRINT(("SynchronousRequest::UploadProgress(%zd, %zd)\n", bytesSent, 94 bytesTotal)); 95} 96 97 98void 99BUrlSynchronousRequest::RequestCompleted(BUrlProtocol* caller, bool success) 100{ 101 PRINT(("SynchronousRequest::RequestCompleted(%s) : %s\n", (success?"true":"false"), 102 caller->StatusString(caller->Status()))); 103 fRequestComplete = true; 104} 105