Date: Tue, 10 Jul 2012 18:22:08 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Volodymyr Kostyrko <c.kworr@gmail.com> Cc: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, freebsd-standards@freebsd.org Subject: Re: kern/149857: [kqueue] kqueue not reporting EOF under certain circumstances Message-ID: <20120710152208.GF2338@deviant.kiev.zoral.com.ua> In-Reply-To: <4FFC441A.2010500@gmail.com> References: <4FFC1D2D.4020405@gmail.com> <20120710140203.GA2338@deviant.kiev.zoral.com.ua> <4FFC39D9.6080809@gmail.com> <20120710142746.GD2338@deviant.kiev.zoral.com.ua> <4FFC441A.2010500@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--ZSoWtPk5XaIUnOQI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 10, 2012 at 06:02:50PM +0300, Volodymyr Kostyrko wrote: > Konstantin Belousov wrote: > >>So you mean this is just my false assumption that EOF _should_ occur on > >>stdin? And it actually occurs only if source is a process which can send > >>EOF? > > > >'Source' cannot be a process. Read filter on pipes can return EV_EOF. > >Read filter on vnodes (read: regular files) does not return EV_EOF, > >except in situation that is created by manual intervention of > >administrator. >=20 > This keeps me puzzled. How then I can tell that file at stdin is already= =20 > at EOF? You mean I should treat stdin like normal vnode-backed file? >=20 > off_t pos =3D 0, endpos; >=20 > lseek(fileno(stdin), 0, SEEK_END); > endpos =3D ftell(stdin); > lseek(fileno(stdin), 0, SEEK_SET); >=20 > ... and then later check it with: >=20 > if(endpos !=3D -1) { > pos +=3D kev.data; > if(pos >=3D endpos) { > printf("end reached\n"); > return(0); > } > } >=20 > Is this a correct way to detect EOF? I'm letting besides that I should=20 > also detect vnode changes and update max file size accordingly. >=20 > >It should have been clear from my previous response. >=20 > Please excuse me, I'm a bit new to this things... Why do you use kqueue there at all ? Just read from stdin, and decide that you hit EOF when read returned 0 bytes. If insisting on using kqueue, which may be ligitimate if you process other sources besides stdin, you should first investigate the nature of the fd 0 using fstat, and then use appropriate code for regular file, pipe and probably socket (e.g. for the case if code allows to run under inetd(8)). --ZSoWtPk5XaIUnOQI Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk/8SJwACgkQC3+MBN1Mb4jqSgCdHgVPqhHwmfHo6xP3bSVIj7LU OoIAnRa30uNLPclEEcXgk17m6VXbU7JG =c8s9 -----END PGP SIGNATURE----- --ZSoWtPk5XaIUnOQI--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120710152208.GF2338>