Moving WSAGetLastError calls closer to socket operation (#3450)
authorHenric Müller <henric.muller@gmail.com>
Wed, 7 Sep 2016 13:30:55 +0000 (15:30 +0200)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 7 Sep 2016 13:30:55 +0000 (15:30 +0200)
commitf577b619e9d410d7a2868f7c556fc934f03354fa
tree75f28a3c1329498d949aec717b6289d83093e989
parenta231b0a82c0102ed603ff2bdf4f575c99b2317f7
Moving WSAGetLastError calls closer to socket operation (#3450)

* When doing async connect on windows, connect returns `WSAEINPROGRESS`
which needs to be returned to managed code for correct handling. However
on Windows, last error gets reset before `WSAGetLastError` is called.
This fix moves all `WSAGetLastError` calls up closer to the socket
operation to make sure correct error code is returned to the managed code.

* Making sure `TcpNoDelay` is set to false for IPv4 by default and
that `DualMode` is default for IPv6.

* Making sure option value is set to 0 before calling getsockopt
because on Windows, a `BOOL` option value (eg TcpNoDelay) is returned
as a one byte value and the other bytes are left untouched which resulted
in TcpNoDelay always seemed to be true.

* Fixed so `TF_REUSE_SOCKET` is set only if `reuse` parameter is set
when disconnecting a socket.
mcs/class/System/System.Net.Sockets/Socket.cs
mono/metadata/socket-io.c