Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit932f4fe

Browse files
committed
Fix warnings.
1 parent4f69a62 commit932f4fe

File tree

5 files changed

+84
-50
lines changed

5 files changed

+84
-50
lines changed

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#override CC := clang
2-
overrideCFLAGS += -Wfatal-errors -O0 -g
2+
overrideCFLAGS += -fpic -Wall -Wfatal-errors -O0 -g -pedantic -std=c99
33
overrideCPPFLAGS += -I. -Iinclude -DDEBUG
44
overrideHEART_LDFLAGS += -Llib -lraft -ljansson
55

@@ -8,12 +8,12 @@ ARFLAGS = -cru
88

99
.PHONY: all clean bindir objdir libdir
1010

11-
all: lib/libraft.a bin/heart
12-
@echo Done.
13-
1411
lib/libraft.a: obj/raft.o obj/util.o | libdir objdir
1512
$(AR)$(ARFLAGS) lib/libraft.a obj/raft.o obj/util.o
1613

14+
all: lib/libraft.a bin/heart
15+
@echo Done.
16+
1717
bin/heart: obj/heart.o lib/libraft.a | bindir objdir
1818
$(CC) -o bin/heart$(CFLAGS)$(CPPFLAGS)\
1919
obj/heart.o$(HEART_LDFLAGS)

‎example/heart.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define_POSIX_C_SOURCE 2
2+
#define_BSD_SOURCE
13
#include<stdio.h>
24
#include<stdlib.h>
35
#include<string.h>
@@ -54,8 +56,6 @@ static void applier(void *state, raft_update_t update, raft_bool_t snapshot) {
5456
}
5557

