MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / read_request

Method read_request

rpc/rpc.cpp:249–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247 }
248
249 int read_request()
250 {
251 ssize_t ret = stream->read(&header, sizeof(header));
252 ERRNO err;
253 if (ret == 0) {
254 // means socket already shutted or disconnected
255 // do not needs more logs
256 return -1;
257 }
258 if (ret != sizeof(header)) {
259 stream->shutdown(ShutdownHow::ReadWrite);
260 LOG_ERROR_RETURN(err.no, -1, "Failed to read rpc header ", stream, VALUE(ret), err);
261 return -1;
262 }
263
264 if (header.magic != Header::MAGIC)
265 LOG_ERROR_RETURN(err.no, -1, "header magic doesn't match ", stream);
266
267 if (header.version != Header::VERSION)
268 LOG_ERROR_RETURN(err.no, -1, "protocol version doesn't match ", stream);
269
270 auto it = sk->m_map.find(header.function);
271 if (it == sk->m_map.end())
272 LOG_ERROR_RETURN(ENOSYS, -1, "unable to find function service for ID ", header.function.function);
273
274 func = it->second;
275 ret = request.push_back(header.size);
276 if (ret != header.size) {
277 LOG_ERRNO_RETURN(ENOMEM, -1, "Failed to allocate iov");
278 }
279 ret = stream->readv(request.iovec(), request.iovcnt());
280 ERRNO errbody;
281 if (ret != header.size) {
282 stream->shutdown(ShutdownHow::ReadWrite);
283 LOG_ERROR_RETURN(errbody.no, -1, "failed to read rpc request body from stream ", stream, VALUE(ret), errbody);
284 }
285 return 0;
286 }
287 int serve_request()
288 {
289 sk->m_serving_count++;

Callers 1

serveMethod · 0.80

Calls 8

readMethod · 0.45
shutdownMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
readvMethod · 0.45
iovecMethod · 0.45
iovcntMethod · 0.45

Tested by

no test coverage detected