From da7760a440dd56191a5deeaa2c0475e830fbe804 Mon Sep 17 00:00:00 2001 From: Ivan Radovanovic Date: Thu, 16 Oct 2014 16:54:16 +0200 Subject: [PATCH 1/2] Detect *BSDs as supporting libc as well. --- .../Sockets/UnmanagedSocket.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) 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 { } } From 388ce98e3363ef7174be90e97f8e5358ee4edffc Mon Sep 17 00:00:00 2001 From: Ivan Radovanovic Date: Wed, 29 Oct 2014 19:06:53 +0100 Subject: [PATCH 2/2] Check Send/Receive return value for errors during socket reading/writting. --- src/Mono.WebServer.FastCgi/Record.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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; } } }