LWN.net Logo

OT

OT

Posted Mar 28, 2006 17:32 UTC (Tue) by tjc (subscriber, #137)
Parent article: The Grumpy Editor's guide to RSS aggregators

This is semi-off-topic, but while on the subject of RSS aggregators, does anyone know how to read data from a socket using recv() without it taking forever? If I OR the MSG_WAITALL flag into the fourth argument of recv(), it takes a long time to return, even if the RSS server is running on localhost. If I don't use the flag, I don't get all the data.

Is there any easy way around this, or do I have to keep track of the number of bytes returned and make multiple attempts?


(Log in to post comments)

OT

Posted Mar 28, 2006 18:48 UTC (Tue) by guinan (subscriber, #4644) [Link]

You have to keep track of the number of bytes returned and make multiple attempts. When things go through network transports (even localhost) you'll get things in chunks corresponding to 1 or more packets.

I usually write a wrapper function around recv() to keep the calling code simple.

OT

Posted Mar 28, 2006 21:10 UTC (Tue) by tjc (subscriber, #137) [Link]

You have to keep track of the number of bytes returned and make multiple attempts. [snip] I usually write a wrapper function around recv() to keep the calling code simple.
Thanks for the reply. Would you mind sharing this wrapper function? It would save me some debugging time.

OT

Posted Mar 29, 2006 20:24 UTC (Wed) by guinan (subscriber, #4644) [Link]

I don't mind sharing, but are you writing in C, Python, other?

Do you know ahead of time how many bytes you want to receive?

If the length is embedded in the data stream, you might as well recv() as much as you can, to avoid extra system calls. But if there's another message behind the first one, you might end up reading into that, in which case you should keep ahold of the "remainder" for the next call.

Email me guinan@bluebutton.com if you want to take it offline.

OT

Posted Mar 28, 2006 22:21 UTC (Tue) by lutchann (subscriber, #8872) [Link]

Well, do you want recv() to return the contents of the socket receive buffer and then return immediately, or do you want it to wait until it has enough received data to fill your entire buffer? Is there some other behavior you're looking for? I'm not sure what that would be...

OT

Posted Mar 28, 2006 22:25 UTC (Tue) by lutchann (subscriber, #8872) [Link]

I took a look at your code since you posted it below; I think maybe you want to change your HTTP request to use "Connection: close" instead.

OT

Posted Mar 29, 2006 2:54 UTC (Wed) by tjc (subscriber, #137) [Link]

I think maybe you want to change your HTTP request to use "Connection: close" instead.
That didn't seem to help. Thanks or the suggestion though; I will keep playing with it. It's probably a combination of things.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds