From owner-freebsd-net@FreeBSD.ORG Fri May 27 23:43:28 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 4628316A41C; Fri, 27 May 2005 23:43:28 +0000 (GMT) (envelope-from pheerboth@apple.com) Received: from mail-out3.apple.com (mail-out3.apple.com [17.254.13.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 06BF943D48; Fri, 27 May 2005 23:43:27 +0000 (GMT) (envelope-from pheerboth@apple.com) Received: from mailgate1.apple.com (a17-128-100-225.apple.com [17.128.100.225]) by mail-out3.apple.com (8.12.11/8.12.11) with ESMTP id j4RNhR8S011191; Fri, 27 May 2005 16:43:27 -0700 (PDT) Received: from relay1.apple.com (relay1.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.3.17) with ESMTP id ; Fri, 27 May 2005 16:43:27 -0700 Received: from [17.206.48.62] (heerboth2.apple.com [17.206.48.62]) by relay1.apple.com (8.12.11/8.12.11) with ESMTP id j4RNhOvW014479 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT); Fri, 27 May 2005 16:43:25 -0700 (PDT) In-Reply-To: <37273927050526180026d23c7d@mail.gmail.com> References: <3727392705052613381067f2a2@mail.gmail.com> <4296410C.1020108@chiaro.com> <3727392705052617366706577c@mail.gmail.com> <37273927050526180026d23c7d@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v730) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Pete Heerboth Date: Fri, 27 May 2005 16:43:23 -0700 To: Aziz Kezzou X-Mailer: Apple Mail (2.730) Cc: dave baukus , freebsd-hackers , freebsd-net Subject: Re: Pseudo-device driver & select ?? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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 23:43:28 -0000 You might want to take a look at the bpf pseudo device and how it handles polls int bpf.c. You need to use the selrecord() and selwakeup() functions. Check out: http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/net/ On May 26, 2005, at 6:00 PM, Aziz Kezzou wrote: >>> >>> 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; >> } >> >> > > 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 ? > 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" >