Apollo 10.0
自动驾驶开放平台
apollo::cyber::transport::MulticastNotifier类 参考

#include <multicast_notifier.h>

类 apollo::cyber::transport::MulticastNotifier 继承关系图:
apollo::cyber::transport::MulticastNotifier 的协作图:

Public 成员函数

virtual ~MulticastNotifier ()
 
void Shutdown () override
 
bool Notify (const ReadableInfo &info) override
 
bool Listen (int timeout_ms, ReadableInfo *info) override
 
- Public 成员函数 继承自 apollo::cyber::transport::NotifierBase
virtual ~NotifierBase ()=default
 

静态 Public 成员函数

static const char * Type ()
 

详细描述

在文件 multicast_notifier.h30 行定义.

构造及析构函数说明

◆ ~MulticastNotifier()

apollo::cyber::transport::MulticastNotifier::~MulticastNotifier ( )
virtual

在文件 multicast_notifier.cc43 行定义.

成员函数说明

◆ Listen()

bool apollo::cyber::transport::MulticastNotifier::Listen ( int  timeout_ms,
ReadableInfo info 
)
overridevirtual

实现了 apollo::cyber::transport::NotifierBase.

在文件 multicast_notifier.cc76 行定义.

76 {
77 if (is_shutdown_.load()) {
78 return false;
79 }
80
81 if (info == nullptr) {
82 AERROR << "info nullptr.";
83 return false;
84 }
85
86 struct pollfd fds;
87 fds.fd = listen_fd_;
88 fds.events = POLLIN;
89 int ready_num = poll(&fds, 1, timeout_ms);
90 if (ready_num > 0) {
91 char buf[32] = {0}; // larger than ReadableInfo::kSize
92 ssize_t nbytes = recvfrom(listen_fd_, buf, 32, 0, nullptr, nullptr);
93 if (nbytes == -1) {
94 AERROR << "fail to recvfrom, " << strerror(errno);
95 return false;
96 }
97 return info->DeserializeFrom(buf, nbytes);
98 } else if (ready_num == 0) {
99 ADEBUG << "timeout, no readableinfo.";
100 } else {
101 if (errno == EINTR) {
102 AINFO << "poll was interrupted.";
103 } else {
104 AERROR << "fail to poll, " << strerror(errno);
105 }
106 }
107 return false;
108}
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ Notify()

bool apollo::cyber::transport::MulticastNotifier::Notify ( const ReadableInfo info)
overridevirtual

实现了 apollo::cyber::transport::NotifierBase.

在文件 multicast_notifier.cc63 行定义.

63 {
64 if (is_shutdown_.load()) {
65 return false;
66 }
67
68 std::string info_str;
69 info.SerializeTo(&info_str);
70 ssize_t nbytes =
71 sendto(notify_fd_, info_str.c_str(), info_str.size(), 0,
72 (struct sockaddr*)&notify_addr_, sizeof(notify_addr_));
73 return nbytes > 0;
74}

◆ Shutdown()

void apollo::cyber::transport::MulticastNotifier::Shutdown ( )
overridevirtual

实现了 apollo::cyber::transport::NotifierBase.

在文件 multicast_notifier.cc45 行定义.

45 {
46 if (is_shutdown_.exchange(true)) {
47 return;
48 }
49
50 if (notify_fd_ != -1) {
51 close(notify_fd_);
52 notify_fd_ = -1;
53 }
54 memset(&notify_addr_, 0, sizeof(notify_addr_));
55
56 if (listen_fd_ != -1) {
57 close(listen_fd_);
58 listen_fd_ = -1;
59 }
60 memset(&listen_addr_, 0, sizeof(listen_addr_));
61}

◆ Type()

static const char * apollo::cyber::transport::MulticastNotifier::Type ( )
inlinestatic

在文件 multicast_notifier.h38 行定义.

38{ return "multicast"; }

该类的文档由以下文件生成: