Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 06 Nov 2012 11:57:06 +0400
From:      Andrey Zonov <zont@FreeBSD.org>
To:        Alfred Perlstein <alfred@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   Re: svn commit: r242637 - in user/alfred/so_discard/sys: kern sys
Message-ID:  <5098C2D2.5060002@FreeBSD.org>
In-Reply-To: <201211060008.qA6089AQ024990@svn.freebsd.org>
References:  <201211060008.qA6089AQ024990@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5098C2D2.5060002>