delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/12/20/21:02:02

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <BAY128-W32F9825331F8E2EED0254BD25E0@phx.gbl>
From: S A <sagarwal10 AT hotmail DOT com>
To: <cygwin AT cygwin DOT com>
Subject: get_osfhandle & WaitForSingleObject on a cygwin socket fd....
Date: Thu, 20 Dec 2007 18:01:34 -0800
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id lBL21pZW005976


Hi

Please bear with me if this is a stupid question but I'm trying to setup a telnet socket
in cygwin and then want to use a Windows wait semaphore (WaitForMultipleObjects) 
to combine it with a sleep for winpcap HANDLEs. 

I thought I'd test this first though. 

Does get_osfhandle() on a AF_INET socket to the right thing? The WaitForSingleObject
below never wakes up (despite an incoming telnet connection). 

Thanks. 

main() {
  struct sockaddr_in sin;
  int s;
  int opt = 1;
  int ret;
  HANDLE h; 

  /* init server socket. */
  if ((s=socket(AF_INET, SOCK_STREAM, 0))< 0) {
    printf("%s: setsockopt! %s\n", __FUNCTION__, strerror(errno));
  }

  /* try to bind to port */
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); // only bind to loopback now
  sin.sin_port = htons(8081);
    
  if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
    return LP_ERR_SOCKET;
  }
   
  if (listen(s, LEAD_PIPE_MAX_CONN) < 0) {
    return LP_ERR_SOCKET;
  }
   
  h = (HANDLE) get_osfhandle(s);
  ASSERT(h> 0); 
  fprintf(stdout, "Waiting on telnet handle %x\n", h);
  while(1) {
      WaitForSingleObject(h, INFINITE);
      fprintf(stdout, "Awoke on telnet handle\n");
  } 
}
_________________________________________________________________
Don't get caught with egg on your face. Play Chicktionary!
http://club.live.com/chicktionary.aspx?icid=chick_wlhmtextlink1_dec

--
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