From: bernd@petrovitsch.priv.at (Bernd Petrovitsch)
To: kernelnewbies@lists.kernelnewbies.org
Subject: recvfrom a large packet
Date: Tue, 06 Nov 2012 23:20:26 +0100 [thread overview]
Message-ID: <1352240427.7397.51.camel@thorin> (raw)
In-Reply-To: <CAKop=Lhe_CoWZqWCaxgComtZ6EhLGBFuAVeUOK_-ZYe+dztg6g@mail.gmail.com>
On Die, 2012-11-06 at 16:08 +0200, Victor Buciuc wrote:
> On Tue, Nov 6, 2012 at 1:35 PM, devendra.aaru <devendra.aaru@gmail.com> wrote:
> > if i do a recvfrom (sk, buf, 10000, 0, &addr, &len), shall i recv all the data
> > i mean the 10000 bytes?
Not necessarily. Consider the case that the other side sends only 9000
bytes.
> > since fragmentation happen in the ip layer and assembled happen in the
> > ip layer it doesnt matter for the upper layer about the packet size.
[....]
> > i wrote a test code and it seems to be working.
You tried one case and then you think it is in all cases the same?
You are very optimistic .....
> > is there any problem will come if i turn on firewall.
[...]
Try it. "Turn on firewall" is also not very precise ....
> I think a signal can interrupt recvfrom. If you already had some
> data copied in the buffer then it will return something. You should
No, if a signal interrupts the recvfrom(), recvfrom() returns -1 (and
errno == EINTR).
Thus it cannot report any partially received packet and so there is
nothing written to the buffer.
> always check what you get in the result returned by recvfrom. If
> you're not satisfied with what you got you can always call again. (I
> assumed it's UDP we're talking about).
That is actually the only robust way:
1) append the read data to a buffer
2) check if enough is there to handle a packet. If not goto 1)
3) handle the first packet and delete it.
4) goto 2)
Kind regards,
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
next prev parent reply other threads:[~2012-11-06 22:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-06 11:35 recvfrom a large packet devendra.aaru
2012-11-06 14:08 ` Victor Buciuc
2012-11-06 22:20 ` Bernd Petrovitsch [this message]
2012-11-07 5:09 ` devendra.aaru
2012-11-07 12:15 ` Bernd Petrovitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352240427.7397.51.camel@thorin \
--to=bernd@petrovitsch.priv.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).