Skip to contentSkip to conversation

asymmetry with MSG_DONTWAIT in sendmsg() and recvmsg()

DISCUSSION Chris Friesen 5 participants 10 messages Jul 7, 2004 – Jul 8, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I have a SOCK_STREAM PF_UNIX socket with no special options enabled using fcntl().

The default with sendmsg() and recvmsg() is to block.

With sndmsg(), I can use the MSG_DONTWAIT flag to enable non-blocking operation for that one call.

How do I do the equivalent for recvmsg()?

Thanks,

Chris

#1 lore raw
Quoted 9 lines

I have a SOCK_STREAM PF_UNIX socket with no special options enabled using fcntl().

The default with sendmsg() and recvmsg() is to block.

With sndmsg(), I can use the MSG_DONTWAIT flag to enable non-blocking operation for that one call.

How do I do the equivalent for recvmsg()?

MSG_DONTWAIT should also work with recvmsg().

Cheers

Signature · 5 lines
Michael Kerrisk
[email protected]

"Sie haben neue Mails!" - Die GMX Toolbar informiert Sie beim Surfen!
Jetzt aktivieren unter http://www.gmx.net/info
#2 lore raw
Quoted 1 line · Michael T Kerrisk

MSG_DONTWAIT should also work with recvmsg().

Hmm... Just tried it with a DGRAM socket, and it seems to work. Any ideas why its not in the man pages?

Chris

#3 lore raw
Quoted 6 lines · Chris Friesen
Quoted 1 line · Michael T Kerrisk

MSG_DONTWAIT should also work with recvmsg().

Hmm... Just tried it with a DGRAM socket, and it seems to work. Any ideas why its not in the man pages?

Nobody ever added it? Just send a patch to [email protected]

-Andi

#4 lore raw
Quoted 10 lines · Andi Kleen
Quoted 5 lines · Chris Friesen
Quoted 1 line · Michael T Kerrisk

MSG_DONTWAIT should also work with recvmsg().

Hmm... Just tried it with a DGRAM socket, and it seems to work. Any

ideas

Quoted 1 line

why its not in the man pages?

Nobody ever added it? Just send a patch to [email protected]

Sending patch as suggested. Fundamentally, the delta is as follows, I've included an attachment with what I hope are the proper formatting codes (copied from send(2)).

recv2.man 2004-07-08 15:47:29.000000000 -0400 renamed from recv.man 2004-07-08 15:43:17.000000000 -0400 +5 -0
@@ -67,6 +67,11 @@
               disconnect occurs, or the next data to be received is of a  dif-
               ferent type than that returned.
 
+       MSG_DONTWAIT
+              Enables  non-blocking  operation;  if the operation would block,
+              EAGAIN is returned (this can also be enabled  using  the  O_NON-
+              BLOCK with the F_SETFL fcntl(2)).
+
        MSG_NOSIGNAL
               This  flag  turns  off raising of SIGPIPE on stream sockets when
               the other end disappears.

Note also that there is a mention of MSG_DONTWAIT in the msg_flags field in the msghdr. It gives the impression that one can *set* that field to cause the non-blocking behaviour. My understanding is that the msg_flags field is a return value only. Perhaps that portion should be reworded as well.

Chris

recv2.man renamed from recv.man +5 -0
@@ -67,6 +67,11 @@
               disconnect occurs, or the next data to be received is of a  dif-
               ferent type than that returned.
 
+       MMSSGG__DDOONNTTWWAAIITT
+              Enables  non-blocking  operation;  if the operation would block,
+              EEAAGGAAIINN is returned (this can also be enabled  using  the  OO__NNOONN--
+              BBLLOOCCKK with the FF__SSEETTFFLL ffccnnttll(2)).
+
        MMSSGG__NNOOSSIIGGNNAALL
               This  flag  turns  off raising of SSIIGGPPIIPPEE on stream sockets when
               the other end disappears.
#5 lore raw
Quoted 28 lines · Chris Friesen
Quoted 3 lines
Quoted 1 line

why its not in the man pages?

Nobody ever added it? Just send a patch to [email protected]

Sending patch as suggested. Fundamentally, the delta is as follows, I've included an attachment with what I hope are the proper formatting codes (copied from send(2)).

recv2.man 2004-07-08 15:47:29.000000000 -0400 renamed from recv.man 2004-07-08 15:43:17.000000000 -0400 +3 -0
@@ -67,6 +67,11 @@
               disconnect occurs, or the next data to be received is of a  
               dif-
               ferent type than that returned.
 
