-print "yes\n" if $has_kqueue == 1;
-print "no\n" if $has_kqueue == 0;
-
-printf "Checking for epoll support... ";
-$has_epoll = test_compile('epoll');
-print $has_epoll ? "yes\n" : "no\n";
-
-printf "Checking for eventfd support... ";
-$config{HAS_EVENTFD} = test_compile('eventfd') ? 'true' : 'false';
-print $config{HAS_EVENTFD} eq 'true' ? "yes\n" : "no\n";
-
-printf "Checking if Solaris I/O completion ports are available... ";
-$has_ports = 0;
-our $system = `uname -s`;
-chomp ($system);
-$has_ports = 1 if ($system eq "SunOS");
-
-if ($has_ports) {
- my $kernel = `uname -r`;
- chomp($kernel);
- if (($kernel !~ /^5\.1./)) {
- $has_ports = 0;
+
+print "Checking whether epoll is available... ";
+$config{HAS_EPOLL} = test_header($config{CXX}, "sys/epoll.h");
+print $config{HAS_EPOLL} ? "yes\n" : "no\n";
+$config{SOCKETENGINE} ||= "epoll" if $config{HAS_EPOLL};
+
+print "Checking whether Kqueue is available... ";
+$config{HAS_KQUEUE} = test_file($config{CXX}, "kqueue.cpp");
+print $config{HAS_KQUEUE} ? "yes\n" : "no\n";
+$config{SOCKETENGINE} ||= "kqueue" if $config{HAS_KQUEUE};
+
+print 'Checking whether Solaris IOCP is available... ';
+$config{HAS_PORTS} = test_header($config{CXX}, 'port.h');
+print $config{HAS_PORTS} ? "yes\n" : "no\n";
+$config{SOCKETENGINE} ||= "ports" if $config{HAS_PORTS};
+
+print 'Checking whether poll is available... ';
+$config{HAS_POLL} = test_header($config{CXX}, 'poll.h');
+print $config{HAS_POLL} ? "yes\n" : "no\n";
+$config{SOCKETENGINE} ||= "poll" if $config{HAS_POLL};
+
+# Select is available on all platforms
+$config{HAS_SELECT} = 1;
+$config{SOCKETENGINE} ||= "select";
+
+if (defined $opt_socketengine) {
+ my $cfgkey = "HAS_" . uc $opt_socketengine;
+ if ($config{$cfgkey} && -f "src/socketengines/socketengine_$opt_socketengine.cpp") {
+ $config{SOCKETENGINE} = $opt_socketengine;
+ } else {
+ print "Unable to use a socket engine which is not supported on this platform ($opt_socketengine)!\n";
+ print "Available socket engines are:";
+ foreach (<src/socketengines/socketengine_*.cpp>) {
+ s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
+ print " $1" if $config{"HAS_" . uc $1};
+ }
+ print "\n";
+ exit 1;