We were sometimes seeing the following failure on Jenkins on OSX:
```
Test Case Failures:
1) MonoTests.System.Net.Sockets.SocketTest.AcceptBlockingStatus : System.Net.Sockets.SocketException : Operation on non-blocking socket would block
at System.Net.Sockets.Socket.Accept () [0x00033] in /Users/builder/jenkins/workspace/test-mono-mainline/label/osx-i386/mcs/class/System/System.Net.Sockets/Socket.cs:896
at MonoTests.System.Net.Sockets.SocketTest.BlockingConnect (Boolean block) [0x0003e] in /Users/builder/jenkins/workspace/test-mono-mainline/label/osx-i386/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs:129
at MonoTests.System.Net.Sockets.SocketTest.AcceptBlockingStatus () [0x0001e] in /Users/builder/jenkins/workspace/test-mono-mainline/label/osx-i386/mcs/class/System/Test/System.Net.Sockets/SocketTest.cs:147
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Users/builder/jenkins/workspace/test-mono-mainline/label/osx-i386/mcs/class/corlib/System.Reflection/MonoMethod.cs:295
```
In non-blocking mode accept() is specified to return this error when no client connection is available right now.
It looks like on OSX we don't immediately get that connection.
To fix this issue, we try to accept in a loop for 100ms and only fail when we don't get a connection in this time.
//
using System;
+using System.Diagnostics;
using System.Linq;
using System.Collections;
using System.Threading;
ProtocolType.Tcp);
conn.Connect (ep);
- Socket client = server.Accept();
+ Socket client = null;
+ var sw = Stopwatch.StartNew ();
+ while (sw.ElapsedMilliseconds < 100)
+ {
+ try {
+ client = server.Accept();
+ break;
+ }
+ catch (SocketException ex) {
+ if (ex.SocketErrorCode == SocketError.WouldBlock)
+ continue;
+ throw;
+ }
+ }
+ Assert.IsNotNull (client, "Couldn't accept a client connection within 100ms.");
bool client_block = client.Blocking;
client.Close();