Browse code

core/tcp: Convert RD_CONN_ flags to enum

Easier to recognize the correct flags in the forest of flags.

Alex Hermann authored on 09/06/2020 07:01:53
Showing 5 changed files
... ...
@@ -218,7 +218,7 @@ static int tcp_emit_closed_event(struct tcp_connection *con, enum tcp_closed_rea
218 218
  * EOF checking should be done by checking the RD_CONN_EOF flag.
219 219
  */
220 220
 int tcp_read_data(int fd, struct tcp_connection *c,
221
-					char* buf, int b_size, int* flags)
221
+					char* buf, int b_size, rd_conn_flags_t* flags)
222 222
 {
223 223
 	int bytes_read;
224 224
 
... ...
@@ -329,7 +329,7 @@ again:
329 329
  * (to distinguish from reads that would block which could return 0)
330 330
  * RD_CONN_SHORT_READ is also set in *flags for short reads.
331 331
  * sets also r->error */
332
-int tcp_read(struct tcp_connection *c, int* flags)
332
+int tcp_read(struct tcp_connection *c, rd_conn_flags_t* flags)
333 333
 {
334 334
 	int bytes_free, bytes_read;
335 335
 	struct tcp_req *r;
... ...
@@ -369,7 +369,7 @@ int tcp_read(struct tcp_connection *c, int* flags)
369 369
  * when either r->body!=0 or r->state==H_BODY =>
370 370
  * all headers have been read. It should be called in a while loop.
371 371
  * returns < 0 if error or 0 if EOF */
372
-int tcp_read_headers(struct tcp_connection *c, int* read_flags)
372
+int tcp_read_headers(struct tcp_connection *c, rd_conn_flags_t* read_flags)
373 373
 {
374 374
 	int bytes, remaining;
375 375
 	char *p;
... ...
@@ -1082,7 +1082,7 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
1082 1082
 #endif
1083 1083
 
1084 1084
 #ifdef READ_WS
1085
-static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1085
+static int tcp_read_ws(struct tcp_connection *c, rd_conn_flags_t* read_flags)
1086 1086
 {
1087 1087
 	int bytes;
1088 1088
 	uint32_t size, pos, mask_present, len;
... ...
@@ -1237,7 +1237,7 @@ static int ws_process_msg(char* tcpbuf, unsigned int len,
1237 1237
 }
1238 1238
 #endif
1239 1239
 
1240
-static int tcp_read_hep3(struct tcp_connection *c, int* read_flags)
1240
+static int tcp_read_hep3(struct tcp_connection *c, rd_conn_flags_t* read_flags)
1241 1241
 {
1242 1242
 	int bytes;
1243 1243
 	uint32_t size, len;
... ...
@@ -1429,7 +1429,7 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len,
1429 1429
 #endif /* TCP_CLONE_RCVBUF */
1430 1430
 }
1431 1431
 
1432
-int tcp_read_req(struct tcp_connection* con, int* bytes_read, int* read_flags)
1432
+int tcp_read_req(struct tcp_connection* con, int* bytes_read, rd_conn_flags_t* read_flags)
1433 1433
 {
1434 1434
 	int bytes;
1435 1435
 	int total_bytes;
... ...
@@ -1712,7 +1712,7 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
1712 1712
 {
1713 1713
 	int ret;
1714 1714
 	int n;
1715
-	int read_flags;
1715
+	rd_conn_flags_t read_flags;
1716 1716
 	struct tcp_connection* con;
1717 1717
 	int s;
1718 1718
 	long resp;
... ...
@@ -25,14 +25,16 @@
25 25
 
26 26
 #include  "tcp_conn.h"
27 27
 
28
-#define RD_CONN_SHORT_READ		1
29
-#define RD_CONN_EOF				2
30
-#define RD_CONN_REPEAT_READ		4 /* read should be repeated (more data)
31
-								   (used so far only by tls) */
32
-#define RD_CONN_FORCE_EOF		65536
28
+typedef enum rd_conn_flags {
29
+	RD_CONN_SHORT_READ  = (1<<0),
30
+	RD_CONN_EOF         = (1<<1),
31
+	RD_CONN_REPEAT_READ = (1<<2), /* read should be repeated (more data)
32
+	                                 (used so far only by tls) */
33
+	RD_CONN_FORCE_EOF   = (1<<16),
34
+} rd_conn_flags_t;
33 35
 
34 36
 int tcp_read_data(int fd, struct tcp_connection *c,
35
-					char* buf, int b_size, int* flags);
37
+					char* buf, int b_size, rd_conn_flags_t* flags);
36 38
 
37 39
 
38 40
 #endif /*__tcp_read_h*/
... ...
@@ -37,13 +37,14 @@
37 37
 #endif
38 38
 
39 39
 #include "tcp_conn.h"
40
+#include "tcp_read.h"
40 41
 
41 42
 
42 43
 
43 44
 struct tls_hooks{
44 45
 	/* read using tls (should use tcp internal read functions to
45 46
 	   get the data from the connection) */
46
-	int  (*read)(struct tcp_connection* c, int* flags);
47
+	int  (*read)(struct tcp_connection* c, rd_conn_flags_t* flags);
47 48
 	/* process data for sending. Should replace pbuf & plen with
48 49
 	   an internal buffer containing the tls records. If it was not able
49 50
 	   to process the whole pbuf, it should set (rest_buf, rest_len) to
... ...
@@ -991,7 +991,7 @@ ssl_eof:
991 991
  *         tcp connection flags and might set c->state and r->error on
992 992
  *         EOF or error).
993 993
  */
994
-int tls_h_read_f(struct tcp_connection* c, int* flags)
994
+int tls_h_read_f(struct tcp_connection* c, rd_conn_flags_t* flags)
995 995
 {
996 996
 	struct tcp_req* r;
997 997
 	int bytes_free, bytes_read, read_size, ssl_error, ssl_read;
... ...
@@ -30,6 +30,7 @@
30 30
 
31 31
 #include <stdio.h>
32 32
 #include "../../core/tcp_conn.h"
33
+#include "../../core/tcp_read.h"
33 34
 #include "tls_domain.h"
34 35
 #include "tls_ct_wrq.h"
35 36
 
... ...
@@ -87,7 +88,7 @@ int tls_h_encode_f(struct tcp_connection *c, const char ** pbuf,
87 88
 		unsigned int* plen, const char** rest_buf, unsigned int* rest_len,
88 89
 		snd_flags_t* send_flags) ;
89 90
 
90
-int tls_h_read_f(struct tcp_connection *c, int* flags);
91
+int tls_h_read_f(struct tcp_connection *c, rd_conn_flags_t* flags);
91 92
 
92 93
 int tls_h_fix_read_conn(struct tcp_connection *c);
93 94