From owner-svn-src-head@freebsd.org Wed Aug 5 07:34:31 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 497DD9B2FDF; Wed, 5 Aug 2015 07:34:31 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 20505DAE; Wed, 5 Aug 2015 07:34:31 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t757YUGZ084301; Wed, 5 Aug 2015 07:34:30 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t757YUnY084298; Wed, 5 Aug 2015 07:34:30 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201508050734.t757YUnY084298@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Wed, 5 Aug 2015 07:34:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286307 - in head: lib/libc/sys sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Aug 2015 07:34:31 -0000 Author: ed Date: Wed Aug 5 07:34:29 2015 New Revision: 286307 URL: https://svnweb.freebsd.org/changeset/base/286307 Log: Make it possible to implement poll(2) on top of kqueue(2). It looks like EVFILT_READ and EVFILT_WRITE trigger under the same conditions as poll()'s POLLRDNORM and POLLWRNORM as described by POSIX. The only difference is that POLLRDNORM has to be triggered on regular files unconditionally, whereas EVFILT_READ only triggers when not EOF. Introduce a new flag, NOTE_FILE_POLL, that can be used to make EVFILT_READ and EVFILT_WRITE behave identically to poll(). This flag will be used by cloudlibc's poll() function. Reviewed by: jmg Differential Revision: https://reviews.freebsd.org/D3303 Modified: head/lib/libc/sys/kqueue.2 head/sys/kern/vfs_subr.c head/sys/sys/event.h Modified: head/lib/libc/sys/kqueue.2 ============================================================================== --- head/lib/libc/sys/kqueue.2 Wed Aug 5 07:29:59 2015 (r286306) +++ head/lib/libc/sys/kqueue.2 Wed Aug 5 07:34:29 2015 (r286307) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 29, 2015 +.Dd August 4, 2015 .Dt KQUEUE 2 .Os .Sh NAME @@ -288,6 +288,14 @@ Returns when the file pointer is not at .Va data contains the offset from current position to end of file, and may be negative. +.Pp +This behavior is different from +.Xr poll 2 , +where read events are triggered for regular files unconditionally. +This event can be triggered unconditionally by setting the +.Dv NOTE_FILE_POLL +flag in +.Va fflags . .It "Fifos, Pipes" Returns when the there is data to read; .Va data Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Wed Aug 5 07:29:59 2015 (r286306) +++ head/sys/kern/vfs_subr.c Wed Aug 5 07:34:29 2015 (r286307) @@ -4622,7 +4622,7 @@ filt_vfsread(struct knote *kn, long hint VI_LOCK(vp); kn->kn_data = va.va_size - kn->kn_fp->f_offset; - res = (kn->kn_data != 0); + res = (kn->kn_sfflags & NOTE_FILE_POLL) != 0 || kn->kn_data != 0; VI_UNLOCK(vp); return (res); } Modified: head/sys/sys/event.h ============================================================================== --- head/sys/sys/event.h Wed Aug 5 07:29:59 2015 (r286306) +++ head/sys/sys/event.h Wed Aug 5 07:34:29 2015 (r286307) @@ -108,6 +108,7 @@ struct kevent { * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace */ #define NOTE_LOWAT 0x0001 /* low water mark */ +#define NOTE_FILE_POLL 0x0002 /* behave like poll() */ /* * data/hint flags for EVFILT_VNODE, shared with userspace