public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* 1.3.2: Cygwin && UDP && O_NONBLOCK
@ 2001-08-14  8:12 Roderick Groesbeek
  2001-08-14  9:34 ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Roderick Groesbeek @ 2001-08-14  8:12 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3582 bytes --]

                                                    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@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
ret=0|
recvfrom: Invalid argument
len=-1|
recvfrom: Invalid argument
len=-1|

(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>
#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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 1.3.2: Cygwin && UDP && O_NONBLOCK
  2001-08-14  8:12 1.3.2: Cygwin && UDP && O_NONBLOCK Roderick Groesbeek
@ 2001-08-14  9:34 ` Keith Seitz
  2001-08-14 13:09   ` Roderick Groesbeek
  0 siblings, 1 reply; 7+ messages in thread
From: Keith Seitz @ 2001-08-14  9:34 UTC (permalink / raw)
  To: Roderick Groesbeek; +Cc: cygwin

On Tue, 14 Aug 2001, Roderick Groesbeek wrote:

> #ifdef __linux__
>    #include <linux/in.h>
> #endif
> #ifdef __CYGWIN__
>    #include <cygwin/in.h>
> #endif

Why not just #include <netinet/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) {
>         perror("socket");
>         exit(1);
>   }
>
>   flags = fcntl(sock, F_GETFL, 0);
>   ret = fcntl(sock, F_SETFL, flags & ~O_NONBLOCK);
>   printf("ret=%d|\n", ret);

This fcntl stuff shouldn't really be necessary, but it should do no harm.

>   bzero((char*) &from, sizeof(from));

Ugh. You mean "bzero (&me, sizeof (me));"?

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

This is not correct. from_len is not initialized (typo?). You MUST set it
to "sizeof (from)". This is a "value/result argument".

>         perror("recvfrom");
>         printf("len=%d|\n", len);
>   }
>
>   return 0;
> }

FWIW, I tried the following program on my system and had no problems
whatsoever, with or without SET_BLOCKING set.

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#ifdef SET_BLOCKING
#include <fcntl.h>
#endif

#ifdef __CYGWIN__
typedef unsigned int socklen_t;
#endif

int
main (int argc, char *argv[])
{
  int ret;
  char buf[1024];
  socklen_t len;
  struct sockaddr_in my_addr, client_addr;
  int sock;
#ifdef SET_BLOCKING
  int flags;
#endif

  sock = socket (AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    {
      perror ("couldn't create socket");
      exit (1);
    }

#ifdef SET_BLOCKING
  flags = fcntl (sock, F_GETFL, 0);
  flags &= ~O_NONBLOCK;
  ret = fcntl (sock, F_SETFL, flags);
  if (ret < 0)
   {
     perror ("couldn't force blocking");
     exit (1);
   }
#endif


  bzero (&my_addr, sizeof (my_addr));
  my_addr.sin_family = AF_INET;
  my_addr.sin_addr.s_addr = htonl (INADDR_ANY);
  my_addr.sin_port = htons (10025);
  if (bind (sock, (struct sockaddr *) &my_addr, sizeof (my_addr)) < 0)
    {
      perror ("couldn't bind to address");
      exit (1);
    }

  while (1)
    {
      len = sizeof (client_addr);
      ret = recvfrom (sock, buf, 1024, 0, (struct sockaddr *) &client_addr, &len);
      printf ("recvfrom returned %d\n", ret);
      if (ret < 0)
	{
	  perror ("error getting data from socket");
	  continue;
	}

      /* Do something with the data. Echo it. */
      ret = sendto (sock, buf, ret, 0, (struct sockaddr *) &client_addr, len);
      if (ret < 0)
	{
	  perror ("error sending data");
	  continue;
	}

      printf ("Sent %d bytes to client at %x\n", ret, client_addr.sin_addr.s_addr);
    }

  return 0;
}




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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 1.3.2: Cygwin && UDP && O_NONBLOCK
  2001-08-14  9:34 ` Keith Seitz
@ 2001-08-14 13:09   ` Roderick Groesbeek
  2001-08-14 13:23     ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Roderick Groesbeek @ 2001-08-14 13:09 UTC (permalink / raw)
  To: Keith Seitz; +Cc: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1654 bytes --]

From: "Keith Seitz" <keiths@cygnus.com>
To: "Roderick Groesbeek" <rgroesb@triple-it.com>
Cc: <cygwin@cygwin.com>
Sent: Tuesday, August 14, 2001 6:33 PM
Subject: Re: 1.3.2: Cygwin && UDP && O_NONBLOCK


> Why not just #include <netinet/in.h>?

