-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
53 lines (45 loc) · 948 Bytes
/
Copy pathutils.cpp
File metadata and controls
53 lines (45 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "utils.h"
int recv_all(int sockfd, void *buffer, size_t len)
{
size_t bytes_received = 0;
size_t bytes_remaining = len;
char *buff = (char *)buffer;
while (bytes_remaining > 0)
{
int rc = recv(sockfd, buff + bytes_received, bytes_remaining, 0);
DIE(rc < 0, "recv");
if (rc == 0)
break;
bytes_received += rc;
bytes_remaining -= rc;
}
return bytes_received;
}
int send_all(int sockfd, void *buffer, size_t len)
{
size_t bytes_sent = 0;
size_t bytes_remaining = len;
char *buff = (char *)buffer;
while (bytes_remaining > 0) {
int rc = send(sockfd, buff + bytes_sent, bytes_remaining, 0);
DIE(rc < 0, "send");
bytes_sent += rc;
bytes_remaining -= rc;
}
return bytes_sent;
}
const char *data_type_to_string(DATA_TYPE type)
{
switch (type) {
case INT:
return "INT";
case SHORT_REAL:
return "SHORT_REAL";
case FLOAT:
return "FLOAT";
case STRING:
return "STRING";
default:
return "";
}
}