Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Detect *BSDs as supporting libc as well. #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Mono.WebServer.FastCgi/Record.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ internal static void SendAll (Socket socket, CompatArraySegment<byte>? 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;
}
}

Expand All @@ -180,9 +184,13 @@ internal static void ReceiveAll (Socket socket, CompatArraySegment<byte> 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;
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions src/Mono.WebServer.FastCgi/Sockets/UnmanagedSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
}
}
Expand Down