| 137 | return true; |
| 138 | } |
| 139 | void HttpClient::HttpThreadProc |
| 140 | ( |
| 141 | Event* _exitEvent, |
| 142 | void* _context |
| 143 | ) |
| 144 | { |
| 145 | HttpClient *client = (HttpClient *)_context; |
| 146 | client->m_httpThreadRunning = true; |
| 147 | |
| 148 | SimpleHTTPClient::InitNetwork(); |
| 149 | bool keepgoing = true; |
| 150 | while( keepgoing ) |
| 151 | { |
| 152 | const uint32 count = 2; |
| 153 | |
| 154 | Wait* waitObjects[count]; |
| 155 | |
| 156 | int32 timeout = Wait::Timeout_Infinite; |
| 157 | timeout = 10000; |
| 158 | |
| 159 | waitObjects[0] = client->m_exitEvent; // Thread must exit. |
| 160 | waitObjects[1] = client->m_httpDownloadEvent; // Http Request |
| 161 | // Wait for something to do |
| 162 | |
| 163 | int32 res = Wait::Multiple( waitObjects, count, timeout ); |
| 164 | |
| 165 | switch (res) { |
| 166 | case -1: /* timeout */ |
| 167 | Log::Write(LogLevel_Info, "HttpThread Exiting. No Transfers in timeout period"); |
| 168 | keepgoing = false; |
| 169 | break; |
| 170 | case 0: /* exitEvent */ |
| 171 | Log::Write(LogLevel_Info, "HttpThread Exiting."); |
| 172 | keepgoing = false; |
| 173 | break; |
| 174 | case 1: /* HttpEvent */ |
| 175 | HttpDownload *download; |
| 176 | { |
| 177 | LockGuard LG(client->m_httpMutex); |
| 178 | download = client->m_httpDownlist.front(); |
| 179 | client->m_httpDownlist.pop_front(); |
| 180 | if (client->m_httpDownlist.empty()) |
| 181 | client->m_httpDownloadEvent->Reset(); |
| 182 | } |
| 183 | Log::Write(LogLevel_Debug, "Download Starting for %s (%s)", download->url.c_str(), download->filename.c_str()); |
| 184 | SimpleHTTPClient::HttpSocket *ht = new SimpleHTTPClient::HttpSocket(); |
| 185 | ht->SetKeepAlive(0); |
| 186 | ht->SetBufsizeIn(64 * 1024); |
| 187 | ht->SetDownloadFile(download->filename); |
| 188 | ht->Download(download->url); |
| 189 | while (ht->isOpen()) |
| 190 | ht->update(); |
| 191 | |
| 192 | if (ht->IsSuccess()) |
| 193 | download->transferStatus = HttpDownload::Ok; |
| 194 | else |
| 195 | download->transferStatus = HttpDownload::Failed; |
| 196 | delete ht; |
nothing calls this directly
no test coverage detected