delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/12/20/19:15:52

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Thu, 20 Dec 2007 19:15:30 -0500
From: Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: FW: Combining winpcap packet wait with poll/select in cygwin
Message-ID: <20071221001530.GA28930@ednor.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <BAY128-W147E0BFF22B2B5B0D232D3D25D0 AT phx DOT gbl> <BAY128-W5EB009802E2D5C2A2D722D25E0 AT phx DOT gbl>
MIME-Version: 1.0
In-Reply-To: <BAY128-W5EB009802E2D5C2A2D722D25E0@phx.gbl>
User-Agent: Mutt/1.5.16 (2007-06-09)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Thu, Dec 20, 2007 at 04:04:11PM -0800, S A wrote:
>Hi Brian 
>
>Finally got a change to try this (sorry it tooks so long). It looks like it does NOT work.
>
>The fd returned from cygwin_attach_handle_to_fd() always returns
>from the poll call with a POLLIN event even though no packets
>are flowing on the network (and hence there should be no pcap
>packets received).
>
>The code I used is attached below. I tried both blocking and non blocking
>fcntl calls. But the poll awakes immediately all the time. If I try
>to do a read of the fd, read returns a -1.
>
>I also found another thread:
>http://cygwin.com/ml/cygwin/2006-10/msg00338.html
>
>I didn't know what exactly to pass as the name (i.e. the first argument
>to cygwin_attach_handle_to_fd()) but I tried NULL, "", "/dev/fd").
>
>Maybe I need to pass the right type of device for a windows socket. Just can't
>find what it is. I've looked at all the fhandler_base classes & derivatives
>but can't seem to locate the "name" field. But I don't know C++ that well.
>
>I'd be happy to try any other suggestions. Thanks.
>
>main (int argc, char *argv[])
>{
>  pcap_t *adhandle;
>  int pcap_fd;
>  struct pollfd pcap_pfd;
>  int i, ret;
>
>  [initialization for winpcap adhandle]
>
>  pcap_fd = cygwin_attach_handle_to_fd("/dev/fd", -1, pcap_getevent(adhandle),
>                                       O_BINARY, GENERIC_READ);
>
>  fcntl(pcap_fd, F_SETFL, O_NONBLOCK);
>
>  pcap_pfd.fd = pcap_fd;
>  pcap_pfd.events =  POLLIN;
>  pcap_pfd.revents = 0;

I doubt that a random handle will be selectable.  Cygwin needs to
know specifically what type of device is attached to a handle in
order to emulate select or poll and a raw windows handle is not
apt to work well.

In other words, it's unlikely that you can successfully use the result
of cygwin_attach_handle_to_fd in a select or poll function.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019