Mingw doesn't like write() to socket

Bert Belder H.Belder at student.TUDelft.NL
Thu Dec 9 16:47:17 CET 2010


Lets settle this for once and for all :-)

Compile & run the attached file, it tests different read and write
functions on winsock sockets. My results are below.

OS: Windows 7 pro 64-bit
Toolchain: MinGW32, GCC 4.5.0
Build command: gcc sockwrite.c -o sockwrite.exe -lws2_32

crt write()                   : failure (-1) - Invalid argument (22)
winsock send()                : success (20)
winapi blocking WriteFile()   : failure ( 0) - Unknown error (87)
winapi overlapped WriteFile() : success (20)

crt read()                    : failure (-1) - Invalid argument (22)
winsock recv()                : success ( 5)
winapi blocking ReadFile()    : failure ( 0) - Unknown error (87)
winapi overlapped ReadFile()  : success ( 5)


Preliminary interpretation:
If anyone gets a blocking ReadFile/Writefile that succeeds, differences
between windows versions are the culprit.
If crt read/write works, it must be due to CRT differences unless
blocking ReadFile/WriteFile also succeed.

- Bert


> -----Oorspronkelijk bericht-----
> Van: libev-bounces+h.belder=student.tudelft.nl at lists.schmorp.de
> [mailto:libev-bounces+h.belder=student.tudelft.nl at lists.schmorp.de]
> Namens Marc Lehmann
> Verzonden: donderdag 9 december 2010 10:57
> Aan: W.C.A. Wijngaards
> CC: libev at lists.schmorp.de
> Onderwerp: Re: Mingw doesn't like write() to socket
> 
> On Thu, Dec 09, 2010 at 10:39:11AM +0100, "W.C.A. Wijngaards"
> <wouter at NLnetLabs.nl> wrote:
> > > I don't really test much on vista, the tcp stack seems to be near
> to
> > > unusable on that box.
> >
> > On vista, sockets work much like XP, I tested that.
> 
> Well, vista breaks (standard) perl, and broke firefox at one point,
> because getsockname and getpeername don't agree on both sides of a
> local
> connection for example.
> 
> I personally measured this on a connection to localhost for example:
> 
>    port of getsockname client == 53364
>    port of getpeername client == 53363
>    port of getsockname server == 53363
>    port of getpeername server == 53365
> 
> I also had (verified) reports of getprotobyname or socket() failing
and
> many other weird issues.
> 
> This definitely didn't happen on XP.
> 
> That will probably not affect libev directly, but Vista and TCP/IP
> don't
> seem to work together :)
> 
> --
>                 The choice of a       Deliantra, the free code+content
> MORPG
>       -----==-     _GNU_              http://www.deliantra.net
>       ----==-- _       generation
>       ---==---(_)__  __ ____  __      Marc Lehmann
>       --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
>       -=====/_/_//_/\_,_/ /_/\_\
> 
> _______________________________________________
> libev mailing list
> libev at lists.schmorp.de
> http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sockwrite.c
Type: application/octet-stream
Size: 4392 bytes
Desc: sockwrite.c
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20101209/f61970fc/attachment.obj>


More information about the libev mailing list