Re: recvfrom() strange operation
- From: steve_schefter@xxxxxxxxxxx
- Date: 7 Sep 2006 10:31:56 -0700
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.
If a message is too long to fit in the supplied buffer,From the recvfrom() man page:
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: kzsolt
- Re: recvfrom() strange operation
- References:
- recvfrom() strange operation
- From: kzsolt
- recvfrom() strange operation
- Prev by Date: Re: recvfrom() strange operation
- Next by Date: Using virtual machines as device drivers?
- Previous by thread: Re: recvfrom() strange operation
- Next by thread: Re: recvfrom() strange operation
- Index(es):