bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read() and write() for MinGW


From: Neil Jerram
Subject: read() and write() for MinGW
Date: Sun, 28 Mar 2010 23:04:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

I'd like to contribute a gnulib module to handle the fact that, on
MinGW, you have to use recv() to read data from a socket, instead of
read().

Similarly, for writing, send() is needed instead of write().

Conceptually this is extremely simple, and I've found that gnulib
already contains useful bits like SOCKET_TO_FD, FD_TO_SOCKET, and the
code for determining if an arbitrary fd is a socket - which is all
great.

But I'm lost in a twisty maze of working out how to do this in the 100%
right Gnulib way.  I believe I should be writing a rpl_read() function
to replace read(), and I can see the pattern for that.  But what's the
preferred way to write the test to see if this is needed?  Checking for
__MINGW32__, or (WIN32 && !CYGWIN), or HAVE_WINSOCK2_H, or a feature
test that tries read() on a socket and determines if it worked?

I've tried to work this out by reference to existing Gnulib modules, but
I'm struggling to understand some points.  For example, looking at the
"write" module...

- m4/write.m4 tests gl_SIGNAL_SIGPIPE, which just tests (IIUC) whether
  SIGPIPE is defined -- but then lib/write.c only implements rpl_write()
  #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__.
  Does this mean that there is an implicit assumption here that those
  two conditions are equivalent?

- The lib/write.c code includes

          /* Try to raise signal SIGPIPE.  */
          raise (SIGPIPE);

  How can that work given that we've already determined that SIGPIPE is
  not defined?

All help and advice would be appreciated!

Thanks,
        Neil




reply via email to

[Prev in Thread] Current Thread [Next in Thread]