From owner-freebsd-hackers@FreeBSD.ORG Fri May 27 00:36:27 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5848616A424 for ; Fri, 27 May 2005 00:36:27 +0000 (GMT) (envelope-from french.linuxian@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id C722343D49 for ; Fri, 27 May 2005 00:36:24 +0000 (GMT) (envelope-from french.linuxian@gmail.com) Received: by zproxy.gmail.com with SMTP id 12so152120nzp for ; Thu, 26 May 2005 17:36:21 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UbxFDzQQAvsYjAaCyT55GDTGLvvF8McY7aqdVMJwOPzWv7KMreRdsa+9akHa3QCSNhTUpnc1f+0RUQsSuw22g3moRp1hH6c4Z67pe34RtUi8G8qzO3dFAzthIzgfQLjMriCun3n+Ipu0/8zMUJ3mQgUN+a8K/0Ve8qFu2vWVnXg= Received: by 10.36.19.12 with SMTP id 12mr902706nzs; Thu, 26 May 2005 17:36:21 -0700 (PDT) Received: by 10.36.58.12 with HTTP; Thu, 26 May 2005 17:36:21 -0700 (PDT) Message-ID: <3727392705052617366706577c@mail.gmail.com> Date: Thu, 26 May 2005 20:36:21 -0400 From: Aziz Kezzou To: dave baukus , freebsd-hackers , freebsd-net In-Reply-To: <4296410C.1020108@chiaro.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <3727392705052613381067f2a2@mail.gmail.com> <4296410C.1020108@chiaro.com> Cc: Subject: Re: Pseudo-device driver & select ?? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Aziz Kezzou List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2005 00:36:27 -0000 >=20 > Aziz Kezzou wrote: > > Hi all, > > I am trying to implement a small kld pseudo-device driver on FreeBSD 5.= 3 that > > behaves just like a socket with regards to the select system call. > > > > Currently, I am using the sample echo pseudo-device driver from > > http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/driverba= sics-char.html > > as an example. However, whenever I call select on the file > > descriptor of "/dev/echo" it always returns even when there is no data > > to be read. > > > > I looked at the socket code and it looks like I need to provide my own > > "fo_select" function in the fileops data structure. Am i right ? How > > do I do that ? The sample echo pseudo-device driver above uses > > "struct cdevsw" instead... > > > > Thanks > > -aziz > > _______________________________________________ > > freebsd-net@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-net > > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" > > > > > look at spec_poll() > I beleive that when your device is opened the fileops{} will > point to the spec ops and you're code will be entered via > spec_poll() - now you just need to implement the poll/select notion > for your device. > =20 Thanks,=20 Actually, il turned out to be very simple. I needed only to provide a "d_poll" function as part of the structure cdevsw, as follows : /* Character device entry points */ static struct cdevsw echo_cdevsw =3D { .d_version =3D D_VERSION, .d_open =3D echo_open, .d_close =3D echo_close, .d_read =3D echo_read, .d_write =3D echo_write, .d_poll =3D echo_poll, .d_name =3D "echo", }; with echo_poll : static=09int echo_poll(struct cdev *dev, int events, struct thread *td) { uprintf( "echo_poll called : data_available =3D %d!\n", data_available ); if(data_available =3D=3D 0) =20 return 0; =20 data_available =3D 0; =20 return 1; }