+       MSG_DONTWAIT
+              Enables  non-blocking  operation;  if the operation would 
 block,
+              EAGAIN is returned (this can also be enabled  using  the  

O_NON-

recv2.man 2004-07-08 15:47:29.000000000 -0400 renamed from recv.man 2004-07-08 15:43:17.000000000 -0400 +2 -0
+              BLOCK with the F_SETFL fcntl(2)).
+
        MSG_NOSIGNAL
               This  flag  turns  off raising of SIGPIPE on stream sockets 
               when
               the other end disappears.
Quoted 6 lines

Note also that there is a mention of MSG_DONTWAIT in the msg_flags field in the msghdr. It gives the impression that one can *set* that field to cause the non-blocking behaviour. My understanding is that the msg_flags field is a return value only. Perhaps that portion should be reworded as well.

Chris

Can you find the man-pages-1.67 package and construct a concrete patch?

(Don't know precisely what you want to do. The above gives a filename recv.man, which would be recv.2 in my sources. But there is no MSG_NOSIGNAL in recv.2, only in send.2. The fragment of text that you give occurs already in recv.2.)

Andries

#8 lore raw
In reply to Chris Friesen
Quoted 6 lines · Chris Friesen
Quoted 1 line · Michael T Kerrisk

MSG_DONTWAIT should also work with recvmsg().

Hmm... Just tried it with a DGRAM socket, and it seems to work. Any ideas why its not in the man pages?

Think you are on an older version of the man pages. It's been there for a while.

thanks,
Nivedita

#6 lore raw
In reply to Andries Brouwer
Quoted 6 lines · Andries Brouwer

Can you find the man-pages-1.67 package and construct a concrete patch?

(Don't know precisely what you want to do. The above gives a filename recv.man, which would be recv.2 in my sources. But there is no MSG_NOSIGNAL in recv.2, only in send.2. The fragment of text that you give occurs already in recv.2.)

Sorry, the filenames have no meaning since I wasn't working from the package, but from the output of the "man" command.

Working from the webpage at:

http://homepages.cwi.nl/~aeb/linux/man2html/man2/recv.2.html

There is mention of MSG_DONTWAIT when discussing the "msg_flags" field in "struct msghdr". It contains exactly the text proposed. However, the msg_flags field is set on *return* of the call. Every other flag discussed there "indicates" something. The blurb for MSG_DONTWAIT says that it "enables" a behaviour, which doesn't make sense for a field set on call return.

There is no mention of MSG_DONTWAIT when discussing the "flags" parameter of the recv/recvfrom/recvmsg call.

Generally, I want to move the current blob from the "msg_flags" area to the "flags" area, and then add a different discussion for "msg_flags" if appropriate (I'm not sure about that part).

Do you still want me to generate an actual patch against man-pages-1.67, or is that description enough?

Chris

#9 lore raw
In reply to Nivedita Singhvi
Quoted 11 lines · Nivedita Singhvi
Quoted 7 lines · Chris Friesen
Quoted 1 line · Michael T Kerrisk

MSG_DONTWAIT should also work with recvmsg().

Hmm... Just tried it with a DGRAM socket, and it seems to work. Any ideas why its not in the man pages?

Think you are on an older version of the man pages. It's been there for a while.

It's mentioned in the "msg_flags" section, which is set on call *return*. It's not mentioned in the "flags" section.

Perhaps its just in the wrong part of the man page...

Chris

#7 lore raw
In reply to Chris Friesen
Quoted 11 lines · Chris Friesen
Quoted 6 lines · Andries Brouwer

Can you find the man-pages-1.67 package and construct a concrete patch?

(Don't know precisely what you want to do. The above gives a filename recv.man, which would be recv.2 in my sources. But there is no MSG_NOSIGNAL in recv.2, only in send.2. The fragment of text that you give occurs already in recv.2.)

Working from the webpage at:

http://homepages.cwi.nl/~aeb/linux/man2html/man2/recv.2.html

Ah, that is how I am punished for neglecting to update these html pages :-) Will update them.

I was confused by your MSG_NOSIGNAL, but indeed, that is still on that page, it was removed later.

Have moved the MSG_DONTWAIT part to after the MSG_WAITALL description. [Will still check whether that is really appropriate.]

Thanks!

Andries