delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/08/14/11:14:10

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <00f801c124d4$40c6ed90$93b849d5@uu.net>
From: "Roderick Groesbeek" <rgroesb AT triple-it DOT com>
To: <cygwin AT cygwin DOT com>
Subject: 1.3.2: Cygwin && UDP && O_NONBLOCK
Date: Tue, 14 Aug 2001 17:17:37 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200

                                                    Howdy People,


According to the website this is the right mailinglist.

Info:
-------
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.



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

Analyze:
------------
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 AT xml /tmp]# gcc -Wall -o server server.c
[root AT xml /tmp]# ./server
(ctrl + c)
[root AT xml /tmp]#
~~
(Nice blocking..)

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

Administrator AT PIGGY ~/cvsroot/blocktest
$ ./server.exe
ret=0|
recvfrom: Invalid argument
len=-1|
recvfrom: Invalid argument
len=-1|

(ctrl + c)
Administrator AT 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>
#endif
#ifdef __CYGWIN__
   #include <cygwin/in.h>
#endif

#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) {
        perror("socket");
        exit(1);
  }

  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) {
        perror("bind");
        exit(1);
  }
  while(1) {
        int len;

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

  return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Questions:
---------------
- 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!

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



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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