From owner-freebsd-net@FreeBSD.ORG Fri May 27 01:00:49 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1D52116A41F for ; Fri, 27 May 2005 01:00:48 +0000 (GMT) (envelope-from french.linuxian@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.192]) by mx1.FreeBSD.org (Postfix) with ESMTP id 523D643D1F for ; Fri, 27 May 2005 01:00:48 +0000 (GMT) (envelope-from french.linuxian@gmail.com) Received: by zproxy.gmail.com with SMTP id 12so159282nzp for ; Thu, 26 May 2005 18:00:47 -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=WCWtoj36cvu2qhCoh1Ns9PFHkh8gM+4pjFJQ9sEhjUYfUyqloLITs2wLu8zfG/4JUZyH+47Is7Pue3K3w2G3W4s33HzT0w9gwcxADDhVOJHjN6MFiKdlVni+ou1DgQtGbOjW2njbNM2Bgj4sx/DheztElkiMF9Mz7AK1e0Mmzes= Received: by 10.36.157.18 with SMTP id f18mr904619nze; Thu, 26 May 2005 18:00:47 -0700 (PDT) Received: by 10.36.58.12 with HTTP; Thu, 26 May 2005 18:00:47 -0700 (PDT) Message-ID: <37273927050526180026d23c7d@mail.gmail.com> Date: Thu, 26 May 2005 21:00:47 -0400 From: Aziz Kezzou To: dave baukus , freebsd-hackers , freebsd-net In-Reply-To: <3727392705052617366706577c@mail.gmail.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> <3727392705052617366706577c@mail.gmail.com> Cc: Subject: Re: Pseudo-device driver & select ?? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Aziz Kezzou List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2005 01:00:49 -0000 > > > > 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/driver= basics-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 dat= a > > > to be read. > > > > > > I looked at the socket code and it looks like I need to provide my ow= n > > > "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, > 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 : >=20 > /* 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", > }; >=20 > with echo_poll : > static int > echo_poll(struct cdev *dev, int events, struct thread *td) > { >=20 > uprintf( "echo_poll called : data_available =3D %d!\n", data_available = ); > if(data_available =3D=3D 0) > return 0; > data_available =3D 0; > return 1; > } >=20 Now the question is, if I don't have any data available when select (i.e d_poll ) is called, how do I notify select when data arrives ? looks like "d_poll" is called only once (the name is a bit misleading here ;-) , isn't it ? Any hints ?=20 Thanks. -aziz