Thnx.
One to remember..
Just like "#!/usr/bin/env perl"    (Why doesn't everybody uses that!)

>
>

Ok keith.
Thnx for your reply, it really helped.

I don't have an excuse for my slappy code....
After struggling, finding out how to use DLLTOOL,
and coming to the conclusion that O_NONBLOCK code
is buggy in Cygwin.
I finally motivated myself to build some UDP server & client test code.
(Borrowed some code from an old C++ project of mine..)
And that even failed, by my own human error.
Anyway.. no excuse.


I'm pretty good, mind you :-)


Anyway, I have extrapolated your sources (based on mine) to the
following.
Would you pls take a look at the server.c code?

It should, when in O_NONBLOCK mode, do some bussy waiting,
just like an awful Kernel Scheduler.

But it just isn't...
And that is the problem I also have in my Library I wanna port to CYGWIN.

I will include the sources in a .tgz.
(Mailinglist will allow attachments?)


Hope you have some spare time to look at it.

Thnx in advance.



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



[-- Attachment #2: blocktest.tgz --]
[-- Type: application/x-gzip, Size: 1681 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: 1.3.2: Cygwin && UDP && O_NONBLOCK
  2001-08-14 13:09   ` Roderick Groesbeek
@ 2001-08-14 13:23     ` Keith Seitz
  2001-08-14 16:20       ` using cygwin within dev-c++ andreas_schmitzer
  2001-08-15  1:42       ` Cygwin && UDP && O_NONBLOCK Ralf Habacker
  0 siblings, 2 replies; 7+ messages in thread
From: Keith Seitz @ 2001-08-14 13:23 UTC (permalink / raw)
  To: Roderick Groesbeek; +Cc: cygwin

On Tue, 14 Aug 2001, Roderick Groesbeek wrote:

> Just like "#!/usr/bin/env perl"    (Why doesn't everybody uses that!)

:-) ( "foo > /dev/null 2>&1 &" is the one I always struggle with. Half the
time it comes out "foo > /dev/null 2&>1 &"!)

> After struggling, finding out how to use DLLTOOL,
> and coming to the conclusion that O_NONBLOCK code
> is buggy in Cygwin.

Yes, see my previous message about the nature of my misunderstanding. You
are absolutely correct: there appears to be a problem with NONBLOCKING i/o
on udp.

I'll talk to you offline about server.c.
Keith



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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* using cygwin  within dev-c++
  2001-08-14 13:23     ` Keith Seitz
@ 2001-08-14 16:20       ` andreas_schmitzer
  2001-08-15  1:42       ` Cygwin && UDP && O_NONBLOCK Ralf Habacker
  1 sibling, 0 replies; 7+ messages in thread
From: andreas_schmitzer @ 2001-08-14 16:20 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1146 bytes --]

hello,

here is another question i wanna ask.
it should be possible to work with the cygwin compiler under dev-
c++. to do so you should put the following lines in your autoexc.bat:

SET PATH=C:\cygnus\cygwin-b20\H-i586-cygwin32\bin;%PATH%
SET C_INCLUDE_PATH=C:\cygnus\cygwin-b20\include
SET CPP_INCLUDE_PATH=C:\cygnus\cygwin-
b20\include\g++;C:\cygnus\cygwin-b20\include
SET GCC_EXEC_PREFIX=C:\cygnus\cygwin-b20\H-i586-
cygwin32\lib\gcc-lib
SET LIBRARY_PATH=C:\cygnus\cygwin-b20\H-i586-cygwin32\i586-
cygwin32\lib
(according to  the dev-c++ documentation)


but these lines must be wrong and should belong to another (older?)
version of cygwin.

where are the real include and lib-files for the c/c++ compiler.
there are a lot of them in the cygwin directory and i must admit that i
don´t understand why they are split in so many directories.
please help even if this question seems to be stupid to you.

greetings
andreas




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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Cygwin && UDP && O_NONBLOCK
  2001-08-14 13:23     ` Keith Seitz
  2001-08-14 16:20       ` using cygwin within dev-c++ andreas_schmitzer
@ 2001-08-15  1:42       ` Ralf Habacker
  2001-08-15  1:55         ` egor duda
  1 sibling, 1 reply; 7+ messages in thread
From: Ralf Habacker @ 2001-08-15  1:42 UTC (permalink / raw)
  To: Cygwin

Hi,
may be this problem is related to the socket problems I had with kde 1.1.2 and
non blocking sockets.

Egor Duga has provided a patch (see in cygwin mailing list) with which I have
build a patched cygwin-1.3.2 available under
http://sourceforge.net/project/showfiles.php?group_id=27249 .

Please note that this is a special cygwin snapshot, which will be removed if
this patch is integrated in the official cygwin release.

Ralf

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


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Cygwin && UDP && O_NONBLOCK
  2001-08-15  1:42       ` Cygwin && UDP && O_NONBLOCK Ralf Habacker
@ 2001-08-15  1:55         ` egor duda
  0 siblings, 0 replies; 7+ messages in thread
From: egor duda @ 2001-08-15  1:55 UTC (permalink / raw)
  To: Ralf Habacker; +Cc: cygwin

Hi!

Wednesday, 15 August, 2001 Ralf Habacker Ralf.Habacker@freenet.de wrote:

RH> may be this problem is related to the socket problems I had with kde 1.1.2 and
RH> non blocking sockets.

no, i don't think so. problems with kde was related to AF_UNIX
sockets and their specifics. i doubt they're related to UDP sockets in
any way.

Egor.            mailto:deo@logos-m.ru ICQ 5165414 FidoNet 2:5020/496.19


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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-08-15  1:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-14  8:12 1.3.2: Cygwin && UDP && O_NONBLOCK Roderick Groesbeek
2001-08-14  9:34 ` Keith Seitz
2001-08-14 13:09   ` Roderick Groesbeek
2001-08-14 13:23     ` Keith Seitz
2001-08-14 16:20       ` using cygwin within dev-c++ andreas_schmitzer
2001-08-15  1:42       ` Cygwin && UDP && O_NONBLOCK Ralf Habacker
2001-08-15  1:55         ` egor duda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).