From owner-svn-src-user@FreeBSD.ORG Tue Nov 6 07:57:13 2012 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 09AF4D21 for ; Tue, 6 Nov 2012 07:57:13 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6FAA28FC16 for ; Tue, 6 Nov 2012 07:57:11 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id e12so134473lag.13 for ; Mon, 05 Nov 2012 23:57:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :x-gm-message-state; bh=oAG94dO31k9Dte2jYTvJLf5xCAEBth4gVk6QL39jGR8=; b=dHF7B+9b3HN6r8GKAYui0BR+QoLoTLOo7iXoLK2ifvmnm7l5d2pBLswPnZE216hvDW +GRnHHzGP+2vi+ik2d1Hssmtt7pe+KUzCZZ8BmlsBtgyGQRZtEKeHEBpvsXbbFWxCFNf MZrx9gwGmleGhsgRgetfkz6eHfMuy83aV5Pvil/xWadA+UF2DkvBWscGEmLhfJceJoVz LxZhfkJp910PWcvwnSJO4H9uVDmBr65C39prHmLQJnA09530X9d8qul+od4GJQ4+gL/B rbcGXaxDYcMWcKmcRvr1vMcmdOWDDkwT8hOcHMkrk2PUfbJPVVVAZywNiI7HEN1yfWOD BElQ== Received: by 10.112.26.131 with SMTP id l3mr164428lbg.26.1352188630787; Mon, 05 Nov 2012 23:57:10 -0800 (PST) Received: from zont-osx.local (ppp95-165-147-157.pppoe.spdop.ru. [95.165.147.157]) by mx.google.com with ESMTPS id fp7sm6478589lab.4.2012.11.05.23.57.09 (version=SSLv3 cipher=OTHER); Mon, 05 Nov 2012 23:57:10 -0800 (PST) Sender: Andrey Zonov Message-ID: <5098C2D2.5060002@FreeBSD.org> Date: Tue, 06 Nov 2012 11:57:06 +0400 From: Andrey Zonov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: Alfred Perlstein Subject: Re: svn commit: r242637 - in user/alfred/so_discard/sys: kern sys References: <201211060008.qA6089AQ024990@svn.freebsd.org> In-Reply-To: <201211060008.qA6089AQ024990@svn.freebsd.org> X-Enigmail-Version: 1.4.5 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig9F46194DB7AF2C0FA2CBD060" X-Gm-Message-State: ALoCoQk84luERYFdIgFkyPCTVu51D3WNNIJ/ACHSN0YY9kdJLxtkQEy1+C041u+c2/DqL5ukElXy Cc: src-committers@freebsd.org, svn-src-user@freebsd.org X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2012 07:57:13 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9F46194DB7AF2C0FA2CBD060 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 11/6/12 4:08 AM, Alfred Perlstein wrote: > Author: alfred > Date: Tue Nov 6 00:08:09 2012 > New Revision: 242637 > URL: http://svnweb.freebsd.org/changeset/base/242637 >=20 > Log: > Implement a socket option SO_DISCARD_RECV, this will discard any > data that arrives. I've found this very useful for testing streaming= > services and want to share it with community as a whole as well as > stash it someplace I can pull up if needed for benching. >=20 > Modified: > user/alfred/so_discard/sys/kern/uipc_socket.c > user/alfred/so_discard/sys/sys/socket.h >=20 > Modified: user/alfred/so_discard/sys/kern/uipc_socket.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- user/alfred/so_discard/sys/kern/uipc_socket.c Tue Nov 6 00:03:53 2= 012 (r242636) > +++ user/alfred/so_discard/sys/kern/uipc_socket.c Tue Nov 6 00:08:09 2= 012 (r242637) > @@ -2479,6 +2479,26 @@ so_setsockopt(struct socket *so, int lev > return (sosetopt(so, &sopt)); > } > =20 > +static int so_discard_rcv_calls; > + > +SYSCTL_INT(_kern_ipc, OID_AUTO, so_discard_rcv_calls, CTLFLAG_RD, > + &so_discard_rcv_calls, 0, "Number of open sockets"); ^^^^^^^^^^^^^^^^^^^^^^ Is the comment correct? > + > + > + > + > +static int > +so_discard_rcv(struct socket *so, void *arg, int waitflag) > +{ > + struct sockbuf *sb; > + > + so_discard_rcv_calls++; It seems this incrementing is not safe in multi-threaded world. > + sb =3D &so->so_rcv; > + SOCKBUF_LOCK_ASSERT(sb); > + sbflush_locked(sb); > + return (SU_OK); > +} > + > int > sosetopt(struct socket *so, struct sockopt *sopt) > { > @@ -2681,7 +2701,31 @@ sosetopt(struct socket *so, struct socko > error =3D EOPNOTSUPP; > #endif > break; > - > + case SO_DISCARD_RECV: { > + struct sockbuf *sb =3D &so->so_rcv; > + error =3D sooptcopyin(sopt, &optval, sizeof optval, > + sizeof optval); > + if (error) > + goto bad; > + SOCKBUF_LOCK(&so->so_rcv); > + if (optval =3D=3D 1) { > + if (sb->sb_upcall !=3D NULL) { > + error =3D EBUSY; > + } else { > + soupcall_set(so, SO_RCV, > + &so_discard_rcv, NULL); > + } > + } else if (optval =3D=3D 0) { > + if (sb->sb_upcall =3D=3D so_discard_rcv) > + soupcall_clear(so, SO_RCV); > + else > + error =3D EINVAL; > + } else { > + error =3D ENOPROTOOPT; > + } > + SOCKBUF_UNLOCK(&so->so_rcv); > + } > + break; > default: > error =3D ENOPROTOOPT; > break; > @@ -2869,6 +2913,10 @@ integer: > optval =3D so->so_incqlen; > goto integer; > =20 > + case SO_DISCARD_RECV: > + optval =3D (so->so_rcv.sb_upcall =3D=3D so_discard_rcv) ? 1 : 0; > + goto integer; > + > default: > error =3D ENOPROTOOPT; > break; >=20 > Modified: user/alfred/so_discard/sys/sys/socket.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- user/alfred/so_discard/sys/sys/socket.h Tue Nov 6 00:03:53 2012 (r= 242636) > +++ user/alfred/so_discard/sys/sys/socket.h Tue Nov 6 00:08:09 2012 (r= 242637) > @@ -140,6 +140,7 @@ typedef __uid_t uid_t; > #define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */ > #define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */ > #define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name)= */ > +#define SO_DISCARD_RECV 0x1017 /* discard recieved data */ > #endif > =20 > /* >=20 --=20 Andrey Zonov --------------enig9F46194DB7AF2C0FA2CBD060 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJQmMLWAAoJEBWLemxX/CvTAp0H/jMsQUZNZoDmkI3p4eYUZCH6 w0cP2jRZfzx4jfgqujr2uOlIQNkhaF8LxnMYKWVLqyjA9W9anSILhO7xTQIcNzuU qFQy+27s5p3J0oeTxnQfj9OYE9jwCuSzKmnvTkM50AQ1o4Ay34DCHv/YOR27m99A 7DcDlJbfVn3377rLZ0wWXURTOrnu3nJCCit+XugK1UoJAHK6eJGoH0SMzDNZhhds 7RKIIZO+QfkXm1qSjLrMubLMMd7W+sCYlTmoYNSuPLzgJHvB+fGns9psa/7H0V3G RR8+ECxvJ9LSVESHghIIoWItPMwJrWvC+hoJys8RiCyS1DW/5zXbH9VYSq+pCS4= =3aaM -----END PGP SIGNATURE----- --------------enig9F46194DB7AF2C0FA2CBD060--