Re: Pseudo-device driver & select ??

From: Aziz Kezzou (french.linuxian_at_gmail.com)
Date: 05/27/05

  • Next message: Aziz Kezzou: "Re: Pseudo-device driver & select ??"
    Date: Thu, 26 May 2005 20:36:21 -0400
    To: dave baukus <dbaukus@chiaro.com>, freebsd-hackers <freebsd-hackers@freebsd.org>, freebsd-net <freebsd-net@freebsd.org>
    
    

    >
    > 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/driverbasics-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.
    >

    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 :

    /* Character device entry points */
    static struct cdevsw echo_cdevsw = {
        .d_version = D_VERSION,
        .d_open = echo_open,
        .d_close = echo_close,
        .d_read = echo_read,
        .d_write = echo_write,
        .d_poll = echo_poll,
        .d_name = "echo",
    };

    with echo_poll :
    static int
    echo_poll(struct cdev *dev, int events, struct thread *td)
    {

      uprintf( "echo_poll called : data_available = %d!\n", data_available );
      if(data_available == 0)
        return 0;
      data_available = 0;
      return 1;
    }
    _______________________________________________
    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"


  • Next message: Aziz Kezzou: "Re: Pseudo-device driver & select ??"

    Relevant Pages

    • Re: Pseudo-device driver & select ??
      ... >> behaves just like a socket with regards to the select system call. ... >> I looked at the socket code and it looks like I need to provide my own ... echo_poll(struct cdev *dev, int events, struct thread *td) ...
      (freebsd-hackers)
    • sosend/soreceive consistency improvements
      ... There's another side to the pluggability, however -- the socket consumers in the kernel, of which there are quite a few -- obviously the socket system calls, but also netgraph, distributed file systems, etc. ... +sosend_generic(so, addr, uio, top, control, flags, td) ... struct sockaddr *addr; ...
      (freebsd-arch)
    • [RFC] Use RCU for tcp_ehash lookup
      ... RCU technique. ... This could possibly be because the hash table size on the machines I was ... parallel to socket input packet processing. ... struct sk_buff *skb); ...
      (Linux-Kernel)
    • RE: [PATCHv9 3/3] vhost_net: a kernel-level virtio server
      ... Is it the result from the raw socket or through tap? ... struct vhost_dev dev; ... int err, wmem; ... unsigned int next; ...
      (Linux-Kernel)
    • Re: kevent behavior with TCP socket
      ... struct sockaddr_in addr; ... struct kevent sChange; ... printf("Server socket error\n"); ... printf ("Server listen error \n"); ...
      (freebsd-net)