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

Iox #33 implement uds with named pipes #820

Merged
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
11e9770
iox-#33 basic unix domain sockets via NamedPipes implemented
elfenpiff May 26, 2021
eddd4a4
iox-#33 unix domain socket tests are running
elfenpiff May 26, 2021
0256efa
iox-#33 default shared memory size increased to 1gb for windows iox_s…
elfenpiff May 26, 2021
f8873b7
iox-#33 received messages have correct size reserved
elfenpiff May 26, 2021
16545e0
iox-#33 multiple pipes in unix domain socket to handle multiple conne…
elfenpiff May 26, 2021
f2da270
iox-#33 number of pipes is defined via max number of messages
elfenpiff May 26, 2021
7541325
iox-#33 fixed move operator
elfenpiff May 26, 2021
db4d52c
iox-#33 returning dummy values in posix user and group api
elfenpiff May 26, 2021
54be87d
iox-#33 windows pthread mutex implementation is not ipc capable
elfenpiff May 28, 2021
76d95d4
iox-#33 getopt_long adjusted so that the cmdlineparser is always succ…
elfenpiff May 28, 2021
d5d6080
iox-#33 unix domain sockets return fitting errors, unit tests expanded
elfenpiff May 28, 2021
ce2cd8a
iox-#33 activated more tests in CI, unix domain socket valid name cha…
elfenpiff May 28, 2021
537abda
iox-#33 introduce NamedPipe windows abstraction
elfenpiff May 28, 2021
ad42adf
iox-#33 moved named pipe into platforms, introduced NamedPipeSender
elfenpiff May 28, 2021
d0eecb0
iox-#33 introduce and integrate named pipe sender
elfenpiff May 28, 2021
f4128d7
iox-#33 used namedpipe abstraction completely in unix domain sockets
elfenpiff May 28, 2021
ce8876e
iox-#33 fixed wrong pipe name issue
elfenpiff May 28, 2021
24cef45
iox-#33 separated win32 implementation from unix domain socket
elfenpiff May 28, 2021
54978ed
iox-#33 added missing int definition header
elfenpiff May 28, 2021
d950f31
iox-#33 added missing platform socket header
elfenpiff May 28, 2021
5a6f8af
iox-#33 created platform_settings for shared generic platform propert…
elfenpiff May 29, 2021
d74ff1e
iox-#33 implement isValidFileName isValidFilePath in helplets and use…
elfenpiff May 29, 2021
37ab19a
iox-#33 implement unit tests for isValidFileName and isValidFilePath
elfenpiff May 29, 2021
acc9b06
iox-#33 add missing includes for windows, update platform settings va…
elfenpiff May 29, 2021
a94a11f
iox-#33 std::cerr seems to lead to program termination in windows swi…
elfenpiff May 29, 2021
4984799
iox-#33 remove time sensitive test from windows CI
elfenpiff May 29, 2021
24e3c6a
iox-#33 added terminating #endif - whoopsie
elfenpiff Jun 1, 2021
85639a9
iox-#33 implemented named pipe via shared memory
elfenpiff Jun 2, 2021
2465310
iox-#33 adjusted named pipes so that they are ipc capable in the roud…
elfenpiff Jun 2, 2021
17513b7
iox-#33 ipc channel type is set in platform settings
elfenpiff Jun 2, 2021
3e6bd55
iox-#33 activated tests which are now running in windows, removed win…
elfenpiff Jun 2, 2021
4d6f56d
iox-#33 added named pipe documentation, more readable code in isFileN…
elfenpiff Jun 2, 2021
7dee386
iox-#33 discarding result of destroy, fixed constexpr linker issue
elfenpiff Jun 2, 2021
fd73e78
iox-#33 filled grp_t completely with dummy values, implemented syscon…
elfenpiff Jun 7, 2021
8e62d20
iox-#33 add constexpr variables for valid character ranges, add iceor…
elfenpiff Jun 7, 2021
12f2192
iox-#33 use variadic arguments
elfenpiff Jun 7, 2021
b941e94
iox-#33 corrected iox uds socket max message size for windows
elfenpiff Jun 7, 2021
d5c44ec
iox-#33 windows supports a maximum SHM size of 1TB, use VirtualAlloc …
elfenpiff Jun 8, 2021
b6624e6
iox-#33 introduced iox::platform namespace for platform specific sett…
elfenpiff Jun 8, 2021
251ef36
iox-#33 added platform namespace for tests enabled only on posix
elfenpiff Jun 8, 2021
a8a6021
iox-#33 add tests for ASCII_x variables, improve code readability
elfenpiff Jun 8, 2021
84b215c
iox-#33 shm death test is only activated on platforms which are zeroi…
elfenpiff Jun 8, 2021
6f82d50
iox-#33 print warning if cmd line arguments are used in windows, redu…
elfenpiff Jun 8, 2021
7b0e23e
iox-#33 max and zero are public Duration factories, added iceoryx_pre…
elfenpiff Jun 8, 2021
6a92042
iox-#33 shortened prefix for windows
elfenpiff Jun 8, 2021
4f901b0
iox-#33 Fix false positive array out of bounds warning
elBoberido Jun 9, 2021
48e33ae
iox-#33 corrected include guard names, null shm in mac os
elfenpiff Jun 9, 2021
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
7 changes: 4 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ jobs:
# we have to exclude the tests explicitly until everyone is running
- name: Run tests, excluding timing_tests
run: |
build\hoofs\test\Debug\hoofs_moduletests.exe --gtest_filter="-*TimingTest*"
build\hoofs\test\Debug\hoofs_moduletests.exe --gtest_filter="-*TimingTest*:IpcChannel*:Mutex*:UnixDomainSocket*"
build\hoofs\test\Debug\hoofs_integrationtests.exe
build\binding_c\test\Debug\binding_c_moduletests.exe --gtest_filter="-Chunk*:iox_listener*:iox_node*:iox_pub*:BindingC_Runtime*:iox_sub*:iox_ws*:iox_types*:*TimingTest*"
build\posh\test\Debug\posh_moduletests.exe --gtest_filter="-PoshRuntime*:IceoryxRoudiApp*:IceoryxRoudiMemoryManager*:PortManager*:ProcessIntrospection*:ProcessManager*:PosixShmMemoryProvider*:Process_test*:ParseAllMalformedInput*:*TimingTest*"
build\binding_c\test\Debug\binding_c_moduletests.exe --gtest_filter="-BindingC_Runtime*:*TimingTest*"
build\posh\test\Debug\posh_moduletests.exe --gtest_filter="-PoshRuntime*:IceoryxRoudiApp*:IceoryxRoudiMemoryManager*:ProcessIntrospection*:ParseAllMalformedInput*:*TimingTest*"
build\posh\test\Debug\posh_integrationtests.exe --gtest_filter="-*ChunkBuildingBlocks*:PortUser*:RoudiFindService*:*TimingTest*"
6 changes: 6 additions & 0 deletions iceoryx_binding_c/include/iceoryx_binding_c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct iox_user_trigger_storage_t_
// sizeof(UserTrigger) / 8
#if defined(__APPLE__)
uint64_t do_not_touch_me[17];
#elif defined(_WIN32)
uint64_t do_not_touch_me[16];
#else
uint64_t do_not_touch_me[14];
#endif
Expand All @@ -57,6 +59,8 @@ struct iox_sub_storage_t_
// sizeof(cpp2c_Subscriber) / 8
#if defined(__APPLE__)
uint64_t do_not_touch_me[17];
#elif defined(_WIN32)
uint64_t do_not_touch_me[17];
#else
uint64_t do_not_touch_me[14];
#endif
Expand All @@ -77,6 +81,8 @@ struct iox_listener_storage_t_
// sizeof(Listener) / 8
#if defined(__APPLE__)
uint64_t do_not_touch_me[2643];
#elif defined(_WIN32)
uint64_t do_not_touch_me[2774];
#else
uint64_t do_not_touch_me[2567];
#endif
Expand Down
1 change: 1 addition & 0 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ add_library(iceoryx_hoofs
source/posix_wrapper/shared_memory_object.cpp
source/posix_wrapper/signal_handler.cpp
source/posix_wrapper/message_queue.cpp
source/posix_wrapper/named_pipe.cpp
source/posix_wrapper/unix_domain_socket.cpp
source/posix_wrapper/shared_memory_object/allocator.cpp
source/posix_wrapper/shared_memory_object/memory_map.cpp
Expand Down
29 changes: 29 additions & 0 deletions iceoryx_hoofs/include/iceoryx_hoofs/cxx/helplets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@

#include <assert.h>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits>
#include <type_traits>

#include "iceoryx_hoofs/platform/platform_correction.hpp"
#include "iceoryx_hoofs/platform/platform_settings.hpp"

namespace iox
{
namespace cxx
{
template <uint64_t Capacity>
class string;
struct TruncateToCapacity_t;

namespace internal
{
inline void
Expand Down Expand Up @@ -66,6 +72,17 @@ struct BestFittingTypeImpl<true, true, false>
{
using Type_t = uint32_t;
};

constexpr char ASCII_A = 'a';
constexpr char ASCII_Z = 'z';
constexpr char ASCII_CAPITAL_A = 'A';
constexpr char ASCII_CAPITAL_Z = 'Z';
constexpr char ASCII_0 = '0';
constexpr char ASCII_9 = '9';
constexpr char ASCII_MINUS = '-';
constexpr char ASCII_DOT = '.';
constexpr char ASCII_COLON = ':';
constexpr char ASCII_UNDERSCORE = '_';
} // namespace internal

// implementing C++ Core Guideline, I.6. Prefer Expects
Expand Down Expand Up @@ -250,7 +267,19 @@ constexpr bool isPowerOfTwo(const T n)
return n && ((n & (n - 1U)) == 0U);
}

/// @brief checks if the given string is a valid filename
/// @return true if the string is a filename, otherwise false
template <uint64_t StringCapacity>
bool isValidFileName(const string<StringCapacity>& name) noexcept;

/// @brief verifies if the given string is a valid path to a file
/// @return true if the string is a path to a file, otherwise false
template <uint64_t StringCapacity>
bool isValidFilePath(const string<StringCapacity>& name) noexcept;

} // namespace cxx
} // namespace iox

