我正在尝试在我的应用程序中构建链表的列表.该列表将包含唯一的IP地址,并且对于每个IP地址,我都有一个应用程序列表.我正在尝试使用unordered_map构建它,将Boost :: boost :: asio :: ip :: address作为键,将std :: list作为值:
#include <boost/unordered/unordered_map.hpp>
#include <iostream>
#include <list>
using namespace boost::asio::ip;
using namespace std;
typedef int ApplicationID;
typedef address IPAddress;
typedef list <ApplicationID> APP_LIST;
typedef boost::unordered::unordered_map <IPAddress, APP_LIST> USER_MAP;
USER_MAP user_map;
Run Code Online (Sandbox Code Playgroud)
后来我尝试获取与IP地址关联的列表,如下所示:
APP_LIST *list = &user_map[ip];
Run Code Online (Sandbox Code Playgroud)
但是我在编译中遇到错误,所以请指出问题是什么?
是否可以使用Boost:IPaddress作为关键功能?
另一个问题是可以使用char [some_size]作为键值吗?
错误输出:
In file included from /boost/functional/hash/hash.hpp:535:0,
from /boost/functional/hash.hpp:6,
from /boost/unordered/unordered_map.hpp:21,
from ipc_module.cpp:18:
/boost/functional/hash/extensions.hpp: In member function ‘std::size_t boost::hash<T>::operator()(const T&) const [with T = boost::asio::ip::address, std::size_t = long unsigned int]’:
/boost/unordered/detail/unique.hpp:331:55: instantiated …Run Code Online (Sandbox Code Playgroud) 任何人都可以给我以下情况的步骤甚至代码:
包含多个线程的进程以及这些线程负责捕获用户定义的信号SIGUSR1.只有这个线程应该能够接收到这个信号,并且在接收到这个信号后我会做一些事情.
在我的情况下,内核模块将信号发送到我的进程ID.然后我的过程负责将它传递给正确的监听线程,该线程还建立了信号处理程序,即信号处理程序不在主线程中.
我已经为一个单线程进程运行了一些代码,但是在多线程环境中运行它时遇到了问题.
我在Linux Ubuntu 12.04.3上使用内核版本3.8.0-29运行我的代码.为了创建流程,我将在Boost Threads和POSIX threads API之间进行混合.
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>
#include <string.h>
/* Value of the last signal caught */
volatile sig_atomic_t sig_value;
static void sig_handler(const int sig_number, siginfo_t *sig_info, void *context)
{
if (sig_number == SIGSEGV)
{
error_sys("Error at address 0x%lx", (long)sig_info->si_addr);
exit(-1);
}
sig_value = sig_number;
}
int init_signal_catcher()
{
struct sigaction sig_action; /* Structure describing the action to be taken when asignal arrives. …Run Code Online (Sandbox Code Playgroud) 考虑我要向容器添加随机数量的项目的情况,即无法预测容器的大小,插入的频率高,插入应该在容器的末尾,除此之外我想删除一个几乎恒定时间的元素.
注意:我还想在共享内存中使用列表或向量.
所以在这种情况下,最好使用std :: vector或std :: list?
Boost库中是否有任何函数,我可以在其中转换并以字符串形式给出IPv4地址:
std::string ip_address = "192.168.0.1";
Run Code Online (Sandbox Code Playgroud)
进入以下"11000000101010000000000000000001"的二进制格式并将其存储在boost :: unit32单元中,或者我应该自己构建函数?
还有什么关于将IPv6地址从std :: string转换为4*unit32,是否有任何函数将其转换为八位字节?