LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2009, 08:14 AM   #1
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
Can't make SO_RCVLOWAT socket option working under LINUX?


Hello,

I want to unlock the "recv" call on an UDP socket when at least 32kbytes of data are available, to do so I make:
Code:
int arg = 32768;
setsockopt (socket_id, SOL_SOCKET, SO_RCVLOWAT, &arg, sizeof (arg));
but, if I display the return value of
Code:
char buffer[65536];
bytes = recv (socket_id, buffer, 65536, MSG_WAITALL);
printf ("%d bytes received\n", bytes);
I can see that I'm always getting out of "recv" with 1476 bytes available, which is one datagram size (datagrams aren't fragmented and I can't increase their size on the sending side)!
How can I get several datagrams with only one "recv" call, if it's not with the SO_RCVLOWAT socket option? Any idea?

remark: my linux kernel version is 2.6.26.8-57.fc8

Thank you for reading.

Last edited by jf.argentino; 09-03-2009 at 08:15 AM. Reason: bad end code balise
 
Old 09-03-2009, 09:00 AM   #2
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by jf.argentino View Post
Hello,

I want to unlock the "recv" call on an UDP socket when at least 32kbytes of data are available, to do so I make:
Code:
int arg = 32768;
setsockopt (socket_id, SOL_SOCKET, SO_RCVLOWAT, &arg, sizeof (arg));
but, if I display the return value of
Code:
char buffer[65536];
bytes = recv (socket_id, buffer, 65536, MSG_WAITALL);
printf ("%d bytes received\n", bytes);
I don't think these options mean what you think they mean. MSG_WAITALL is certainly only useful on a stream socket, where datagram boundaries are not the same as message boundaries.

Quote:
I can see that I'm always getting out of "recv" with 1476 bytes available, which is one datagram size (datagrams aren't fragmented and I can't increase their size on the sending side)!

How can I get several datagrams with only one "recv" call, if it's not with the SO_RCVLOWAT socket option? Any idea?
In short: you can't. In datagram sockets, a packet is a message. You could possibly ip fragment, but that usually never works the way you want it to work in a live net.

You might look into packet_mmap. It's not exactly multiple datagrams in one recv, but I'm guessing that you're trying to avoid lots of context switching. packet_mmap is a shared buffer between user and kernel space for receiving packets which has no context copying, and minimal structure overhead.
 
Old 09-03-2009, 09:51 AM   #3
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Original Poster
Rep: Reputation: 50
Quote:
You might look into packet_mmap. It's not exactly multiple datagrams in one recv, but I'm guessing that you're trying to avoid lots of context switching.
Yes my purpose is to avoid context switching, i'll take a look at packet_mmap asap. Thank you
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a socket available ... wangjinyi Programming 3 11-28-2005 06:24 PM
Asking again.... Does anyone know how '-j' option in make works tuxfood Programming 1 04-20-2005 09:55 AM
need help finding wifi option in make menuconfig and cant get orinoco pcmcia working hotgirl101 Linux - Software 2 04-05-2004 06:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration