Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #490
| From | jakashthree@gmail.com |
|---|---|
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: Linux equivalent for ioctlsocket(FIONREAD) on datagram sockets |
| Date | 2012-06-28 00:53 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <3fd1b811-0ccb-4466-937c-1b3aafb569cf@googlegroups.com> (permalink) |
| References | <f65e99bb-529d-45e1-b759-cdbc13200033@r18g2000vbi.googlegroups.com> |
On Monday, March 9, 2009 4:16:02 AM UTC-7, already...@yahoo.com wrote:
> Hi
>
> Winsock2 implements two variants of FIONREAD control code which are
> non-trivially different when applied to datagram (UDP) sockets.
> Specifically:
> ioctlsocket(FIONREAD):
> If s is message oriented (for example, type SOCK_DGRAM), FIONREAD
> still returns the amount of pending data in the network buffer,
> however, the amount that can actually be read in a single call to the
> recv function is limited to the data size written in the send or
> sendto function call.
>
> WSAIoctl(FIONREAD):
> If s is message oriented (for example, type SOCK_DGRAM), FIONREAD
> returns the size of the first datagram (message) queued on the
> socket.
>
> According to udp(7) - Linux man page:
> FIONREAD (SIOCINQ) ... returns the size of the next pending datagram
> in the integer in bytes, or 0 when no datagram is pending."
>
> So Linux variant of ioctl(SIOCINQ) is an exact equivalent of Windows
> WSAIoctl(FIONREAD).
>
> Now the question, what is a Linux equivalent for Windows ioctlsocket
> (FIONREAD)?
> Motivation: I want to read as many as possible messages from the
> blocking UDP socket without danger of being blocked.
> On Windows I do something like that (leaving error handling aside for
> sake of brevity):
> select(...)
> ioctlsocket(s, FIONREAD, &nOctets);
> while (nOctets > 0)
> {
> rcvlen = recvfrom(s, ...);
> handle_rx_message();
> nOctets -= rcvlen;
> }
>
> On Linux the code like above produces correct results but it doesn't
> achieve the original goal which is a minimizing the # of system calls.
>
> Regards,
> Michael
Hi, I hope I'm not too late. To set a socket as non-blocking in Linux use fcntl with F_SETFL and O_NONBLOCK. I prefer to do it like this:
fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0) | O_NONBLOCK);
This way, any other flags associated with the socket are preserved.
Back to comp.os.linux.development.apps | Previous | Next | Find similar
Re: Linux equivalent for ioctlsocket(FIONREAD) on datagram sockets jakashthree@gmail.com - 2012-06-28 00:53 -0700
csiph-web