This is the mail archive of the 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]

1.3.2: Cygwin && UDP && O_NONBLOCK

                                                    Howdy People,

According to the website this is the right mailinglist.

I'm porting an Unix library to Cygwin.
First I builded a test environment to analyze/study
the behaviour of using DLL's with Cygwin.

All my tests with the DLL's succeed, so after that
I patched my Unix Library Makefile to build a DLL with dlltool.

The library, both .dll as .a import, are ok.
Crafted with DLLTOOL I can perfectly port my
library to Cygwin, and link against it.

- My Unix library uses nonblocking UDP sockets,
  which works under Linux, but still blocks under Cygwin.

After some debugging of the library, I found that indeed the
recvfrom() is blocking, and couldn't quite come to a fix.

I finally came to the point to build some UDP server + client test program,
to see if UDP && Cygwin is operating correctly.

But my first UDP test program is already acting 'weird'.

Under Linux:
[root@xml /tmp]# gcc -Wall -o server server.c
[root@xml /tmp]# ./server
(ctrl + c)
[root@xml /tmp]#
(Nice blocking..)

Under Cygwin:
Administrator@PIGGY ~/cvsroot/blocktest
$ gcc -Wall -o server server.c

Administrator@PIGGY ~/cvsroot/blocktest
$ ./server.exe
recvfrom: Invalid argument
recvfrom: Invalid argument

(ctrl + c)
Administrator@PIGGY ~/cvsroot/blocktest
(Not blocking? Acting weird?)

#include <stdio.h>
#include <stdlib.h>

#include <string.h>

#include <sys/socket.h>
#include <sys/types.h>
#ifdef __linux__
   #include <linux/in.h>
#ifdef __CYGWIN__
   #include <cygwin/in.h>

#include <unistd.h>
#include <fcntl.h>

#define BUFSIZE 1024

int main(int argc, char* argv[], char* env[])
  int sock;
  int ret;
  char buf[BUFSIZE];
  struct sockaddr_in me, from;
  unsigned int from_len;

  int flags;

  sock = socket(PF_INET, SOCK_DGRAM, 0);

  if (sock < 0) {

  flags = fcntl(sock, F_GETFL, 0);
  ret = fcntl(sock, F_SETFL, flags & ~O_NONBLOCK);
  printf("ret=%d|\n", ret);

  bzero((char*) &from, sizeof(from));
  me.sin_family = AF_INET;
  me.sin_addr.s_addr = htonl(INADDR_ANY);
  me.sin_port = htons(1025);
  ret = bind(sock, (struct sockaddr *) & me, sizeof(me));
  if (ret < 0) {
  while(1) {
        int len;

        len = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *) &from,
        printf("len=%d|\n", len);

  return 0;

- Are UDP sockets problematic under Cygwin?
  (Couldn't find any references in the mailinglist archive)
- Are NONBLOCKING sockets operating correctly under Cygwin?
   fcntl(sock, F_SETFL, flags & ~O_NONBLOCK);

I hereby thank you for your time.

Vriendelijke Groet,

Note: For efficiŽnt work-behaviour, I'm currently only reading my E-mail
twice a day!

Pettemerstraat 12A                                  T r I p l e
1823 CW Alkmaar                                         T
Tel. +31 (0)72-5129516
fax. +31 (0)72-5129520                              Automatisering                                 "Laat uw Net Werken!"

Unsubscribe info:
Bug reporting:

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