|
4 | 4 | ////////////////////////////////////////////////////////////////////////////////////////// |
5 | 5 | /* |
6 | 6 | The MIT License (MIT) |
7 | | -
|
8 | 7 | Copyright (c) 2012-2019 halx99 |
9 | | -
|
10 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy |
11 | 9 | of this software and associated documentation files (the "Software"), to deal |
12 | 10 | in the Software without restriction, including without limitation the rights |
13 | 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
14 | 12 | copies of the Software, and to permit persons to whom the Software is |
15 | 13 | furnished to do so, subject to the following conditions: |
16 | | -
|
17 | 14 | The above copyright notice and this permission notice shall be included in all |
18 | 15 | copies or substantial portions of the Software. |
19 | | -
|
20 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
21 | 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
22 | 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
@@ -138,17 +134,19 @@ YASIO_API int luaopen_yasio(lua_State *L) |
138 | 134 | service->set_option(opt, static_cast<int>(va[0])); |
139 | 135 | } |
140 | 136 | }, |
141 | | - "dispatch_events", &io_service::dispatch_events, "open", &io_service::open, "get_state", |
142 | | - &io_service::get_state, "close", |
| 137 | + "dispatch_events", &io_service::dispatch_events, "open", &io_service::open, "is_open", |
| 138 | + sol::overload(static_cast<bool (io_service::*)(size_t) const>(&io_service::is_open), |
| 139 | + static_cast<bool (io_service::*)(transport_ptr) const>(&io_service::is_open)), |
| 140 | + "close", |
143 | 141 | sol::overload(static_cast<void (io_service::*)(transport_ptr)>(&io_service::close), |
144 | 142 | static_cast<void (io_service::*)(size_t)>(&io_service::close)), |
145 | 143 | "write", |
146 | 144 | sol::overload( |
147 | 145 | [](io_service *service, transport_ptr transport, yasio::string_view s) { |
148 | | - service->write(transport, std::vector<char>(s.data(), s.data() + s.length())); |
| 146 | + return service->write(transport, std::vector<char>(s.data(), s.data() + s.length())); |
149 | 147 | }, |
150 | 148 | [](io_service *service, transport_ptr transport, yasio::obstream *obs) { |
151 | | - service->write(transport, obs->take_buffer()); |
| 149 | + return service->write(transport, obs->take_buffer()); |
152 | 150 | })); |
153 | 151 |
|
154 | 152 | // ##-- obstream |
@@ -215,30 +213,31 @@ YASIO_API int luaopen_yasio(lua_State *L) |
215 | 213 | lyasio["highp_time"] = &highp_clock<system_clock_t>; |
216 | 214 |
|
217 | 215 | // ##-- yasio enums |
218 | | - lyasio["YCM_TCP_CLIENT"] = YCM_TCP_CLIENT; |
219 | | - lyasio["YCM_TCP_SERVER"] = YCM_TCP_SERVER; |
220 | | - lyasio["YCM_UDP_CLIENT"] = YCM_UDP_CLIENT; |
221 | | - lyasio["YCM_UDP_SERVER"] = YCM_UDP_SERVER; |
222 | | - lyasio["YEK_CONNECT_RESPONSE"] = YEK_CONNECT_RESPONSE; |
223 | | - lyasio["YEK_CONNECTION_LOST"] = YEK_CONNECTION_LOST; |
224 | | - lyasio["YEK_PACKET"] = YEK_PACKET; |
225 | | - lyasio["YOPT_CONNECT_TIMEOUT"] = YOPT_CONNECT_TIMEOUT; |
226 | | - lyasio["YOPT_SEND_TIMEOUT"] = YOPT_CONNECT_TIMEOUT; |
227 | | - lyasio["YOPT_RECONNECT_TIMEOUT"] = YOPT_RECONNECT_TIMEOUT; |
228 | | - lyasio["YOPT_DNS_CACHE_TIMEOUT"] = YOPT_DNS_CACHE_TIMEOUT; |
229 | | - lyasio["YOPT_DEFER_EVENT"] = YOPT_DEFER_EVENT; |
230 | | - lyasio["YOPT_TCP_KEEPALIVE"] = YOPT_TCP_KEEPALIVE; |
231 | | - lyasio["YOPT_RESOLV_FUNCTION"] = YOPT_RESOLV_FUNCTION; |
232 | | - lyasio["YOPT_LOG_FILE"] = YOPT_LOG_FILE; |
233 | | - lyasio["YOPT_LFBFD_PARAMS"] = YOPT_LFBFD_PARAMS; |
234 | | - lyasio["YOPT_IO_EVENT_CALLBACK"] = YOPT_IO_EVENT_CALLBACK; |
235 | | - lyasio["YOPT_CHANNEL_LOCAL_PORT"] = YOPT_CHANNEL_LOCAL_PORT; |
236 | | - lyasio["YOPT_CHANNEL_REMOTE_HOST"] = YOPT_CHANNEL_REMOTE_HOST; |
237 | | - lyasio["YOPT_CHANNEL_REMOTE_PORT"] = YOPT_CHANNEL_REMOTE_PORT; |
238 | | - lyasio["YOPT_CHANNEL_REMOTE_ENDPOINT"] = YOPT_CHANNEL_REMOTE_ENDPOINT; |
239 | | - lyasio["SEEK_CUR"] = SEEK_CUR; |
240 | | - lyasio["SEEK_SET"] = SEEK_SET; |
241 | | - lyasio["SEEK_END"] = SEEK_END; |
| 216 | +# define YASIO_EXPORT_ENUM(v) lyasio[# v] = v |
| 217 | + YASIO_EXPORT_ENUM(YCM_TCP_CLIENT); |
| 218 | + YASIO_EXPORT_ENUM(YCM_TCP_SERVER); |
| 219 | + YASIO_EXPORT_ENUM(YCM_UDP_CLIENT); |
| 220 | + YASIO_EXPORT_ENUM(YCM_UDP_SERVER); |
| 221 | + YASIO_EXPORT_ENUM(YOPT_CONNECT_TIMEOUT); |
| 222 | + YASIO_EXPORT_ENUM(YOPT_CONNECT_TIMEOUT); |
| 223 | + YASIO_EXPORT_ENUM(YOPT_RECONNECT_TIMEOUT); |
| 224 | + YASIO_EXPORT_ENUM(YOPT_DNS_CACHE_TIMEOUT); |
| 225 | + YASIO_EXPORT_ENUM(YOPT_DEFER_EVENT); |
| 226 | + YASIO_EXPORT_ENUM(YOPT_TCP_KEEPALIVE); |
| 227 | + YASIO_EXPORT_ENUM(YOPT_RESOLV_FUNCTION); |
| 228 | + YASIO_EXPORT_ENUM(YOPT_LOG_FILE); |
| 229 | + YASIO_EXPORT_ENUM(YOPT_LFBFD_PARAMS); |
| 230 | + YASIO_EXPORT_ENUM(YOPT_IO_EVENT_CALLBACK); |
| 231 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_LOCAL_PORT); |
| 232 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_HOST); |
| 233 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_PORT); |
| 234 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_ENDPOINT); |
| 235 | + YASIO_EXPORT_ENUM(YEK_CONNECT_RESPONSE); |
| 236 | + YASIO_EXPORT_ENUM(YEK_CONNECTION_LOST); |
| 237 | + YASIO_EXPORT_ENUM(YEK_PACKET); |
| 238 | + YASIO_EXPORT_ENUM(SEEK_CUR); |
| 239 | + YASIO_EXPORT_ENUM(SEEK_SET); |
| 240 | + YASIO_EXPORT_ENUM(SEEK_END); |
242 | 241 |
|
243 | 242 | return lyasio.push(); /* return 'yasio' table */ |
244 | 243 | } |
@@ -341,16 +340,18 @@ YASIO_API int luaopen_yasio(lua_State *L) |
341 | 340 | .addFunction("stop_service", &io_service::stop_service) |
342 | 341 | .addFunction("dispatch_events", &io_service::dispatch_events) |
343 | 342 | .addFunction("open", &io_service::open) |
344 | | - .addFunction("get_state", &io_service::get_state) |
| 343 | + .addOverloadedFunctions( |
| 344 | + "is_open", static_cast<bool (io_service::*)(size_t) const>(&io_service::is_open), |
| 345 | + static_cast<bool (io_service::*)(transport_ptr) const>(&io_service::is_open)) |
345 | 346 | .addOverloadedFunctions( |
346 | 347 | "close", static_cast<void (io_service::*)(transport_ptr)>(&io_service::close), |
347 | 348 | static_cast<void (io_service::*)(size_t)>(&io_service::close)) |
348 | 349 | .addOverloadedFunctions( |
349 | 350 | "write", |
350 | | - static_cast<void (io_service::*)(transport_ptr transport, std::vector<char> data)>( |
| 351 | + static_cast<int (io_service::*)(transport_ptr transport, std::vector<char> data)>( |
351 | 352 | &io_service::write), |
352 | 353 | [](io_service *service, transport_ptr transport, yasio::obstream *obs) { |
353 | | - service->write(transport, obs->take_buffer()); |
| 354 | + return service->write(transport, obs->take_buffer()); |
354 | 355 | }) |
355 | 356 | .addStaticFunction("set_option", [](io_service *service, int opt, |
356 | 357 | kaguya::VariadicArgType args) { |
@@ -485,30 +486,31 @@ YASIO_API int luaopen_yasio(lua_State *L) |
485 | 486 | lyasio["highp_time"] = &highp_clock<system_clock_t>; |
486 | 487 |
|
487 | 488 | // ##-- yasio enums |
488 | | - lyasio["YCM_TCP_CLIENT"] = YCM_TCP_CLIENT; |
489 | | - lyasio["YCM_TCP_SERVER"] = YCM_TCP_SERVER; |
490 | | - lyasio["YCM_UDP_CLIENT"] = YCM_UDP_CLIENT; |
491 | | - lyasio["YCM_UDP_SERVER"] = YCM_UDP_SERVER; |
492 | | - lyasio["YEK_CONNECT_RESPONSE"] = YEK_CONNECT_RESPONSE; |
493 | | - lyasio["YEK_CONNECTION_LOST"] = YEK_CONNECTION_LOST; |
494 | | - lyasio["YEK_PACKET"] = YEK_PACKET; |
495 | | - lyasio["YOPT_CONNECT_TIMEOUT"] = YOPT_CONNECT_TIMEOUT; |
496 | | - lyasio["YOPT_SEND_TIMEOUT"] = YOPT_CONNECT_TIMEOUT; |
497 | | - lyasio["YOPT_RECONNECT_TIMEOUT"] = YOPT_RECONNECT_TIMEOUT; |
498 | | - lyasio["YOPT_DNS_CACHE_TIMEOUT"] = YOPT_DNS_CACHE_TIMEOUT; |
499 | | - lyasio["YOPT_DEFER_EVENT"] = YOPT_DEFER_EVENT; |
500 | | - lyasio["YOPT_TCP_KEEPALIVE"] = YOPT_TCP_KEEPALIVE; |
501 | | - lyasio["YOPT_RESOLV_FUNCTION"] = YOPT_RESOLV_FUNCTION; |
502 | | - lyasio["YOPT_LOG_FILE"] = YOPT_LOG_FILE; |
503 | | - lyasio["YOPT_LFBFD_PARAMS"] = YOPT_LFBFD_PARAMS; |
504 | | - lyasio["YOPT_IO_EVENT_CALLBACK"] = YOPT_IO_EVENT_CALLBACK; |
505 | | - lyasio["YOPT_CHANNEL_LOCAL_PORT"] = YOPT_CHANNEL_LOCAL_PORT; |
506 | | - lyasio["YOPT_CHANNEL_REMOTE_HOST"] = YOPT_CHANNEL_REMOTE_HOST; |
507 | | - lyasio["YOPT_CHANNEL_REMOTE_PORT"] = YOPT_CHANNEL_REMOTE_PORT; |
508 | | - lyasio["YOPT_CHANNEL_REMOTE_ENDPOINT"] = YOPT_CHANNEL_REMOTE_ENDPOINT; |
509 | | - lyasio["SEEK_CUR"] = SEEK_CUR; |
510 | | - lyasio["SEEK_SET"] = SEEK_SET; |
511 | | - lyasio["SEEK_END"] = SEEK_END; |
| 489 | +# define YASIO_EXPORT_ENUM(v) lyasio[# v] = v |
| 490 | + YASIO_EXPORT_ENUM(YCM_TCP_CLIENT); |
| 491 | + YASIO_EXPORT_ENUM(YCM_TCP_SERVER); |
| 492 | + YASIO_EXPORT_ENUM(YCM_UDP_CLIENT); |
| 493 | + YASIO_EXPORT_ENUM(YCM_UDP_SERVER); |
| 494 | + YASIO_EXPORT_ENUM(YOPT_CONNECT_TIMEOUT); |
| 495 | + YASIO_EXPORT_ENUM(YOPT_CONNECT_TIMEOUT); |
| 496 | + YASIO_EXPORT_ENUM(YOPT_RECONNECT_TIMEOUT); |
| 497 | + YASIO_EXPORT_ENUM(YOPT_DNS_CACHE_TIMEOUT); |
| 498 | + YASIO_EXPORT_ENUM(YOPT_DEFER_EVENT); |
| 499 | + YASIO_EXPORT_ENUM(YOPT_TCP_KEEPALIVE); |
| 500 | + YASIO_EXPORT_ENUM(YOPT_RESOLV_FUNCTION); |
| 501 | + YASIO_EXPORT_ENUM(YOPT_LOG_FILE); |
| 502 | + YASIO_EXPORT_ENUM(YOPT_LFBFD_PARAMS); |
| 503 | + YASIO_EXPORT_ENUM(YOPT_IO_EVENT_CALLBACK); |
| 504 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_LOCAL_PORT); |
| 505 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_HOST); |
| 506 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_PORT); |
| 507 | + YASIO_EXPORT_ENUM(YOPT_CHANNEL_REMOTE_ENDPOINT); |
| 508 | + YASIO_EXPORT_ENUM(YEK_CONNECT_RESPONSE); |
| 509 | + YASIO_EXPORT_ENUM(YEK_CONNECTION_LOST); |
| 510 | + YASIO_EXPORT_ENUM(YEK_PACKET); |
| 511 | + YASIO_EXPORT_ENUM(SEEK_CUR); |
| 512 | + YASIO_EXPORT_ENUM(SEEK_SET); |
| 513 | + YASIO_EXPORT_ENUM(SEEK_END); |
512 | 514 |
|
513 | 515 | return lyasio.push(); /* return 'yasio' table */ |
514 | 516 | } |
|
0 commit comments