Re: recvfrom() strange operation
- From: kzsolt@xxxxxxxxxx
- Date: 8 Sep 2006 03:11:54 -0700
So gentlemans first thank you for all of the answers!
"Any reason not go always supply a buffer at least as big as your
datagram?"
Our application is a reliable protocol running in separated threads and
theoretically working over TCP and UDP too. If I have no chance to
retrive packet content by bytes then the only way is implement
additional buffering. But this buffering is triple buffering in our
stack instead of double buffering. This cost mouch CPU and time too.
And of course I write the same algorithm already in the kernel...
No matter the data arrived over TCP or UDP, arrived in packet (more
than one octett units). In case of TCP implement buffering and I can
retrive packet data as byte, but in case of UDP not. I think the
buffering calls missing from the UDP path.
steve_schefter@xxxxxxxxxxx írta:
kzsolt@xxxxxxxxxx wrote:
Linux SU9.3 I586 K: 2.6.11.4-21.11 / GCC 3.3.5
I send one packet trough SOCK_DGRAM socket (UDP) like this
sendto(sockfd,"abcdefghijklmnop",16,0,xxx,nnn);
On a receiver sied in case of:
recvfrom(sockfd,p,16,0,xxx,nnn);
the p contain "abcdefghijklmnop"
but in case of:
recvfrom(sockfd,p,1,0,xxx,nnn);
recvfrom(sockfd,q,15,0,xxx,nnn);
the p contain "a"
the q is empty (insted of "bcdefghijklmnop")
If I use SOCK_STREAM (TCP) ths same code working fine.
From the recvfrom() man page:If a message is too long to fit in the supplied buffer,
excess bytes may be discarded depending on the type of
socket the message is received from (see socket(2))
and from the socket man page:
SOCK_SEQPACKET sockets employ the same system calls as
SOCK_STREAM sockets. The only difference is that read(2) calls
will return only the amount of data requested, and any remaining in
the arriving packet will be discarded. Also all message boundaries
in incoming datagrams are preserved.
No specific mention of SOCK_DGRAM discarding excess data, but
you emperical evidence would suggest that it does. You'd have to
look at the kernel source to see for sure, but it looks like you can't
control this. Any reason not go always supply a buffer at least
as big as your datagram?
Regards,
Steve
------------------------------------------------------------------------
Steve Schefter phone: +1 705 725 9999 x26
The Software Group Limited fax: +1 705 725 9666
642 Welham Road,
Barrie, Ontario CANADA L4N 9A1 Web: www.wanware.com
.
- Follow-Ups:
- Re: recvfrom() strange operation
- From: steve_schefter
- Re: recvfrom() strange operation
- References:
- recvfrom() strange operation
- From: kzsolt
- Re: recvfrom() strange operation
- From: steve_schefter
- recvfrom() strange operation
- Prev by Date: Re: newbie questions
- Next by Date: Re: Newbie - Optimizing an NFS client
- Previous by thread: Re: recvfrom() strange operation
- Next by thread: Re: recvfrom() strange operation
- Index(es):
Relevant Pages
|