#include "iceoryx_hoofs/internal/cxx/helplets.inl"

#endif // IOX_HOOFS_CXX_HELPLETS_HPP
132 changes: 132 additions & 0 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/helplets.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_HELPLETS_INL
#define IOX_HOOFS_CXX_HELPLETS_INL

namespace iox
{
namespace cxx
{
template <uint64_t StringCapacity>
inline bool isValidFileName(const string<StringCapacity>& name) noexcept
{
if (name.empty())
{
return false;
}

uint64_t nameSize = name.size();

const string<StringCapacity> currentDirectory(".");
const string<StringCapacity> parentDirectory("..");

if (name == currentDirectory || name == parentDirectory)
{
return false;
}

// dot at the end is invalid to be compatible with windows api
const char lastCharacter = name.c_str()[nameSize - 1U];
if (lastCharacter == '.')
{
return false;
}

// check if the file contains only valid characters
for (uint64_t i = 0; i < nameSize; ++i)
{
const char c = name.c_str()[i];
if (!((internal::ASCII_A <= c && c <= internal::ASCII_Z)
|| (internal::ASCII_CAPITAL_A <= c && c <= internal::ASCII_CAPITAL_Z)
|| (internal::ASCII_0 <= c && c <= internal::ASCII_9) || c == internal::ASCII_MINUS
|| c == internal::ASCII_DOT || c == internal::ASCII_COLON || c == internal::ASCII_UNDERSCORE))
{
return false;
}
}

return true;
}

template <uint64_t StringCapacity>
inline bool isValidFilePath(const string<StringCapacity>& name) noexcept
{
if (name.empty())
{
return false;
}

uint64_t nameSize = name.size();

// a file path ends with the filename and not the path separator, only a
// directory can end with a path separator
auto numberOfPathSeparators = strlen(platform::IOX_PATH_SEPARATORS);
for (uint64_t i = 0; i < numberOfPathSeparators; ++i)
{
const char lastCharacter = name.c_str()[nameSize - 1U];
if (lastCharacter == platform::IOX_PATH_SEPARATORS[i])
{
return false;
}
}

auto temp = name;
elfenpiff marked this conversation as resolved.
Show resolved Hide resolved

const string<StringCapacity> currentDirectory(".");
const string<StringCapacity> parentDirectory("..");

while (!temp.empty())
{
auto separatorPosition = temp.find_first_of(platform::IOX_PATH_SEPARATORS);

// multiple slashes are explicitly allowed. the following paths
// are equivalent:
// /some/fuu/bar
// //some///fuu////bar
if (separatorPosition && *separatorPosition == 0)
{
temp = *temp.substr(*separatorPosition + 1);
continue;
}

// verify if the entry between two path separators is a valid directory
// name, e.g. either it has the relative component . or .. or conforms
// with a valid file name
if (separatorPosition)
{
auto filenameToVerify = temp.substr(0, *separatorPosition);
bool isValidDirectory = isValidFileName(*filenameToVerify) || *filenameToVerify == currentDirectory
|| *filenameToVerify == parentDirectory;
if (!isValidDirectory)
{
return false;
}

temp = *temp.substr(*separatorPosition + 1);
}
// we reached the last entry, if its a valid file name the path is valid
else if (!separatorPosition)
{
return isValidFileName(temp);
}
}

return false;
}
} // namespace cxx
} // namespace iox

