This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

get_osfhandle & WaitForSingleObject on a cygwin socket fd....


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


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!

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]