Re: Linux recvfrom() broken (was: DNS problems)

Perry Harrington (pedward@sun4.apsoft.com)
Tue, 18 Aug 1998 15:30:47 -0700 (PDT)


>
> It strikes me as semantically surprising to have a "bytes-received" value
> returned into user space that is greater than the supplied buffer length as
> it breaks the most I/O common coding constructs. But as you say, maybe 1003.1g
> had other considerations on their mind.
>

Like packet blocking? You get a fragment, you know how much to ask for to make it
whole. Then you don't get more data than is needed, and have another fragmented
packet to block.

Seems simple enough to implement:

int bytes_recvd, i, buf_size = BUF_CONSTANT;
char *buffer;

buffer=malloc(buf_size);

bytes_recvd = recvfrom(fd, buffer, buf_size);

if (bytes_recvd > buf_size) {
buffer = realloc(buffer, buf_recvd);

i = buf_size;
buf_size = bytes_recvd;

bytes_recvd = recvfrom(fd, buffer + i, bytes_recvd - i);

}

Compare that with:

int bytes_recvd;
char buffer[BUF_CONSTANT], *packet;
static leftovers[BUF_CONSTANT];
int fetched_some=0;

fetchmore:

bytes_recvd = recvfrom(fd, buffer, BUF_CONSTANT);

if (bytes_recvd == BUF_CONSTANT) { /* assume not EOP */

packet = malloc(bytes_recvd);

memcpy(packet, buffer, bytes_recvd);

fetchedsome = 1;

goto fetchmore;
} else {
if (fetchedsome) {
...
}
}

I'm too lazy to complete the other case scenario.

>
> Regards.
>

--Perry

-- 
Perry Harrington       Linux rules all OSes.    APSoft      ()
email: perry@apsoft.com 			Think Blue. /\

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html