From 61755bc1680afaad45290e5ab6d3bff3dbd5b762 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Fri, 2 Dec 2016 18:51:50 -0800 Subject: [PATCH] Replace direct calls to recv with read_bytes. (#78) * Replace direct calls to recv with read_bytes. * Fixes. * Formatting. --- src/common/common.c | 4 +++- src/photon/photon_scheduler.c | 11 ++++++++++- src/plasma/plasma_manager.c | 9 +++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/common/common.c b/src/common/common.c index 8ab6e4fe5..07022e776 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -6,6 +6,8 @@ #include #include +#include "io.h" + /* This is used to define the array of object IDs. */ const UT_icd object_id_icd = {sizeof(object_id), NULL, NULL, NULL}; @@ -20,7 +22,7 @@ unique_id globally_unique_id(void) { LOG_ERROR("Could not generate random number"); } unique_id result; - read(fd, &result.id[0], UNIQUE_ID_SIZE); + CHECK(read_bytes(fd, &result.id[0], UNIQUE_ID_SIZE) >= 0); close(fd); return result; } diff --git a/src/photon/photon_scheduler.c b/src/photon/photon_scheduler.c index 3f02f9035..60726ee36 100644 --- a/src/photon/photon_scheduler.c +++ b/src/photon/photon_scheduler.c @@ -133,7 +133,16 @@ void process_plasma_notification(event_loop *loop, local_scheduler_state *s = context; /* Read the notification from Plasma. */ object_id obj_id; - recv(client_sock, (char *) &obj_id, sizeof(obj_id), 0); + int error = read_bytes(client_sock, (uint8_t *) &obj_id, sizeof(obj_id)); + if (error < 0) { + /* The store has closed the socket. */ + LOG_DEBUG( + "The plasma store has closed the object notification socket, or some " + "other error has occurred."); + event_loop_remove_file(loop, client_sock); + close(client_sock); + return; + } handle_object_available(s->scheduler_info, s->scheduler_state, obj_id); } diff --git a/src/plasma/plasma_manager.c b/src/plasma/plasma_manager.c index b388a0114..3d12e9e9c 100644 --- a/src/plasma/plasma_manager.c +++ b/src/plasma/plasma_manager.c @@ -1303,15 +1303,16 @@ void process_object_notification(event_loop *loop, plasma_manager_state *state = context; object_id obj_id; /* Read the notification from Plasma. */ - int n = recv(client_sock, (char *) &obj_id, sizeof(object_id), MSG_WAITALL); - if (n == 0) { + int error = read_bytes(client_sock, (uint8_t *) &obj_id, sizeof(obj_id)); + if (error < 0) { /* The store has closed the socket. */ - LOG_DEBUG("The plasma store has closed the object notification socket."); + LOG_DEBUG( + "The plasma store has closed the object notification socket, or some " + "other error has occurred."); event_loop_remove_file(loop, client_sock); close(client_sock); return; } - CHECK(n == sizeof(object_id)); /* Add object to locally available object. */ /* TODO(pcm): Where is this deallocated? */ available_object *entry =