[mingw - C/C++] socket - slow FTP download.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[mingw - C/C++] socket - slow FTP download.

SourceForge.net

Read and respond to this message at:
https://sourceforge.net/forum/message.php?msg_id=3209318
By: brunoc0pa

Hi,

I?m coding a simple FTP client, compiling with Mingw 4.0.5 Alpha, and I noticed
that downloads of files greather than 1Mb are very slow. The function for receiving
data is:

int ftpreceive_file_data(int ftpSocket, char *recebe, int tam, char caminho[])
{
  int rval;
  FILE *arq;

  if ((arq = fopen(caminho,"wb")) == NULL)
  {
        printf("Erro ao criar arquivo %s\n", caminho);
        return(-1);
  }  

  if(recebe == NULL)
  {
     printf("Erro! Buffer nao alocado.\n");
     return 0;
  }

  while( 1 )
  {
     memset(recebe,'\0', tam);

     if ((rval = recv(ftpSocket,recebe,tam, 0)) < 0)
     {
        perror("recv()");
        fclose(arq);
        close(ftpSocket);
        return(-1);
     }
     else if( rval == 0 )
        break;
     else
        fwrite(recebe,sizeof(char),rval,arq);
  }

  fclose(arq);
  return rval;
} //end ftprecebe

What I?m doing wrong? Frequently my downloads are very slow, using this
function.

Can anyone help me to improve the download speed?

Best Regards,
         Bruno

______________________________________________________________________
You are receiving this email because you elected to monitor this forum.
To stop monitoring this forum, login to SourceForge.net and visit:
https://sourceforge.net/forum/unmonitor.php?forum_id=286529


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: [mingw - C/C++] socket - slow FTP download.

Mark Junker
SourceForge.net schrieb:

>Can anyone help me to improve the download speed?
>  
>
Try receiving smaller chunks.
It seems to be an effect of the Heap*() functions that get slower and
slower for larger memory areas (AFAIK 4MB but you might notice a
slowdown with a 1MB size too). Normally, the reason for such a slowdown
is either a bug or permanent memory reallocations to enlarge the buffer.

Regards,
Mark



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users