5658
staticraft_update_tsnapshooter(void*state) {
57-
json_error_terror;
58-
5959
raft_update_tshot;
6060
shot.data=json_dumps(state,JSON_SORT_KEYS);
6161
shot.len=strlen(shot.data);
@@ -98,7 +98,6 @@ static void main_loop(char *host, int port) {
9898
while (true) {
9999
intms;
100100
raft_msg_tm;
101-
intapplied;
102101

103102
ms=mstimer_reset(&t);
104103

‎include/raft.h‎

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@ typedef int raft_bool_t;
1111
typedefstructraft_update_t {
1212
intlen;
1313
char*data;
14-
void*userdata;// use this to track which query caused this update
14+
void*userdata;/* use this to track which query caused this update */
1515
}raft_update_t;
1616

17-
// --- Callbacks ---
17+
/* --- Callbacks --- */
1818

19-
// This should be a function that applies an 'update' to the state machine.
20-
// 'snapshot' is true if 'update' contains a snapshot. 'userdata' is the
21-
// userdata that raft was configured with.
19+
/*
20+
* This should be a function that applies an 'update' to the state machine.
21+
* 'snapshot' is true if 'update' contains a snapshot. 'userdata' is the
22+
* userdata that raft was configured with.
23+
*/
2224
typedefvoid (*raft_applier_t)(void*userdata,raft_update_tupdate,raft_bool_tsnapshot);
2325

24-
// This should be a function that makes a snapshot of the state machine. Used
25-
// for raft log compaction. 'userdata' is the userdata that raft was configured
26-
// with.
26+
/*
27+
* This should be a function that makes a snapshot of the state machine. Used
28+
* for raft log compaction. 'userdata' is the userdata that raft was configured
29+
* with.
30+
*/
2731
typedefraft_update_t (*raft_snapshooter_t)(void*userdata);
2832

29-
// --- Configuration ---
33+
/* --- Configuration --- */
3034

3135
typedefstructraft_config_t {
3236
intpeernum_max;
@@ -40,56 +44,80 @@ typedef struct raft_config_t {
4044
intchunk_len;
4145
intmsg_len_max;
4246

43-
void*userdata;// this will get passed to applier() and snapshooter()
47+
void*userdata;/* this will get passed to applier() and snapshooter() */
4448
raft_applier_tapplier;
4549
raft_snapshooter_tsnapshooter;
4650
}raft_config_t;
4751

48-
// Initialize a raft instance. Returns NULL on failure.
52+
/*
53+
* Initialize a raft instance. Returns NULL on failure.
54+
*/
4955
raft_traft_init(raft_config_t*config);
5056

51-
// Add a peer named 'id'. 'self' should be true, if that peer is this instance.
52-
// Only one peer should have 'self' == true.
57+
/*
58+
* Add a peer named 'id'. 'self' should be true, if that peer is this instance.
59+
* Only one peer should have 'self' == true.
60+
*/
5361
raft_bool_traft_peer_up(raft_tr,intid,char*host,intport,raft_bool_tself);
5462

55-
// Remove a previously added peer named 'id'.
63+
/*
64+
* Remove a previously added peer named 'id'.
65+
*/
5666
raft_bool_traft_peer_down(raft_tr,intid);
5767

58-
// --- Log Actions ---
68+
/* --- Log Actions --- */
5969

60-
// Emit an 'update'. Returns the log index if emitted successfully, or -1
61-
// otherwise.
70+
/*
71+
* Emit an 'update'. Returns the log index if emitted successfully, or -1
72+
* otherwise.
73+
*/
6274
intraft_emit(raft_tr,raft_update_tupdate);
6375

64-
// Checks whether an entry at 'index' has been applied by the peer named 'id'.
76+
/*
77+
* Checks whether an entry at 'index' has been applied by the peer named 'id'.
78+
*/
6579
raft_bool_traft_applied(raft_tt,intid,intindex);
6680

67-
// --- Control ---
68-
69-
// Note, that UDP socket and raft messages are exposed to the user. This gives
70-
// the user the opportunity to incorporate the socket with other sockets in
71-
// select() or poll(). Thus, the messages will be processed as soon as they
72-
// come, not as soon as we call raft_tick().
73-
74-
// Perform various raft logic tied to time. Call this function once in a while
75-
// and pass the elapsed 'msec' from the previous call. This function will only
76-
// trigger time-related events, and will not receive and process messages (see
77-
// the note above).
81+
/* --- Control --- */
82+
83+
/*
84+
* Note, that UDP socket and raft messages are exposed to the user. This gives
85+
* the user the opportunity to incorporate the socket with other sockets in
86+
* select() or poll(). Thus, the messages will be processed as soon as they
87+
* come, not as soon as we call raft_tick().
88+
*/
89+
90+
/*
91+
* Perform various raft logic tied to time. Call this function once in a while
92+
* and pass the elapsed 'msec' from the previous call. This function will only
93+
* trigger time-related events, and will not receive and process messages (see
94+
* the note above).
95+
*/
7896
voidraft_tick(raft_tr,intmsec);
7997

80-
// Receive a raft message. Returns NULL if no message available.
98+
/*
99+
* Receive a raft message. Returns NULL if no message available.
100+
*/
81101
raft_msg_traft_recv_message(raft_tr);
82102

83-
// Process the message.
103+
/*
104+
* Process the message.
105+
*/
84106
voidraft_handle_message(raft_tr,raft_msg_tm);
85107

86-
// Create the raft socket.
108+
/*
109+
* Create the raft socket.
110+
*/
87111
intraft_create_udp_socket(raft_tr);
88112

89-
// Returns true if this peer thinks it is the leader.
113+
/*
114+
* Returns true if this peer thinks it is the leader.
115+
*/
90116
raft_bool_traft_is_leader(raft_tr);
91117

92-
// Returns the id of the current leader, or NOBODY if no leader.
118+
/*
119+
* Returns the id of the current leader, or NOBODY if no leader.
120+
*/
93121
intraft_get_leader(raft_tr);
94122

95123
#endif

‎include/util.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ struct timeval ms2tv(int ms);
3232

3333
// ------ logging ------
3434

35-
#ifndefDEBUG
36-
#definedebug(...)
35+
#ifdefDEBUG
36+
#defineDEBUG_ENABLED 1
3737
#else
38+
#defineDEBUG_ENABLED 0
39+
#endif
40+
3841
#definedebug(...) \
3942
do { \
40-
fprintf(stderr, __VA_ARGS__); \
41-
fflush(stderr); \
43+
if (DEBUG_ENABLED) {\
44+
fprintf(stderr, __VA_ARGS__); \
45+
fflush(stderr); \
46+
}\
4247
} while (0)
43-
#endif
4448

4549
#defineshout(...) \
4650
do { \

‎src/raft.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#define_BSD_SOURCE
2+
#include<sys/socket.h>
3+
#include<netinet/in.h>
14
#include<arpa/inet.h>
5+
26
#include<assert.h>
37
#include<errno.h>
48
#include<limits.h>
@@ -448,7 +452,6 @@ static void raft_beat(raft_t r, int dst) {
448452

449453
if (p->acked.entries <=RAFT_LOG_LAST_INDEX(r)) {
450454
intsendindex;
451-
intsendbyte;
452455

453456
if (p->acked.entries<RAFT_LOG_FIRST_INDEX(r)) {
454457
// The peer has woken up from anabiosis. Send the first
@@ -721,8 +724,6 @@ static bool raft_restore(raft_t r, int previndex, raft_entry_t *e) {
721724
staticboolraft_appendable(raft_tr,intprevindex,intprevterm) {
722725
intlow,high;
723726

724-
raft_log_t*l=&r->log;
725-
726727
low=RAFT_LOG_FIRST_INDEX(r);
727728
if (low==0)low=-1;// allow appending at the start
728729
high=RAFT_LOG_LAST_INDEX(r);
@@ -743,6 +744,8 @@ static bool raft_appendable(raft_t r, int previndex, int prevterm) {
743744
return false;
744745
}
745746
}
747+
748+
return true;
746749
}
747750

748751
staticboolraft_append(raft_tr,intprevindex,intprevterm,raft_entry_t*e) {
@@ -754,7 +757,7 @@ static bool raft_append(raft_t r, int previndex, int prevterm, raft_entry_t *e)
754757
debug(
755758
"log_append(%p, previndex=%d, prevterm=%d,"
756759
" term=%d)\n",
757-
l,previndex,prevterm,
760+
(void*)l,previndex,prevterm,
758761
e->term
759762
);
760763

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp