-
Notifications
You must be signed in to change notification settings - Fork 91
Detect *BSDs as supporting libc as well. #68
base: main
Are you sure you want to change the base?
Conversation
@@ -266,8 +266,33 @@ unsafe public void Run (object state) | |||
static UnmanagedSocket () | |||
{ | |||
try { | |||
string os = File.ReadAllText("/proc/sys/kernel/ostype"); | |||
supports_libc = os.StartsWith ("Linux"); | |||
string uname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than starting uname, wouldn't it be better to use a native call such as in: https://github.com/mono/monodevelop/blob/7c51ae11c323d429c10acd22169373927217198f/main/src/core/Mono.Texteditor/Mono.TextEditor/Platform.cs#L48-L68
I didn't know about this call, however after checking it now there is never mentioned any guarantee about member order within structure (and that MonoDevelop example obviously assumes that sysname is first member, otherwise casting it to string wouldn't work) - I have no clue if across different unices you can safely assume that sysname is always first member of structure? |
Actually, you're right. Good point there. |
On the other hand uname is a POSIX standard |
I am not sure, but actually maybe it would make sense to have something in essence similar to your idea: try {
s = socket(PF_LOCAL, SOCK_STREAM, 0);
close(s);
supports_local_sockets = true;
}
catch {
supports_local_sockets = false;
} (with similar detection for every type of sockets) since idea of all this is anyway to check if "native" sockets are available through libc - but again maybe uname idea is easier to maintain and understand |
I like your idea of "feature detection", would this be a big change to make? |
No, it would be easy to implement, however I have doubts:
CONS:
|
I suppose if |
Hehehe, you have point there - I was more thinking like this (according to my experience with mono) - quite often on freebsd some functions fail because of missing mapping between system libs and names used by mono (since it is not the same as in linux) - with uname way it is clear that you enforced using of native sockets and then if needed you could later investigate further problems (easier path for somebody not familiar with this code). I would say in general best way to approach this would be along these lines: try {
s = socket(PF_LOCAL, SOCK_STREAM, 0);
close(s);
supports_local_sockets = true;
}
catch {
LogWhyItFailed();
supports_local_sockets = false;
} So if somebody with write access agrees to that I could implement it :-) |
@grendello what do you think? |
I think we should have specific checks for the systems we know for sure work fine (Linux, OS X) using their native mechanisms. Start with consulting Environment.OSVersion to see if we're on Unix or OS/X (since it's supported directly in PlatformID). If we're not, no local sockets obviously. If OS/X, we're done. If Unix, go to check if there's the /proc filesystem, make sure it's Linux. If not, fall back to the libc syscall for detection of local socket support. |
That sounds overcomplicated to me without any real benefit (if libc call works why would we care what OS is behind (OSX, BeOS, or HP-UX) - it is its socket functionality we care about). Btw, is there any unix that doesn't support bsd sockets? Since they are part of posix anyway, maybe it makes more sense simply to enable it for all Unix (obviously that would leave any exotic OS with socket support (Haiku for example) unsupported)? |
Btw, not strictly related to this one, would it be too complicated to patch mono not to drop requests in processing on application updates (similar way like you would normally write fastcgi app in C (signal it to stop accepting new requests and die, and have web server start new version of application for new requests))? |
As a reply to the "not dropping requests" idea: I think you could patch mono-fpm to do that with a moderate effort. |
Modified fastcgi server to be able to use native (and local sockets) with *BSDs as well. I tested it on FreeBSD with lighttpd & local socket and it works as expected.