public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: lkml@pengaru.com
To: linux-kernel@vger.kernel.org
Subject: Honoring SO_RCVLOWAT in proto_ops.poll methods
Date: Sat, 20 Sep 2008 16:42:29 -0500	[thread overview]
Message-ID: <20080920214229.GP2761@fc6222126.aspadmin.net> (raw)

Hello lkml,

I have a need for select/poll/epoll_wait to block on sockets which have
unread data sitting in the receive buffer with a quantity less than
specified via setsockopt() w/SO_RCVLOWAT, not less than one like the
current implementation.

Upon looking at the code in net/ipv4/tcp.c it doesn't look like this
would be difficult to support.  Something along the lines of changing
the function tcp_poll() of version 2.6.26.5 from doing this:

 394                 if ((tp->rcv_nxt != tp->copied_seq) &&
 395                     (tp->urg_seq != tp->copied_seq ||
 396                      tp->rcv_nxt != tp->copied_seq + 1 ||
 397                      sock_flag(sk, SOCK_URGINLINE) || !tp->urg_data))
 398                         mask |= POLLIN | POLLRDNORM;

to this:

 394                 if ((tp->rcv_nxt != tp->copied_seq) &&
 395                     (tp->urg_seq != tp->copied_seq ||
 396                      tp->rcv_nxt > tp->copied_seq + sk->sk_rcvlowat ||
 397                      sock_flag(sk, SOCK_URGINLINE) || !tp->urg_data))
 398                         mask |= POLLIN | POLLRDNORM;


I imagine it's similarly simple for the other socket types.  Am I
missing something?  Is there a technical reason why Linux only blocks in
read/recv but not the poll with respect to the SO_RCVLOWAT setting?


For those interested the application is basically doing:

1: Wait for input on active sockets with epoll_wait()
2: Recv() data off the eventful sockets with MSG_PEEK flag, parse contents
   looking for specific keyword and value from buffer.
3: If buffer is too short call setsockopt() with SO_RCVLOWAT parameter set
   greater than what recv() with MSG_PEEK returned.

Repeat @ 1 until finding what's needed or shutdown/error/timeout.

Once the value is parsed it's used as an address to locate (with a db
lookup) a path which would be a unix domain socket for passing the
socket descriptor through.  The unrelated process at the other end needs
to accept the descriptor and use it as if no other program mucked with it
hence the MSG_PEEK magic.

As-is I must basically tie up threads in blocked recv() calls after
increasing SO_RCVLOWAT if the first recv() peek falls short.  This
solution obviously doesn't scale well.

Thanks,
Vito Caputo

             reply	other threads:[~2008-09-20 21:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-20 21:42 lkml [this message]
2008-09-20 22:21 ` Honoring SO_RCVLOWAT in proto_ops.poll methods David Miller
2008-09-20 23:00   ` lkml
2008-09-21  9:24     ` lkml
2008-09-21 14:18       ` Alan Cox
     [not found]         ` <20080921145134.GT2761@fc6222126.aspadmin.net>
2008-09-21 20:13           ` Alan Cox
2008-09-21 22:09             ` lkml
2008-10-05 20:27               ` David Miller
2008-10-05 21:45                 ` swivel
2008-10-05 22:30                   ` David Miller
2008-10-06  5:17                     ` lkml
2008-10-06 17:18                       ` David Miller
2008-10-06 17:45                         ` David Miller
2008-10-13  7:34                     ` David Miller
2008-10-13  8:32                       ` swivel
2008-10-13  9:58                         ` David Miller
2008-10-20  3:58                           ` swivel
2008-10-20  4:25                             ` David Miller
2008-11-05 11:36                             ` David Miller
2008-09-22 12:15             ` David Miller

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=20080920214229.GP2761@fc6222126.aspadmin.net \
    --to=lkml@pengaru.com \
    --cc=linux-kernel@vger.kernel.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