Unix Programming - Re: recv() - How do you know the length of buffer that you are going

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2005 > Re: recv() - How do you know the length of buffer that you are going





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: recv() - How do you know the length of buffer that you are going
Nils O. Selåsdal

2005-12-19, 7:49 am

Steven wrote:
> So sizeof() should be used in the 3rd param of send() too?

It is how much data you want to receive. You have to decide. Often
based on an application protocol.

char buf[512];
recv(fd,buf,sizeof buf); /*sizeof, sure why not */
ofcourse you check the return value of recv to know
how much you actually received.

or how about

....
if((sofar+ chunksize*2) > (sofar+chunksize+1)/chunksize)*chunksize)
buf = realloc(buf,sofar+chunksize); /*leak if we fail*/
ret = recv(fd,buf+sofar,chunksize);
if(ret > 0)
sofar += ret;

So, not just sizeof
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com