aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.rst12
-rw-r--r--cmake/Modules/FindLibuv.cmake106
3 files changed, 114 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4769b38..b441591 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,7 @@ project(Salticidae)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
-find_package(Libevent REQUIRED)
+find_package(Libuv REQUIRED)
find_package(OpenSSL REQUIRED)
include_directories(include)
diff --git a/README.rst b/README.rst
index 03fef81..2a40304 100644
--- a/README.rst
+++ b/README.rst
@@ -67,7 +67,6 @@ Example (MsgNetwork layer)
--------------------------
.. code-block:: cpp
-
#include <cstdio>
#include <string>
#include <functional>
@@ -135,8 +134,8 @@ Example (MsgNetwork layer)
reg_handler(salticidae::generic_bind(
&MyNet::on_receive_hello, this, _1, _2));
- reg_conn_handler([this](ConnPool::Conn &conn) {
- if (conn.get_fd() != -1)
+ reg_conn_handler([this](ConnPool::Conn &conn, bool connected) {
+ if (connected)
{
if (conn.get_mode() == ConnPool::Conn::ACTIVE)
{
@@ -175,8 +174,8 @@ Example (MsgNetwork layer)
}
salticidae::EventContext ec;
- NetAddr alice_addr("127.0.0.1:1234");
- NetAddr bob_addr("127.0.0.1:1235");
+ NetAddr alice_addr("127.0.0.1:12345");
+ NetAddr bob_addr("127.0.0.1:12346");
int main() {
/* test two nodes */
@@ -187,6 +186,9 @@ Example (MsgNetwork layer)
alice.reg_handler(on_receive_ack);
bob.reg_handler(on_receive_ack);
+ alice.start();
+ bob.start();
+
alice.listen(alice_addr);
bob.listen(bob_addr);
diff --git a/cmake/Modules/FindLibuv.cmake b/cmake/Modules/FindLibuv.cmake
new file mode 100644
index 0000000..e708225
--- /dev/null
+++ b/cmake/Modules/FindLibuv.cmake
@@ -0,0 +1,106 @@
+# This script is pasted from https://github.com/neovim/neovim/blob/master/cmake/FindLibUV.cmake
+#
+# - Try to find libuv
+# Once done, this will define
+#
+# LIBUV_FOUND - system has libuv
+# LIBUV_INCLUDE_DIRS - the libuv include directories
+# LIBUV_LIBRARIES - link these to use libuv
+#
+# Set the LIBUV_USE_STATIC variable to specify if static libraries should
+# be preferred to shared ones.
+
+if(NOT USE_BUNDLED_LIBUV)
+ find_package(PkgConfig)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_LIBUV QUIET libuv)
+ endif()
+else()
+ set(PC_LIBUV_INCLUDEDIR)
+ set(PC_LIBUV_INCLUDE_DIRS)
+ set(PC_LIBUV_LIBDIR)
+ set(PC_LIBUV_LIBRARY_DIRS)
+ set(LIMIT_SEARCH NO_DEFAULT_PATH)
+endif()
+
+find_path(LIBUV_INCLUDE_DIR uv.h
+ HINTS ${PC_LIBUV_INCLUDEDIR} ${PC_LIBUV_INCLUDE_DIRS}
+ ${LIMIT_SEARCH})
+
+# If we're asked to use static linkage, add libuv.a as a preferred library name.
+if(LIBUV_USE_STATIC)
+ list(APPEND LIBUV_NAMES
+ "${CMAKE_STATIC_LIBRARY_PREFIX}uv${CMAKE_STATIC_LIBRARY_SUFFIX}")
+endif(LIBUV_USE_STATIC)
+
+list(APPEND LIBUV_NAMES uv)
+
+find_library(LIBUV_LIBRARY NAMES ${LIBUV_NAMES}
+ HINTS ${PC_LIBUV_LIBDIR} ${PC_LIBUV_LIBRARY_DIRS}
+ ${LIMIT_SEARCH})
+
+mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)
+
+if(PC_LIBUV_LIBRARIES)
+ list(REMOVE_ITEM PC_LIBUV_LIBRARIES uv)
+endif()
+
+set(LIBUV_LIBRARIES ${LIBUV_LIBRARY} ${PC_LIBUV_LIBRARIES})
+set(LIBUV_INCLUDE_DIRS ${LIBUV_INCLUDE_DIR})
+
+# Deal with the fact that libuv.pc is missing important dependency information.
+
+include(CheckLibraryExists)
+
+check_library_exists(dl dlopen "dlfcn.h" HAVE_LIBDL)
+if(HAVE_LIBDL)
+ list(APPEND LIBUV_LIBRARIES dl)
+endif()
+
+check_library_exists(kstat kstat_lookup "kstat.h" HAVE_LIBKSTAT)
+if(HAVE_LIBKSTAT)
+ list(APPEND LIBUV_LIBRARIES kstat)
+endif()
+
+check_library_exists(kvm kvm_open "kvm.h" HAVE_LIBKVM)
+if(HAVE_LIBKVM AND NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+ list(APPEND LIBUV_LIBRARIES kvm)
+endif()
+
+check_library_exists(nsl gethostbyname "nsl.h" HAVE_LIBNSL)
+if(HAVE_LIBNSL)
+ list(APPEND LIBUV_LIBRARIES nsl)
+endif()
+
+check_library_exists(perfstat perfstat_cpu "libperfstat.h" HAVE_LIBPERFSTAT)
+if(HAVE_LIBPERFSTAT)
+ list(APPEND LIBUV_LIBRARIES perfstat)
+endif()
+
+check_library_exists(rt clock_gettime "time.h" HAVE_LIBRT)
+if(HAVE_LIBRT)
+ list(APPEND LIBUV_LIBRARIES rt)
+endif()
+
+check_library_exists(sendfile sendfile "" HAVE_LIBSENDFILE)
+if(HAVE_LIBSENDFILE)
+ list(APPEND LIBUV_LIBRARIES sendfile)
+endif()
+
+if(WIN32)
+ # check_library_exists() does not work for Win32 API calls in X86 due to name
+ # mangling calling conventions
+ list(APPEND LIBUV_LIBRARIES iphlpapi)
+ list(APPEND LIBUV_LIBRARIES psapi)
+ list(APPEND LIBUV_LIBRARIES userenv)
+ list(APPEND LIBUV_LIBRARIES ws2_32)
+endif()
+
+include(FindPackageHandleStandardArgs)
+
+# handle the QUIETLY and REQUIRED arguments and set LIBUV_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(LibUV DEFAULT_MSG
+ LIBUV_LIBRARY LIBUV_INCLUDE_DIR)
+
+mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY)