Modernize plasma store (C to C++ changes). (#546)

This commit is contained in:
Philipp Moritz
2017-05-15 01:19:44 -07:00
committed by Robert Nishihara
parent e2e9e4ce6f
commit 08e988aee5
14 changed files with 794 additions and 738 deletions
-3
View File
@@ -14,7 +14,6 @@
#include <execinfo.h>
#endif
#include "utarray.h"
#ifdef __cplusplus
#include <functional>
extern "C" {
@@ -145,8 +144,6 @@ extern "C" {
typedef struct { unsigned char id[UNIQUE_ID_SIZE]; } UniqueID;
extern const UT_icd object_id_icd;
extern const UniqueID NIL_ID;
/* Generate a globally unique ID. */
+30
View File
@@ -384,6 +384,36 @@ disconnected:
return 0;
}
int64_t read_vector(int fd, int64_t *type, std::vector<uint8_t> &buffer) {
int64_t version;
int closed = read_bytes(fd, (uint8_t *) &version, sizeof(version));
if (closed) {
goto disconnected;
}
CHECK(version == RAY_PROTOCOL_VERSION);
int64_t length;
closed = read_bytes(fd, (uint8_t *) type, sizeof(*type));
if (closed) {
goto disconnected;
}
closed = read_bytes(fd, (uint8_t *) &length, sizeof(length));
if (closed) {
goto disconnected;
}
if (length > buffer.size()) {
buffer.resize(length);
}
closed = read_bytes(fd, buffer.data(), length);
if (closed) {
goto disconnected;
}
return length;
disconnected:
/* Handle the case in which the socket is closed. */
*type = DISCONNECT_CLIENT;
return 0;
}
void write_log_message(int fd, const char *message) {
/* Account for the \0 at the end of the string. */
write_message(fd, LOG_MESSAGE, strlen(message) + 1, (uint8_t *) message);
+18
View File
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <vector>
#include "utarray.h"
#define RAY_PROTOCOL_VERSION 0x0000000000000000
@@ -187,6 +188,23 @@ uint8_t *read_message_async(event_loop *loop, int sock);
*/
int64_t read_buffer(int fd, int64_t *type, UT_array *buffer);
/**
* Read a sequence of bytes written by write_message from a file descriptor.
* This does not allocate space for the message if the provided buffer is
* large enough and can therefore often avoid allocations.
*
* @param fd The file descriptor to read from. It can be non-blocking.
* @param type The type of the message that is read will be written at this
* address. If there was an error while reading, this will be
* DISCONNECT_CLIENT.
* @param buffer The array the message will be written to. If it is not
* large enough to hold the message, it will be enlarged by read_vector.
* @return Number of bytes of the message that were read. This size does not
* include the bytes used to encode the type and length. If there was
* an error while reading, this will be 0.
*/
int64_t read_vector(int fd, int64_t *type, std::vector<uint8_t> &buffer);
/**
* Write a null-terminated string to a file descriptor.
*/