Mar 26th 2023 Dev

This commit is contained in:
Ned Wright
2023-03-27 15:06:15 +00:00
parent 5848f1d7e3
commit 3f5a3b27a4
68 changed files with 1534 additions and 1836 deletions

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#ifndef __SHARED_STRING_WRAPPER_H__
#define __SHARED_STRING_WRAPPER_H__
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
using char_alloc = boost::interprocess::allocator<u_char, boost::interprocess::managed_shared_memory::segment_manager>;
using shared_string = boost::interprocess::basic_string<u_char, std::char_traits<u_char>, char_alloc>;
class SharedStringWrapper
{
public:
static void setAlloc(boost::interprocess::managed_shared_memory::segment_manager *_alloc) { alloc = _alloc; }
SharedStringWrapper() : str(alloc) {}
void reserve(size_t size) { str.reserve(size); }
void append(const u_char *data, size_t len) { str.append(data, len); }
size_t size() const { return str.size(); }
shared_string::iterator begin() { return str.begin(); }
shared_string::iterator end() { return str.end(); }
u_char * data() { return str.data(); }
private:
static boost::interprocess::managed_shared_memory::segment_manager *alloc;
shared_string str;
};
using ring_buffer = boost::lockfree::spsc_queue<SharedStringWrapper, boost::lockfree::capacity<200>>;
#endif // __SHARED_STRING_WRAPPER_H__

View File

@@ -16,42 +16,16 @@
#include <iostream>
#include <map>
#include <sstream>
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <sys/time.h>
#include "common.h"
static const int queue_size = 200;
#include "shared_string_wrapper.h"
const int shm_pkt_queue_bad_alloc = -2;
namespace bip = boost::interprocess;
using char_alloc = bip::allocator<u_char, bip::managed_shared_memory::segment_manager>;
using shared_string = bip::basic_string<u_char, std::char_traits<u_char>, char_alloc>;
class SharedStringWrapper
{
public:
static void setAlloc(bip::managed_shared_memory::segment_manager *_alloc) { alloc = _alloc; }
SharedStringWrapper() : str(alloc) {}
void reserve(size_t size) { str.reserve(size); }
void append(const u_char *data, size_t len) { str.append(data, len); }
size_t size() const { return str.size(); }
shared_string::iterator begin() { return str.begin(); }
shared_string::iterator end() { return str.end(); }
private:
static bip::managed_shared_memory::segment_manager *alloc;
shared_string str;
};
bip::managed_shared_memory::segment_manager *SharedStringWrapper::alloc = nullptr;
using ring_buffer = boost::lockfree::spsc_queue<SharedStringWrapper, boost::lockfree::capacity<queue_size>>;
class Impl
{
public:

View File

@@ -1,22 +1,25 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#include "shmpktqueue.h"
#include <string>
#include <sstream>
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include "cptest.h"
#include "maybe_res.h"
#include "../shared_string_wrapper.h"
namespace bip = boost::interprocess;
static const int queue_size = 200;
using char_alloc = bip::allocator<u_char, bip::managed_shared_memory::segment_manager>;
using shared_string = bip::basic_string<u_char, std::char_traits<u_char>, char_alloc>;
using ring_buffer = boost::lockfree::spsc_queue<shared_string, boost::lockfree::capacity<queue_size>>;
using namespace std;
static const int segment_name_len = 128;
@@ -103,8 +106,7 @@ class ShmPktQueueTest : public ::testing::Test {
pop_packet_via_boost()
{
ring_buffer *queue = segment->find_or_construct<ring_buffer>(queue_name)();
char_alloc char_alloc(segment->get_segment_manager());
shared_string node_content(char_alloc);
SharedStringWrapper node_content;
PacketInfo packet_pop_by_boost;
if (queue->pop(node_content)) {