This is the mail archive of the cygwin@sourceware.cygnus.com 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]

accept() fails?


Hi all.

I'm in the process of porting the USR PalmPilot PDA emulator 'copilot'
to cygwin32 with support for debugging pilot code with gdb.  I've got most of
it working.  I can't figure out how to get the resources the native win32
code uses in so it looks funny but other than that, it's functional.

I need to add the support for gdb now, which just means a TCP/IP socket.
I've modified the XWindow version to have this feature, which works just
fine.  Under cygwin32, calls to accept() fail, and I can't see anything
wrong with the code.  I've distilled this down and included a small
test program below.

I've looked through the mailing list archives, and I don't see anything,
so it's got to be just me.  Would someone be kind enough to point out
what I doing wrong that Linux is letting me get away with and cygwin32
is not?  The code below, compiled for Linux, works as expected.  Compiled
for b18 cygwin32 immediately returns -1 from the call to accept.

Thanks in advance :-)

Jeff.

---------------tst.c-------------------
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>

int
main(int argc, char *argv[])
{
  int fd, nfd;
  struct sockaddr_in sockaddr;
  int tmp;

  fd = socket (AF_INET, SOCK_STREAM, 0);
  if (fd < 0)
    return -1;

  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(2000);
  sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);

  if (bind (fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
    perror("bind");
    close (fd);
    return -1;
  }

  if (listen(fd, 1)) {
    close (fd);
    return -1;
  }

  if ((nfd=accept(fd, (struct sockaddr *) &sockaddr, &tmp)) < 0) {
    fprintf(stderr,"not good, accept ret %d fd %d\n",nfd,fd);
    close (fd);
    return -1;
  }

  fprintf(stderr,"Got connecton, returned fd %d\n",nfd);

  close (fd);
  close (nfd);
  return 0;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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