#endif
6 changes: 1 addition & 5 deletions iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/string.inl
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,7 @@ inline iox::cxx::optional<string<Capacity>> string<Capacity>::substr(const uint6
return iox::cxx::nullopt;
}

uint64_t length = count;
if (m_rawstringSize < (pos + count))
{
length = m_rawstringSize - pos;
}
uint64_t length = std::min(count, m_rawstringSize - pos);
string subString;
std::memcpy(&(subString.m_rawstring[0]), &m_rawstring[pos], length);
subString.m_rawstring[length] = '\0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static constexpr const char* ACCESS_MODE_STRING[] = {"AccessMode::READ_ONLY", "A
enum class OwnerShip : uint64_t
{
MINE = 0U,
OPEN_EXISTING = 1U
OPEN_EXISTING_SHM = 1U
};
static constexpr const char* OWNERSHIP_STRING[] = {"OwnerShip::MINE", "OwnerShip::OPEN_EXISTING"};
static constexpr const char* OWNERSHIP_STRING[] = {"OwnerShip::MINE", "OwnerShip::OPEN_EXISTING_SHM"};

enum class SharedMemoryError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/units/duration.hpp"
#include "iceoryx_hoofs/platform/fcntl.hpp"
#include "iceoryx_hoofs/platform/mqueue.hpp"
#include "iceoryx_hoofs/platform/platform_settings.hpp"
#include "iceoryx_hoofs/platform/socket.hpp"
#include "iceoryx_hoofs/platform/stat.hpp"
#include "iceoryx_hoofs/platform/un.hpp"

