Skip to content

Commit de7b0b6

Browse files
committed
more cleanups
1 parent 9024214 commit de7b0b6

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

cpp/src/plasma/io.cc

+15-14
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828

2929
using arrow::Status;
3030

31-
/* Number of times we try connecting to a socket. */
32-
#define NUM_CONNECT_ATTEMPTS 50
33-
#define CONNECT_TIMEOUT_MS 100
31+
/// Number of times we try connecting to a socket.
32+
constexpr int64_t kNumConnectAttempts = 50;
33+
/// Time to wait between connection attempts.
34+
constexpr int64_t kConnectTimeoutMs = 100;
3435

3536
namespace plasma {
3637

@@ -39,8 +40,8 @@ Status WriteBytes(int fd, uint8_t* cursor, size_t length) {
3940
size_t bytesleft = length;
4041
size_t offset = 0;
4142
while (bytesleft > 0) {
42-
/* While we haven't written the whole message, write to the file descriptor,
43-
* advance the cursor, and decrease the amount left to write. */
43+
// While we haven't written the whole message, write to the file descriptor,
44+
// advance the cursor, and decrease the amount left to write.
4445
nbytes = write(fd, cursor + offset, bytesleft);
4546
if (nbytes < 0) {
4647
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
@@ -68,7 +69,7 @@ Status WriteMessage(int fd, int64_t type, int64_t length, uint8_t* bytes) {
6869

6970
Status ReadBytes(int fd, uint8_t* cursor, size_t length) {
7071
ssize_t nbytes = 0;
71-
/* Termination condition: EOF or read 'length' bytes total. */
72+
// Termination condition: EOF or read 'length' bytes total.
7273
size_t bytesleft = length;
7374
size_t offset = 0;
7475
while (bytesleft > 0) {
@@ -117,7 +118,7 @@ int bind_ipc_sock(const std::string& pathname, bool shall_listen) {
117118
ARROW_LOG(ERROR) << "socket() failed for pathname " << pathname;
118119
return -1;
119120
}
120-
/* Tell the system to allow the port to be reused. */
121+
// Tell the system to allow the port to be reused.
121122
int on = 1;
122123
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&on),
123124
sizeof(on)) < 0) {
@@ -152,23 +153,23 @@ int bind_ipc_sock(const std::string& pathname, bool shall_listen) {
152153

153154
Status ConnectIpcSocketRetry(const std::string& pathname, int num_retries,
154155
int64_t timeout, int* fd) {
155-
/* Pick the default values if the user did not specify. */
156+
// Pick the default values if the user did not specify.
156157
if (num_retries < 0) {
157-
num_retries = NUM_CONNECT_ATTEMPTS;
158+
num_retries = kNumConnectAttempts;
158159
}
159160
if (timeout < 0) {
160-
timeout = CONNECT_TIMEOUT_MS;
161+
timeout = kConnectTimeoutMs;
161162
}
162163
*fd = connect_ipc_sock(pathname);
163164
while (*fd < 0 && num_retries > 0) {
164165
ARROW_LOG(ERROR) << "Connection to IPC socket failed for pathname " << pathname
165166
<< ", retrying " << num_retries << " more times";
166-
/* Sleep for timeout milliseconds. */
167+
// Sleep for timeout milliseconds.
167168
usleep(static_cast<int>(timeout * 1000));
168169
*fd = connect_ipc_sock(pathname);
169170
--num_retries;
170171
}
171-
/* If we could not connect to the socket, exit. */
172+
// If we could not connect to the socket, exit.
172173
if (*fd == -1) {
173174
std::stringstream ss;
174175
ss << "Could not connect to socket " << pathname;
@@ -217,15 +218,15 @@ std::unique_ptr<uint8_t[]> read_message_async(int sock) {
217218
int64_t size;
218219
Status s = ReadBytes(sock, reinterpret_cast<uint8_t*>(&size), sizeof(int64_t));
219220
if (!s.ok()) {
220-
/* The other side has closed the socket. */
221+
// The other side has closed the socket.
221222
ARROW_LOG(DEBUG) << "Socket has been closed, or some other error has occurred.";
222223
close(sock);
223224
return NULL;
224225
}
225226
auto message = std::unique_ptr<uint8_t[]>(new uint8_t[size]);
226227
s = ReadBytes(sock, message.get(), size);
227228
if (!s.ok()) {
228-
/* The other side has closed the socket. */
229+
// The other side has closed the socket.
229230
ARROW_LOG(DEBUG) << "Socket has been closed, or some other error has occurred.";
230231
close(sock);
231232
return NULL;

0 commit comments

Comments
 (0)