Skip to content

Commit c062205

Browse files
committed
Falling back to select when target OS(NT < 6.0) not support poll
1 parent 681876c commit c062205

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

examples/lua/main.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ int main(int argc, char** argv)
4343

4444
std::string new_package_path = s["package"]["path"];
4545

46-
sol::function function = s.script_file("scripts/example.lua");
47-
48-
do
46+
try
47+
{
48+
sol::table module_example = s.load_file("scripts/example.lua").call();
49+
sol::function update_func = module_example["update"];
50+
do
51+
{
52+
std::this_thread::sleep_for(std::chrono::milliseconds(16));
53+
} while (!update_func(50.0 / 1000));
54+
}
55+
catch (const sol::error& e)
4956
{
50-
std::this_thread::sleep_for(std::chrono::milliseconds(16));
51-
} while (!function.call(50.0 / 1000));
57+
std::cerr << "Error: " << e.what() << std::endl;
58+
return -1;
59+
}
5260
#else
5361
kaguya::State s;
5462
s.openlibs();
@@ -65,11 +73,12 @@ int main(int argc, char** argv)
6573
s["package"]["path"] = package_path;
6674

6775
auto function = s.loadfile("scripts/example.lua");
68-
auto update = function();
76+
auto module_example = function();
77+
auto update_func = module_example["update"];
6978
do
7079
{
7180
std::this_thread::sleep_for(std::chrono::milliseconds(50));
72-
} while (!update(50.0 / 1000));
81+
} while (!update_func(50.0 / 1000));
7382
#endif
7483
return 0;
7584
}

yasio/bindings/lyasio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ end
795795

796796
char version[32];
797797
snprintf(version, sizeof(version), "%x.%x.%x", (YASIO_VERSION_NUM >> 16) & 0xff, (YASIO_VERSION_NUM >> 8) & 0xff, YASIO_VERSION_NUM & 0xff);
798-
YASIO_EXPORT_ANY(version);
798+
yasio_lib["version"] = std::string(version);
799799

800800
return yasio_lib.push(); /* return 'yasio' table */
801801
}

yasio/compiler/feature_test.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ SOFTWARE.
121121

122122
/// Tests multiplex io model of current OS
123123

124+
// poll
125+
#if !defined(_WIN32) || NTDDI_VERSION >= NTDDI_VISTA
126+
# define YASIO__HAS_POLL 1
127+
#else
128+
# define YASIO__HAS_POLL 0
129+
#endif
130+
124131
// ppoll
125132
#if defined(__linux__) && !defined(__ANDROID__) || (defined(__ANDROID_API__) && __ANDROID_API__ >= 21)
126133
# define YASIO__HAS_PPOLL 1

yasio/io_watcher.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
#elif YASIO__HAS_EVPORT && defined(YASIO_ENABLE_HPERF_IO)
1818
# include "yasio/impl/evport_io_watcher.hpp"
1919
#elif !defined(YASIO_DISABLE_POLL)
20-
# include "yasio/impl/poll_io_watcher.hpp"
20+
# if YASIO__HAS_POLL
21+
# include "yasio/impl/poll_io_watcher.hpp"
22+
# else
23+
# pragma message("Falling back to select_io_watcher due to target OS(NT < 6.0) not support poll")
24+
# include "yasio/impl/select_io_watcher.hpp"
25+
# endif
2126
#else
2227
# include "yasio/impl/select_io_watcher.hpp"
2328
#endif
@@ -33,7 +38,7 @@ using io_watcher = kqueue_io_watcher;
3338
using io_watcher = epoll_io_watcher;
3439
#elif defined(YASIO__EVPORT_IO_WATCHER_HPP)
3540
using io_watcher = evport_io_watcher;
36-
#elif !defined(YASIO_DISABLE_POLL)
41+
#elif !defined(YASIO_DISABLE_POLL) && YASIO__HAS_POLL
3742
using io_watcher = poll_io_watcher;
3843
#else
3944
using io_watcher = select_io_watcher;

0 commit comments

Comments
 (0)