root用户,运行./fastrtps/examples/cpp/dds/HelloWorldExampleSharedMem/DDSHelloWorldExampleSharedMem publisher
创建以下文件描述符
$ ll /dev/shm/
总用量 2232
drwxrwxrwt 2 root root 260 11月 1 09:37 ./
drwxr-xr-x 19 root root 4640 10月 7 13:14 ../
-rw-rw-rw- 1 root root 2122272 11月 1 09:37 fastrtps_fb0567544297e750
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_fb0567544297e750_el
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7400
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_port7400_sl
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7410
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_port7410_el
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7411
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_port7411_el
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7400_mutex
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7410_mutex
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7411_mutex
yong用户,运行./fastrtps/examples/cpp/dds/HelloWorldExampleSharedMem/DDSHelloWorldExampleSharedMem subscriber
$ ll /dev/shm/
总用量 2344
drwxrwxrwt 2 root root 360 11月 1 09:38 ./
drwxr-xr-x 19 root root 4640 10月 7 13:14 ../
-rw-rw-rw- 1 root root 2122272 11月 1 09:37 fastrtps_fb0567544297e750
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_fb0567544297e750_el
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7400
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_port7400_sl
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7410
-rw-rw-rw- 1 root root 52400 11月 1 09:37 fastrtps_port7411
-rw-rw-rw- 1 root root 0 11月 1 09:37 fastrtps_port7411_el
-rw-rw-rw- 1 yong yong 52400 11月 1 09:37 fastrtps_port7412
-rw-rw-rw- 1 yong yong 0 11月 1 09:37 fastrtps_port7412_el
-rw-rw-rw- 1 yong yong 52400 11月 1 09:37 fastrtps_port7413
-rw-rw-rw- 1 yong yong 0 11月 1 09:37 fastrtps_port7413_el
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7400_mutex
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7410_mutex
-rw-rw-rw- 1 root root 32 11月 1 09:37 sem.fastrtps_port7411_mutex
-rw-rw-rw- 1 yong yong 32 11月 1 09:37 sem.fastrtps_port7412_mutex
-rw-rw-rw- 1 yong yong 32 11月 1 09:37 sem.fastrtps_port7413_mutex
fastrtps_fb0567544297e750_el独占锁 只有pub才会创建
el是 RobustExclusiveLock 缩写
sl是RobustSharedLock 缩写
本程序默认 domainId =0、participantId=0
PG=Paricipant Id Gain 默认2
rtps端口计算规则:
应用首个进程的端口计算方法,eg:pid=1;每个进程端口默认+PG(2),eg:Pid=2
Traffic type | Well-known port expression | pid = 1 | pId = 3 |
---|---|---|---|
Metatraffic multicast | 7400 + 250 * domainId | 7400 | 7400 |
Metatraffic unicast | 7400 + 250 * domainId + 10 + 2 * participantId | 7410 | 7412 |
User multicast | 7400 + 250 * domainId + 1 | ||
User unicast | 7400 + 250 * domainId + 11 + 2 * participantId | 7411 | 7413 |
fasrtps 代码: | |||
RTPSParticipantImpl.cpp |
bool RTPSParticipantImpl::createReceiverResources(LocatorList_t& Locator_list,bool ApplyMutation,bool RegisterReceiver)
{//略...for (auto it_loc = Locator_list.begin(); it_loc != Locator_list.end(); ++it_loc){bool ret = m_network_Factory.BuildReceiverResources(*it_loc, newItemsBuffer, max_receiver_buffer_size);if (!ret && ApplyMutation){uint32_t tries = 0;while (!ret && (tries < m_att.builtin.mutation_tries)){tries++;applyLocatorAdaptRule(*it_loc);ret = m_network_Factory.BuildReceiverResources(*it_loc, newItemsBuffer, max_receiver_buffer_size);}}ret_val |= !newItemsBuffer.empty();for (auto it_buffer = newItemsBuffer.begin(); it_buffer != newItemsBuffer.end(); ++it_buffer){std::lock_guard<std::mutex> lock(m_receiverResourcelistMutex);//Push the new items into the ReceiverResource bufferm_receiverResourcelist.emplace_back(*it_buffer);//Create and init the MessageReceiverauto mr = new MessageReceiver(this, (*it_buffer)->max_message_size());m_receiverResourcelist.back().mp_receiver = mr;//Start receptionif (RegisterReceiver){m_receiverResourcelist.back().Receiver->RegisterReceiver(mr);}}newItemsBuffer.clear();}return ret_val;
}Locator_t& RTPSParticipantImpl::applyLocatorAdaptRule(Locator_t& loc)
{// This is a completely made up rule// It is transport responsibility to interpret this new port.loc.port += m_att.port.participantIDGain;return loc;
}