Skip to content

Commit 3dd0391

Browse files
committed
Back to basic - renamed client status -> state
1 parent 0ac92b9 commit 3dd0391

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/server.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static void client_init(struct client *client)
370370
client->connected = false;
371371
client->clean_session = true;
372372
client->client_id[0] = '\0';
373-
client->status = WAITING_HEADER;
373+
client->state = WAITING_HEADER;
374374
client->rc = 0;
375375
client->rpos = 0;
376376
client->read = 0;
@@ -446,8 +446,8 @@ static ssize_t recv_packet(struct client *c)
446446
unsigned opcode = 0, pos = 0;
447447
unsigned int pktlen = 0LL;
448448

449-
// Base status, we have read 0 to 2 bytes
450-
if (c->status == WAITING_HEADER) {
449+
// Base state, we have read 0 to 2 bytes
450+
if (c->state == WAITING_HEADER) {
451451

452452
/*
453453
* Read the first two bytes, the first should contain the message
@@ -463,7 +463,7 @@ static ssize_t recv_packet(struct client *c)
463463
if (errno == EAGAIN && c->read < 2)
464464
return -ERREAGAIN;
465465

466-
c->status = WAITING_LENGTH;
466+
c->state = WAITING_LENGTH;
467467
}
468468

469469
/*
@@ -473,7 +473,7 @@ static ssize_t recv_packet(struct client *c)
473473
* case of ACK type packet or PINGREQ/PINGRESP and DISCONNECT, the
474474
* entire packet
475475
*/
476-
if (c->status == WAITING_LENGTH) {
476+
if (c->state == WAITING_LENGTH) {
477477

478478
if (c->read == 2) {
479479
opcode = *c->rbuf >> 4;
@@ -538,11 +538,11 @@ static ssize_t recv_packet(struct client *c)
538538
if (pktlen <= 4)
539539
goto exit;
540540

541-
c->status = WAITING_DATA;
541+
c->state = WAITING_DATA;
542542
}
543543

544544
/*
545-
* Last status, we have access to the length of the packet and we know
545+
* Last state, we have access to the length of the packet and we know
546546
* for sure that it's not a PINGREQ/PINGRESP/DISCONNECT packet.
547547
*/
548548
nread = recv_data(&c->conn, c->rbuf + c->read, c->toread - c->read);
@@ -649,9 +649,9 @@ static void write_callback(struct ev_ctx *ctx, void *arg)
649649
/*
650650
* Rearm descriptor making it ready to receive input,
651651
* read_callback will be the callback to be used; also reset the
652-
* read buffer status for the client.
652+
* read buffer state for the client.
653653
*/
654-
client->status = WAITING_HEADER;
654+
client->state = WAITING_HEADER;
655655
ev_fire_event(ctx, client->conn.fd, EV_READ, read_callback, client);
656656
break;
657657
case -ERREAGAIN:
@@ -728,7 +728,7 @@ static void accept_callback(struct ev_ctx *ctx, void *data)
728728
static void read_callback(struct ev_ctx *ctx, void *data)
729729
{
730730
struct client *c = data;
731-
if (c->status == SENDING_DATA)
731+
if (c->state == SENDING_DATA)
732732
return;
733733
/*
734734
* Received a bunch of data from a client, after the creation
@@ -745,7 +745,7 @@ static void read_callback(struct ev_ctx *ctx, void *data)
745745
*/
746746
/* Record last action as of now */
747747
c->last_seen = time(NULL);
748-
c->status = SENDING_DATA;
748+
c->state = SENDING_DATA;
749749
process_message(ctx, c);
750750
break;
751751
case -ERRCLIENTDC:
@@ -839,7 +839,7 @@ static void process_message(struct ev_ctx *ctx, struct client *c)
839839
log_error(solerr(c->rc));
840840
break;
841841
default:
842-
c->status = WAITING_HEADER;
842+
c->state = WAITING_HEADER;
843843
if (io.data.header.bits.type != PUBLISH)
844844
mqtt_packet_destroy(&io.data);
845845
break;

src/sol_internal.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ struct inflight_msg {
148148
* - WAITING_DATA it's the step required to receive the full byte stream as
149149
* the encoded length describe. We wait for the effective
150150
* payload in this state.
151-
* - SENDING_DATA the last status, a complete packet has been received and
151+
* - SENDING_DATA the last state, a complete packet has been received and
152152
* has to be processed and reply back if needed.
153153
*/
154-
enum client_status {
154+
enum client_state {
155155
WAITING_HEADER,
156156
WAITING_LENGTH,
157157
WAITING_DATA,
@@ -170,18 +170,18 @@ enum client_status {
170170
*/
171171
struct client {
172172
struct ev_ctx
173-
*ctx; /* An event context refrence mostly used to fire write events */
174-
int rc; /* Return code of the message just handled */
175-
int status; /* Current status of the client (state machine) */
176-
int rpos; /* The nr of bytes to skip after a complete
177-
* packet has * been read. This because for
178-
* MQTT, length is encoded on multiple bytes
179-
* according to it's size, using a continuation bit
180-
* as a technique to encode it. We don't want to
181-
* decode the length two times when we already
182-
* know it, so we need an offset to know where
183-
* the actual packet will start
184-
*/
173+
*ctx; /* An event context refrence mostly used to fire write events */
174+
int rc; /* Return code of the message just handled */
175+
int state; /* Current state of the client (state machine) */
176+
int rpos; /* The nr of bytes to skip after a complete
177+
* packet has * been read. This because for
178+
* MQTT, length is encoded on multiple bytes
179+
* according to it's size, using a continuation bit
180+
* as a technique to encode it. We don't want to
181+
* decode the length two times when we already
182+
* know it, so we need an offset to know where
183+
* the actual packet will start
184+
*/
185185
size_t read; /* The number of bytes already read */
186186
size_t toread; /* The number of bytes that have to be read */
187187
unsigned char *rbuf; /* The reading buffer */

0 commit comments

Comments
 (0)