MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / HttpThreadProc

Method HttpThreadProc

cpp/src/Http.cpp:139–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 return true;
138}
139void 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;

Callers

nothing calls this directly

Calls 14

InitNetworkFunction · 0.85
WriteFunction · 0.85
StopNetworkFunction · 0.85
SetKeepAliveMethod · 0.80
SetBufsizeInMethod · 0.80
SetDownloadFileMethod · 0.80
DownloadMethod · 0.80
isOpenMethod · 0.80
updateMethod · 0.80
IsSuccessMethod · 0.80
FinishDownloadMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected