MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / fileTransfer

Function fileTransfer

cmake/Windows/Contrib/Inetc/inetc.cpp:361–425  ·  view source on GitHub ↗

* FUNCTION NAME: fileTransfer() * PURPOSE: * http/ftp file transfer itself * for any protocol and both directions I guess * SPECIAL CONSIDERATIONS: * *****************************************************/

Source from the content-addressed store, hash-verified

359*
360*****************************************************/
361void fileTransfer(HANDLE localFile,
362 HINTERNET hFile)
363{
364 static BYTE data_buf[1024*8];
365 BYTE *dw;
366 DWORD rslt = 0;
367 DWORD bytesDone;
368
369 status = ST_DOWNLOAD;
370 while(status == ST_DOWNLOAD)
371 {
372 if(fput)
373 {
374 if(!ReadFile(localFile, data_buf, rslt = sizeof(data_buf), &bytesDone, NULL))
375 {
376 status = ERR_FILEREAD;
377 break;
378 }
379 if(bytesDone == 0) // EOF reached
380 {
381 status = ST_OK;
382 break;
383 }
384 while(bytesDone > 0)
385 {
386 dw = data_buf;
387 if(!InternetWriteFile(hFile, dw, bytesDone, &rslt) || rslt == 0)
388 {
389 status = ERR_TRANSFER;
390 break;
391 }
392 dw += rslt;
393 cnt += rslt;
394 bytesDone -= rslt;
395 }
396 }
397 else
398 {
399 if(!InternetReadFile(hFile, data_buf, sizeof(data_buf), &rslt))
400 {
401 status = ERR_TRANSFER;
402 break;
403 }
404 if(rslt == 0) // EOF reached or cable disconnect
405 {
406// on cable disconnect returns TRUE and 0 bytes. is cnt == 0 OK (zero file size)?
407// cannot check this if reply is chunked (no content-length, http 1.1)
408 status = (fs != NOT_AVAILABLE && cnt < fs) ? ERR_TRANSFER : ST_OK;
409 break;
410 }
411 if(szToStack)
412 {
413 for (DWORD i = 0; cntToStack < g_stringsize && i < rslt; i++, cntToStack++)
414 *(szToStack + cntToStack) = data_buf[i];
415 }
416 else if(!WriteFile(localFile, data_buf, rslt, &bytesDone, NULL) ||
417 rslt != bytesDone)
418 {

Callers 1

inetTransferFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected