-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
64 lines (48 loc) · 1.34 KB
/
Copy pathutils.h
File metadata and controls
64 lines (48 loc) · 1.34 KB
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
54
55
56
57
58
59
60
61
62
63
64
#ifndef UTILS_H
#define UTILS_H
#define MAX_CONNECTIONS 32
#define MAX_PAYLOAD_SIZE 1500
#define MAX_TOPIC_SIZE 50
#define MAX_ID_SIZE 10
#define CLIENT_POLLFDS 2
#define MAX_CLIENT_COMMAND_SIZE 100
#define MAX_SERVER_COMMAND_SIZE 10
#define TRASH_SIZE 15
#define INCREMENTAL_POLL_SIZE 10
#define INT_SIZE 5
#define SHORT_REAL_SIZE 2
#define FLOAT_SIZE 6
#define SUB_SUCCESS 0xBBBB
#define SUB_FAIL 0xAAAA
#define UNSUB_SUCCESS 0xBBBB
#define UNSUB_FAIL 0xAAAA
#define ASSERT(a, b) if((a)) { perror((b)); exit(EXIT_FAILURE); }
int send_all(int sockfd, void *buff, size_t no_bytes, int flags) {
int rc = 0;
size_t bytes_remaining = no_bytes;
size_t bytes_sent = 0;
while(bytes_remaining > 0) {
rc = send(sockfd, (char *) buff + bytes_sent, bytes_remaining, flags);
if (rc < 0)
return -1;
bytes_sent += rc;
bytes_remaining -= rc;
}
return bytes_sent;
}
int recv_all(int sockfd, void *buff, size_t no_bytes, int flags) {
int rc = 0;
size_t bytes_remaining = no_bytes;
size_t bytes_sent = 0;
while(bytes_remaining > 0) {
rc = recv(sockfd, (char *) buff + bytes_sent, bytes_remaining, flags);
if (rc < 0)
return -1;
if (rc == 0)
return 0;
bytes_sent += rc;
bytes_remaining -= rc;
}
return bytes_sent;
}
#endif