Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 May 2005 20:36:21 -0400
From:      Aziz Kezzou <french.linuxian@gmail.com>
To:        dave baukus <dbaukus@chiaro.com>,  freebsd-hackers <freebsd-hackers@freebsd.org>,  freebsd-net <freebsd-net@freebsd.org>
Subject:   Re: Pseudo-device driver & select ??
Message-ID:  <3727392705052617366706577c@mail.gmail.com>
In-Reply-To: <4296410C.1020108@chiaro.com>
References:  <3727392705052613381067f2a2@mail.gmail.com> <4296410C.1020108@chiaro.com>

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



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