diff --git a/src/Mono.WebServer.FastCgi/Record.cs b/src/Mono.WebServer.FastCgi/Record.cs index fab89c38..3b7192f4 100644 --- a/src/Mono.WebServer.FastCgi/Record.cs +++ b/src/Mono.WebServer.FastCgi/Record.cs @@ -168,8 +168,12 @@ internal static void SendAll (Socket socket, CompatArraySegment? data, int int total = 0; while (total < length) { - total += socket.Send (data.Value.Array, data.Value.Offset + total, - length - total, System.Net.Sockets.SocketFlags.None); + int written = socket.Send(data.Value.Array, data.Value.Offset + total, + length - total, System.Net.Sockets.SocketFlags.None); + if (written <= 0) + throw new System.Net.Sockets.SocketException(); + + total += written; } } @@ -180,9 +184,13 @@ internal static void ReceiveAll (Socket socket, CompatArraySegment data, i int total = 0; while (total < length) { - total += socket.Receive (data.Array, total + data.Offset, - length - total, - System.Net.Sockets.SocketFlags.None); + int read = socket.Receive(data.Array, total + data.Offset, + length - total, + System.Net.Sockets.SocketFlags.None); + if (read <= 0) + throw new System.Net.Sockets.SocketException(); + + total += read; } } } diff --git a/src/Mono.WebServer.FastCgi/Sockets/UnmanagedSocket.cs b/src/Mono.WebServer.FastCgi/Sockets/UnmanagedSocket.cs index bf166417..c39ccf68 100644 --- a/src/Mono.WebServer.FastCgi/Sockets/UnmanagedSocket.cs +++ b/src/Mono.WebServer.FastCgi/Sockets/UnmanagedSocket.cs @@ -266,8 +266,33 @@ public object AsyncState { static UnmanagedSocket () { try { - string os = File.ReadAllText("/proc/sys/kernel/ostype"); - supports_libc = os.StartsWith ("Linux"); + string uname; + try { + var p = new System.Diagnostics.Process(); + + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.FileName = "uname"; + + p.Start(); + + uname = p.StandardOutput.ReadToEnd(); + p.WaitForExit(); + if (uname == null) + uname = ""; + uname = uname.Trim().ToLower(); + + supports_libc = uname.StartsWith("linux") || + uname.StartsWith("freebsd") || + uname.StartsWith("netbsd") || + uname.StartsWith("openbsd"); + } catch { + uname = ""; + } + if (uname == "") { + string os = File.ReadAllText("/proc/sys/kernel/ostype"); + supports_libc = os.StartsWith ("Linux"); + } } catch { } }