Expand All @@ -38,16 +39,13 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha
{
};
static constexpr NoPathPrefix_t NoPathPrefix{};
static constexpr char PATH_PREFIX[] = "/tmp/";

static constexpr uint64_t NULL_TERMINATOR_SIZE = 1U;
/// @brief Max message size is on linux = 4096 and on mac os = 2048. To have
/// the same behavior on every platform we use 2048.
static constexpr uint64_t MAX_MESSAGE_SIZE = 2048U - NULL_TERMINATOR_SIZE;
/// @brief The name length is limited by the size of the sockaddr_un::sun_path buffer and the path prefix
static constexpr uint64_t MAX_MESSAGE_SIZE = platform::IOX_UDS_SOCKET_MAX_MESSAGE_SIZE - NULL_TERMINATOR_SIZE;
/// @brief The name length is limited by the size of the sockaddr_un::sun_path buffer and the IOX_SOCKET_PATH_PREFIX
static constexpr size_t LONGEST_VALID_NAME = sizeof(sockaddr_un::sun_path) - 1;

using UdsName_t = cxx::string<LONGEST_VALID_NAME>;
using Message_t = cxx::string<MAX_MESSAGE_SIZE>;

/// @brief for calling private constructor in create method
friend class DesignPattern::Creation<UnixDomainSocket, IpcChannelError>;
Expand Down Expand Up @@ -125,7 +123,6 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha
const size_t maxMsgSize = MAX_MESSAGE_SIZE,
const uint64_t maxMsgNumber = 10U) noexcept;


/// @brief initializes the unix domain socket
/// @return IpcChannelError if error occured
cxx::expected<IpcChannelError> initalizeSocket() noexcept;
Expand All @@ -134,8 +131,6 @@ class UnixDomainSocket : public DesignPattern::Creation<UnixDomainSocket, IpcCha
/// @return IpcChannelError if error occured
IpcChannelError convertErrnoToIpcChannelError(const int32_t errnum) const noexcept;

static bool isNameValid(const UdsName_t& name) noexcept;

/// @brief Tries to close the file descriptor
/// @return IpcChannelError if error occured
cxx::expected<IpcChannelError> closeFileDescriptor() noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ class Duration
template <typename T>
static constexpr Duration fromDays(const T value) noexcept;

/// @brief Constructs a new Duration object of maximum allowed length. Useful for functions which should have an
/// "infinite" timeout.
static constexpr Duration max() noexcept;

/// @brief Constructs a new Duration object with a duration of zero
static constexpr Duration zero() noexcept;
// END CREATION FROM STATIC FUNCTIONS

// BEGIN CONSTRUCTORS AND ASSIGNMENT
Expand Down Expand Up @@ -313,9 +319,6 @@ class Duration
/// from public methods
static constexpr Duration createDuration(const Seconds_t seconds, const Nanoseconds_t nanoseconds) noexcept;

static constexpr Duration max() noexcept;
static constexpr Duration zero() noexcept;

private:
template <typename T, typename String>
static constexpr unsigned long long int positiveValueOrClampToZero(const T value, const String fromMethod) noexcept;
Expand Down
Loading