Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event framework based on epoll, kqueue and select #1080

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ install(
COMPONENT dev
)

add_subdirectory(compat)
add_subdirectory(src)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
Expand Down
52 changes: 0 additions & 52 deletions cmake/Modules/GenerateDummyExportHeader.cmake

This file was deleted.

3 changes: 2 additions & 1 deletion cmake/Modules/GenerateExportHeader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if(_include_file)

cmake_parse_arguments(_GEHW "${_opts}" "${_single_opts}" "${_multi_opts}" ${ARGN})

string(MAKE_C_IDENTIFIER "${TARGET_LIBRARY}" _target_name)
set(_prefix_name "${_GEHW_PREFIX_NAME}")
set(_base_name "${TARGET_LIBRARY}")

Expand All @@ -56,7 +57,7 @@ if(_include_file)
set(_custom_content
"
#ifndef ${_prefix_name}${_base_name_upper}_INLINE_EXPORT
# if __MINGW32__ && (!defined(__clang__) || !defined(${TARGET_LIBRARY}_EXPORTS))
# if __MINGW32__ && (!defined(__clang__) || !defined(${_target_name}_EXPORTS))
# define ${_prefix_name}${_base_name_upper}_INLINE_EXPORT
# else
# define ${_prefix_name}${_base_name_upper}_INLINE_EXPORT ${_prefix_name}${_base_name_upper}_EXPORT
Expand Down
10 changes: 10 additions & 0 deletions compat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include(CheckIncludeFile)

check_include_file(getopt.h HAVE_GETOPT_H)
if(WIN32 OR NOT HAVE_GETOPT_H)
add_library(compat OBJECT)
target_include_directories(compat INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
target_sources(compat PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/getopt.c")
else()
add_library(compat INTERFACE)
endif()
File renamed without changes.
12 changes: 5 additions & 7 deletions src/ddsrt/include/getopt.h.in → compat/getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
#ifndef GETOPT_H
#define GETOPT_H

#include "dds/export.h"
extern int opterr;
extern int optind;
extern int optopt;
extern char *optarg;

DDS_EXPORT extern int opterr;
DDS_EXPORT extern int optind;
DDS_EXPORT extern int optopt;
DDS_EXPORT extern char *optarg;

DDS_EXPORT int getopt(int argc, char **argv, const char *opts);
int getopt(int argc, char **argv, const char *opts);

#endif /* GETOPT_H */
56 changes: 13 additions & 43 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,61 +22,34 @@ function(PREPEND var prefix)
set(${var} "${listVar}" PARENT_SCOPE)
endfunction()

# Generate a header file listing compile-time options relevant to the API. Define to
# "1" if enabled so that the generated features.h ends up having either
#
# - #define DDS_HAS_SECURITY 1
# or
# - /* #undef DDS_HAS_SECURITY */
#
# which caters both for those who prefer #ifdef DDS_HAS_SECURITY and for those who prefer
# #if DDS_HAS_SECURITY.
option(ENABLE_SECURITY "Enable OMG DDS Security support" ON)
option(ENABLE_LIFESPAN "Enable Lifespan QoS support" ON)
option(ENABLE_DEADLINE_MISSED "Enable Deadline Missed QoS support" ON)
option(ENABLE_NETWORK_PARTITIONS "Enable network partition support" ON)
option(ENABLE_SOURCE_SPECIFIC_MULTICAST "Enable support for source-specific multicast" ON)
option(ENABLE_TYPE_DISCOVERY "Enable Type Discovery support" OFF)
option(ENABLE_TOPIC_DISCOVERY "Enable Topic Discovery support" OFF)
option(ENABLE_SHM "Enable shared memory support" ON)
if(ENABLE_SECURITY)
set(DDS_HAS_SECURITY "1")
endif()
if(ENABLE_LIFESPAN)
set(DDS_HAS_LIFESPAN "1")
endif()
if(ENABLE_DEADLINE_MISSED)
set(DDS_HAS_DEADLINE_MISSED "1")
endif()
if(ENABLE_NETWORK_PARTITIONS)
set(DDS_HAS_NETWORK_PARTITIONS "1")
endif()
if(ENABLE_SOURCE_SPECIFIC_MULTICAST)
set(DDS_HAS_SSM "1")
endif()
if(ENABLE_TYPE_DISCOVERY)
set(DDS_HAS_TYPE_DISCOVERY "1")
endif()
if(ENABLE_TOPIC_DISCOVERY)
if(NOT ENABLE_TYPE_DISCOVERY)
message(FATAL_ERROR "ENABLE_TOPIC_DISCOVERY requires ENABLE_TYPE_DISCOVERY to be enabled")
endif()
set(DDS_HAS_TOPIC_DISCOVERY "1")
endif()

option(CYCLONE_BUILD_WITH_ICEORYX "iceoryx not found by default" OFF)
if(ENABLE_SOURCE_SPECIFIC_MULTICAST)
set(ENABLE_SSM ON)
endif()

# Prefer iceoryx integration but do not require it.
set(ENABLE_SHM "AUTO" CACHE STRING "Enable shared memory support")
set_property(CACHE ENABLE_SHM PROPERTY STRINGS ON OFF AUTO)
if(ENABLE_SHM)
if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin OR CMAKE_SYSTEM_NAME MATCHES QNX)
message(STATUS "Linux/MacOS/QNX system found, trying to find iceoryx...")
find_package(iceoryx_binding_c QUIET)
if(iceoryx_binding_c_FOUND)
set(CYCLONE_BUILD_WITH_ICEORYX TRUE CACHE BOOL "Iceoryx found!" FORCE)
set(DDS_HAS_SHM "1")
message(STATUS "Build CycloneDDS with iceoryx shared memory support!")
else()
message(STATUS "iceoryx not found, falling back to loopback communication.")
endif()
if(NOT ENABLE_SHM STREQUAL "AUTO")
set(iceoryx_required REQUIRED)
else()
set(iceoryx_required QUIET)
endif()
find_package(iceoryx_binding_c ${iceoryx_required})
set(ENABLE_SHM ${iceoryx_binding_c_FOUND} CACHE STRING "" FORCE)
endif()

# ones that linger in the sources
Expand All @@ -98,7 +71,6 @@ endif()
if(ENABLE_SSL)
find_package(OpenSSL)
if(OPENSSL_FOUND)
set(DDS_HAS_SSL "1")
message(STATUS "Building with OpenSSL support")
else()
message(STATUS "Building without OpenSSL support")
Expand All @@ -109,8 +81,6 @@ if(NOT ENABLE_SECURITY)
message(STATUS "Building without OMG DDS Security support")
endif()

configure_file(features.h.in "${CMAKE_CURRENT_BINARY_DIR}/core/include/dds/features.h")

add_subdirectory(tools)
add_subdirectory(ddsrt)
if(BUILD_IDLC)
Expand Down
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if(ENABLE_SECURITY)
$<BUILD_INTERFACE:$<TARGET_PROPERTY:security_api,INTERFACE_INCLUDE_DIRECTORIES>>)
endif()

if(iceoryx_binding_c_FOUND)
if(ENABLE_SHM)
target_link_libraries(ddsc PRIVATE iceoryx_binding_c::iceoryx_binding_c)
endif()

Expand Down
7 changes: 3 additions & 4 deletions src/core/ddsc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ prepend(srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/"
dds_data_allocator.c
dds_loan.c)

if (DDS_HAS_SHM)
if(ENABLE_SHM)
list(APPEND srcs_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/shm_monitor.c")
endif()

Expand Down Expand Up @@ -91,7 +91,7 @@ prepend(hdrs_public_ddsc "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<
ddsc/dds_data_allocator.h
ddsc/dds_loan_api.h)

if (DDS_HAS_SHM)
if(ENABLE_SHM)
list(APPEND hdrs_private_ddsc "${CMAKE_CURRENT_LIST_DIR}/src/shm__monitor.h")
endif()

Expand All @@ -104,8 +104,7 @@ target_sources(ddsc
${hdrs_private_ddsc}
PUBLIC
${hdrs_public_ddsc}
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>$<INSTALL_INTERFACE:include>/dds/export.h"
)
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>$<INSTALL_INTERFACE:include>/dds/export.h")

target_include_directories(ddsc
PUBLIC
Expand Down
6 changes: 3 additions & 3 deletions src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ target_include_directories(
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src/include/>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsc/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>")
if(iceoryx_binding_c_FOUND)
if(ENABLE_SHM)
target_include_directories(
cunit_ddsc PRIVATE
"$<BUILD_INTERFACE:$<TARGET_PROPERTY:iceoryx_binding_c::iceoryx_binding_c,INTERFACE_INCLUDE_DIRECTORIES>>")
Expand Down Expand Up @@ -139,7 +139,7 @@ target_include_directories(
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsc/src>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsi/include>")

if(iceoryx_binding_c_FOUND)
if(ENABLE_SHM)
target_include_directories(
oneliner PRIVATE
"$<BUILD_INTERFACE:$<TARGET_PROPERTY:iceoryx_binding_c::iceoryx_binding_c,INTERFACE_INCLUDE_DIRECTORIES>>")
Expand All @@ -150,7 +150,7 @@ target_link_libraries(oneliner PRIVATE RoundTrip Space ddsc)
# Iceoryx itself isn't really supported yet on Windows, so it
# better not be part of the tests. That also saves us from
# having to figure out now how to start/stop RouDi on Windows.
if(iceoryx_binding_c_FOUND AND NOT WIN32)
if(ENABLE_SHM)
idlc_generate(TARGET Array100 FILES Array100.idl)
idlc_generate(TARGET DynamicData FILES DynamicData.idl)

Expand Down
5 changes: 2 additions & 3 deletions src/core/ddsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ set(srcs_ddsi
q_qosmatch.c
q_radmin.c
q_receive.c
q_sockwaitset.c
q_thread.c
q_transmit.c
q_inverse_uint32_set.c
Expand Down Expand Up @@ -152,14 +151,14 @@ set(hdrs_private_ddsi
q_radmin.h
q_receive.h
q_rtps.h
q_sockwaitset.h
q_thread.h
q_transmit.h
q_inverse_uint32_set.h
q_unused.h
q_whc.h
q_xevent.h
q_xmsg.h
q_receive.h
sysdeps.h)

if(ENABLE_LIFESPAN)
Expand All @@ -178,7 +177,7 @@ if(ENABLE_SECURITY)
list(APPEND srcs_ddsi ddsi_security_msg.c ddsi_security_exchange.c)
list(APPEND hdrs_private_ddsi ddsi_security_msg.h ddsi_security_exchange.h)
endif()
if(iceoryx_binding_c_FOUND)
if(ENABLE_SHM)
list(APPEND srcs_ddsi ddsi_shm_transport.c)
list(APPEND hdrs_private_ddsi ddsi_shm_transport.h)
endif()
Expand Down
4 changes: 2 additions & 2 deletions src/core/ddsi/include/dds/ddsi/ddsi_domaingv.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include "dds/ddsrt/sync.h"
#include "dds/ddsrt/fibheap.h"
#include "dds/ddsrt/avl.h"
#include "dds/ddsrt/event.h"

#include "dds/ddsi/ddsi_plist.h"
#include "dds/ddsi/ddsi_ownip.h"
#include "dds/ddsi/q_protocol.h"
#include "dds/ddsi/q_sockwaitset.h"
#include "dds/ddsi/q_config.h"

#if defined (__cplusplus)
Expand Down Expand Up @@ -80,7 +80,7 @@ struct recv_thread_arg {
struct ddsi_tran_conn *conn;
} single;
struct {
os_sockWaitset ws;
ddsrt_loop_t loop;
} many;
} u;
};
Expand Down
12 changes: 12 additions & 0 deletions src/core/ddsi/include/dds/ddsi/ddsi_tran.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* DDSI Transport module */

#include "dds/ddsrt/event.h"
#include "dds/ddsrt/ifaddrs.h"
#include "dds/ddsrt/atomics.h"
#include "dds/ddsi/ddsi_locator.h"
Expand Down Expand Up @@ -50,6 +51,7 @@ typedef ssize_t (*ddsi_tran_write_fn_t) (ddsi_tran_conn_t, const ddsi_locator_t
typedef int (*ddsi_tran_locator_fn_t) (ddsi_tran_factory_t, ddsi_tran_base_t, ddsi_locator_t *);
typedef bool (*ddsi_tran_supports_fn_t) (const struct ddsi_tran_factory *, int32_t);
typedef ddsrt_socket_t (*ddsi_tran_handle_fn_t) (ddsi_tran_base_t);
typedef ddsrt_event_t *(*ddsi_tran_event_fn_t) (ddsi_tran_base_t);
typedef int (*ddsi_tran_listen_fn_t) (ddsi_tran_listener_t);
typedef void (*ddsi_tran_free_fn_t) (ddsi_tran_factory_t);
typedef void (*ddsi_tran_peer_locator_fn_t) (ddsi_tran_conn_t, ddsi_locator_t *);
Expand Down Expand Up @@ -104,6 +106,7 @@ struct ddsi_tran_base
/* Functions */

ddsi_tran_handle_fn_t m_handle_fn;
ddsi_tran_event_fn_t m_event_fn;
};

struct ddsi_tran_conn
Expand Down Expand Up @@ -262,9 +265,15 @@ void ddsi_tran_free (ddsi_tran_base_t base);
DDS_INLINE_EXPORT inline ddsrt_socket_t ddsi_tran_handle (ddsi_tran_base_t base) {
return base->m_handle_fn (base);
}
DDS_INLINE_EXPORT inline ddsrt_event_t *ddsi_tran_event (ddsi_tran_base_t base) {
return base->m_event_fn (base);
}
DDS_INLINE_EXPORT inline ddsrt_socket_t ddsi_conn_handle (ddsi_tran_conn_t conn) {
return conn->m_base.m_handle_fn (&conn->m_base);
}
DDS_INLINE_EXPORT inline ddsrt_event_t *ddsi_conn_event (ddsi_tran_conn_t conn) {
return conn->m_base.m_event_fn (&conn->m_base);
}
DDS_INLINE_EXPORT inline uint32_t ddsi_conn_type (const struct ddsi_tran_conn *conn) {
return conn->m_base.m_trantype;
}
Expand Down Expand Up @@ -326,6 +335,9 @@ DDS_INLINE_EXPORT inline int ddsi_listener_listen (ddsi_tran_listener_t listener
DDS_INLINE_EXPORT inline ddsi_tran_conn_t ddsi_listener_accept (ddsi_tran_listener_t listener) {
return listener->m_accept_fn (listener);
}
DDS_INLINE_EXPORT inline ddsrt_event_t *ddsi_listener_event (ddsi_tran_listener_t listener) {
return listener->m_base.m_event_fn (&listener->m_base);
}
void ddsi_listener_unblock (ddsi_tran_listener_t listener);
void ddsi_listener_free (ddsi_tran_listener_t listener);

Expand Down
Loading