113 {
114 struct sockaddr_in client_addr;
115 socklen_t sock_len = static_cast<socklen_t>(sizeof(client_addr));
118 int bytes =
119 static_cast<int>(recvfrom(fd, total_buf, total_recv, 0,
120 (struct sockaddr *)&client_addr, &sock_len));
121 if (bytes <= 0 || bytes > total_recv) {
122 return false;
123 }
124
126 AERROR <<
"Header flag didn't match!";
127 return false;
128 }
130
131 const char *cursor = total_buf + offset;
132 hsize header_size = *(
reinterpret_cast<const hsize *
>(cursor));
133 offset +=
sizeof(
hsize) + 1;
134
135 if (header_size < offset || header_size >
FRAME_SIZE) {
136 AERROR <<
"header size is more than FRAME_SIZE!";
137 return false;
138 }
139
140 cursor = total_buf + offset;
141 size_t buf_size = header_size - offset;
142 BridgeHeader header;
143 if (!header.Diserialize(cursor, buf_size)) {
144 AERROR <<
"header diserialize failed!";
145 return false;
146 }
147
148 ADEBUG <<
"proto name : " << header.GetMsgName().c_str();
149 ADEBUG <<
"proto sequence num: " << header.GetMsgID();
150 ADEBUG <<
"proto total frames: " << header.GetTotalFrames();
151 ADEBUG <<
"proto frame index: " << header.GetIndex();
152
153 std::lock_guard<std::mutex> lock(mutex_);
154 std::shared_ptr<ProtoDiserializedBufBase> proto_buf =
156 if (!proto_buf) {
157 return false;
158 }
159
160 cursor = total_buf + header_size;
161 if (header.GetFramePos() > header.GetMsgSize()) {
162 return false;
163 }
164 char *buf = proto_buf->GetBuf(header.GetFramePos());
165
166 if (header.GetFrameSize() < 0 ||
167 header.GetFrameSize() > (total_recv - header_size)) {
168 return false;
169 }
170
171 if (header.GetFrameSize() > (header.GetMsgSize() - header.GetFramePos())) {
172 return false;
173 }
174 memcpy(buf, cursor, header.GetFrameSize());
175 proto_buf->UpdateStatus(header.GetIndex());
176 if (proto_buf->IsReadyDiserialize()) {
177 proto_buf->DiserializedAndPub();
178 RemoveInvalidBuf(proto_buf->GetMsgID(), proto_buf->GetMsgName());
180 }
181 return true;
182}
std::shared_ptr< ProtoDiserializedBufBase > CreateBridgeProtoBuf(const BridgeHeader &header)
constexpr uint32_t FRAME_SIZE
constexpr char BRIDGE_HEADER_FLAG[]
constexpr size_t HEADER_FLAG_SIZE
bool RemoveItem(std::vector< T * > *list, const T *t)