Skip to content

Commit 26004ab

Browse files
committed
Renamed nrequests -> total_requests, same with nclients and nconnections
1 parent adf4b2f commit 26004ab

File tree

3 files changed

+93
-21
lines changed

3 files changed

+93
-21
lines changed

src/mqtt.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ enum packet_type {
8181

8282
enum qos_level { AT_MOST_ONCE, AT_LEAST_ONCE, EXACTLY_ONCE };
8383

84+
/*
85+
* MQTT Fixed header, according to official docs it's comprised of a single
86+
* byte carrying:
87+
* - opcode (packet type)
88+
* - dup flag
89+
* - QoS
90+
* - retain flag
91+
* It's followed by the remaining_len of the packet, encoded onto 1 to 4
92+
* bytes starting at bytes 2.
93+
*
94+
* | Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
95+
* |------------|-----------------------|--------------------------|
96+
* | Byte 1 | MQTT type 3 | dup | QoS | retain |
97+
* |------------|--------------------------------------------------|
98+
* | Byte 2 | |
99+
* | . | Remaining Length |
100+
* | . | |
101+
* | Byte 5 | |
102+
* |------------|--------------------------------------------------|
103+
*/
84104
union mqtt_header {
85105
u8 byte;
86106
struct {
@@ -91,6 +111,58 @@ union mqtt_header {
91111
} bits;
92112
};
93113

114+
/*
115+
* MQTT Connect packet, contains a variable header with some connect related
116+
* flags:
117+
* - clean session flag
118+
* - will flag
119+
* - will QoS (if will flag set to true)
120+
* - will topic (if will flag set to true)
121+
* - will retain flag (if will flag set to true)
122+
* - password flag
123+
* - username flag
124+
*
125+
* It's followed by all required fields according the flags set to true.
126+
*
127+
* |------------|--------------------------------------------------|
128+
* | Byte 6 | Protocol name len MSB |
129+
* | Byte 7 | Protocol name len LSB | [UINT16]
130+
* |------------|--------------------------------------------------|
131+
* | Byte 8 | |
132+
* | . | 'M' 'Q' 'T' 'T' |
133+
* | Byte 12 | |
134+
* |------------|--------------------------------------------------|
135+
* | Byte 13 | Protocol level |
136+
* |------------|--------------------------------------------------|
137+
* | | Connect flags |
138+
* | Byte 14 |--------------------------------------------------|
139+
* | | U | P | WR | WQ | WF | CS | R |
140+
* |------------|--------------------------------------------------|
141+
* | Byte 15 | Keepalive MSB | [UINT16]
142+
* | Byte 17 | Keepalive LSB |
143+
* |------------|--------------------------------------------------|<-- Payload
144+
* | Byte 18 | Client ID length MSB | [UINT16]
145+
* | Byte 19 | Client ID length LSB |
146+
* |------------|--------------------------------------------------|
147+
* | Byte 20 | |
148+
* | . | Client ID |
149+
* | Byte N | |
150+
* |------------|--------------------------------------------------|
151+
* | Byte N+1 | Username length MSB |
152+
* | Byte N+2 | Username length LSB |
153+
* |------------|--------------------------------------------------|
154+
* | Byte N+3 | |
155+
* | . | Username |
156+
* | Byte N+M | |
157+
* |------------|--------------------------------------------------|
158+
* | Byte N+M+1 | Password length MSB |
159+
* | Byte N+M+2 | Password length LSB |
160+
* |------------|--------------------------------------------------|
161+
* | Byte N+M+3 | |
162+
* | . | Password |
163+
* | Byte N+M+K | |
164+
* |------------|--------------------------------------------------|
165+
*/
94166
struct mqtt_connect {
95167
union {
96168
u8 byte;

src/server.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void publish_stats(struct ev_ctx *ctx, void *data) {
213213
(void)data;
214214

215215
char cclients[21];
216-
snprintf(cclients, 21, "%lu", info.nclients);
216+
snprintf(cclients, 21, "%lu", info.active_connections);
217217

218218
char bsent[21];
219219
snprintf(bsent, 21, "%lu", info.bytes_sent);
@@ -698,8 +698,8 @@ static void write_callback(struct ev_ctx *ctx, void *arg) {
698698
ev_del_fd(ctx, client->conn.fd);
699699
client_deactivate(client);
700700
// Update stats
701-
info.nclients--;
702-
info.nconnections--;
701+
info.active_connections--;
702+
info.total_connections--;
703703
break;
704704
}
705705
}
@@ -747,8 +747,8 @@ static void accept_callback(struct ev_ctx *ctx, void *data) {
747747
ev_register_event(ctx, fd, EV_READ, read_callback, c);
748748

749749
/* Record the new client connected */
750-
info.nclients++;
751-
info.nconnections++;
750+
info.active_connections++;
751+
info.total_connections++;
752752

753753
log_info("[%p] Connection from %s", (void *) pthread_self(), conn.ip);
754754
}
@@ -818,8 +818,8 @@ static void read_callback(struct ev_ctx *ctx, void *data) {
818818
pthread_mutex_unlock(&mutex);
819819
#endif
820820
client_deactivate(c);
821-
info.nclients--;
822-
info.nconnections--;
821+
info.active_connections--;
822+
info.total_connections--;
823823
break;
824824
case -ERREAGAIN:
825825
/*
@@ -869,8 +869,8 @@ static void process_message(struct ev_ctx *ctx, struct client *c) {
869869
ev_del_fd(ctx, c->conn.fd);
870870
client_deactivate(io.client);
871871
// Update stats
872-
info.nclients--;
873-
info.nconnections--;
872+
info.active_connections--;
873+
info.total_connections--;
874874
break;
875875
case -ERRNOMEM:
876876
log_error(solerr(c->rc));

src/server.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ struct io_event {
6767
/* Global informations statistics structure */
6868
struct sol_info {
6969
/* Number of clients currently connected */
70-
atomic_size_t nclients;
70+
atomic_size_t active_connections;
7171
/* Total number of clients connected since the start */
72-
atomic_size_t nconnections;
72+
atomic_size_t total_connections;
7373
/* Total number of sent messages */
7474
atomic_size_t messages_sent;
7575
/* Total number of received messages */
@@ -79,23 +79,23 @@ struct sol_info {
7979
/* Seconds passed since the start */
8080
atomic_size_t uptime;
8181
/* Total number of requests served */
82-
atomic_size_t nrequests;
82+
atomic_size_t total_requests;
8383
/* Total number of bytes received */
8484
atomic_size_t bytes_sent;
8585
/* Total number of bytes sent out */
8686
atomic_size_t bytes_recv;
8787
};
8888

8989
#define INIT_INFO do { \
90-
info.nclients = ATOMIC_VAR_INIT(0); \
91-
info.nconnections = ATOMIC_VAR_INIT(0); \
92-
info.messages_sent = ATOMIC_VAR_INIT(0); \
93-
info.messages_recv = ATOMIC_VAR_INIT(0); \
94-
info.start_time = ATOMIC_VAR_INIT(0); \
95-
info.uptime = ATOMIC_VAR_INIT(0); \
96-
info.nrequests = ATOMIC_VAR_INIT(0); \
97-
info.bytes_sent = ATOMIC_VAR_INIT(0); \
98-
info.bytes_recv = ATOMIC_VAR_INIT(0); \
90+
info.active_connections = ATOMIC_VAR_INIT(0); \
91+
info.total_connections = ATOMIC_VAR_INIT(0); \
92+
info.messages_sent = ATOMIC_VAR_INIT(0); \
93+
info.messages_recv = ATOMIC_VAR_INIT(0); \
94+
info.start_time = ATOMIC_VAR_INIT(0); \
95+
info.uptime = ATOMIC_VAR_INIT(0); \
96+
info.total_requests = ATOMIC_VAR_INIT(0); \
97+
info.bytes_sent = ATOMIC_VAR_INIT(0); \
98+
info.bytes_recv = ATOMIC_VAR_INIT(0); \
9999
} while (0)
100100

101101
/*

0 commit comments

Comments
 (0)