Skip to content

Commit ab650ec

Browse files
committed
Merge branch 'dev'
2 parents 95afa32 + 8f36597 commit ab650ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1074
-461
lines changed

docs/c-api/mbuf.h/intro.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ symbol_kind: "intro"
44
decl_name: "mbuf.h"
55
items:
66
- { name: mbuf_append.md }
7+
- { name: mbuf_append_and_free.md }
8+
- { name: mbuf_clear.md }
79
- { name: mbuf_free.md }
810
- { name: mbuf_init.md }
911
- { name: mbuf_insert.md }
12+
- { name: mbuf_move.md }
1013
- { name: mbuf_remove.md }
1114
- { name: mbuf_resize.md }
1215
- { name: mbuf_trim.md }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "mbuf_append_and_free()"
3+
decl_name: "mbuf_append_and_free"
4+
symbol_kind: "func"
5+
signature: |
6+
size_t mbuf_append_and_free(struct mbuf *, void *data, size_t data_size);
7+
---
8+
9+
Appends data to the Mbuf and frees it (data must be heap-allocated).
10+
11+
Returns the number of bytes appended or 0 if out of memory.
12+
data is freed irrespective of return value.
13+

docs/c-api/mbuf.h/mbuf_clear.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "mbuf_clear()"
3+
decl_name: "mbuf_clear"
4+
symbol_kind: "func"
5+
signature: |
6+
void mbuf_clear(struct mbuf *);
7+
---
8+
9+
Removes all the data from mbuf (if any).
10+

docs/c-api/mbuf.h/mbuf_move.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "mbuf_move()"
3+
decl_name: "mbuf_move"
4+
symbol_kind: "func"
5+
signature: |
6+
void mbuf_move(struct mbuf *from, struct mbuf *to);
7+
---
8+
9+
Moves the state from one mbuf to the other.
10+

docs/c-api/mg_http.h/mg_set_protocol_http_websocket.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ The user-defined event handler will receive following extra events:
3030
- MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received the WebSocket
3131
handshake request. `ev_data` contains parsed HTTP request.
3232
- MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed the WebSocket
33-
handshake. `ev_data` is `NULL`.
33+
handshake. `ev_data` is a `struct http_message` containing the
34+
client's request (server mode) or server's response (client).
35+
In client mode handler can examine `resp_code`, which should be 101.
3436
- MG_EV_WEBSOCKET_FRAME: new WebSocket frame has arrived. `ev_data` is
3537
`struct websocket_message *`
3638

docs/c-api/mg_http.h/struct_mg_http_multipart_part.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ signature: |
99
struct mg_str data;
1010
int status; /* <0 on error */
1111
void *user_data;
12+
/*
13+
* User handler can indicate how much of the data was consumed
14+
* by setting this variable. By default, it is assumed that all
15+
* data has been consumed by the handler.
16+
* If not all data was consumed, user's handler will be invoked again later
17+
* with the remainder.
18+
*/
19+
size_t num_data_consumed;
1220
};
1321
---
1422

docs/c-api/mg_net.h/mg_broadcast.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ that can be, and must be, called from a different (non-IO) thread.
1616
`func` callback function will be called by the IO thread for each
1717
connection. When called, the event will be `MG_EV_POLL`, and a message will
1818
be passed as the `ev_data` pointer. Maximum message size is capped
19-
by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
19+
by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes by default.
2020

docs/c-api/mg_net.h/struct_mg_connection.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ signature: |
4646
#define MG_F_WANT_READ (1 << 6) /* SSL specific */
4747
#define MG_F_WANT_WRITE (1 << 7) /* SSL specific */
4848
#define MG_F_IS_WEBSOCKET (1 << 8) /* Websocket specific */
49+
#define MG_F_RECV_AND_CLOSE (1 << 9) /* Drain rx and close the connection. */
4950
5051
/* Flags that are settable by user */
5152
#define MG_F_SEND_AND_CLOSE (1 << 10) /* Push remaining data and close */

examples/CC3200/bm222.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ bool bm222_get_data(struct bm222_ctx *ctx) {
9898
s->y = v[3];
9999
s->z = v[5];
100100
if (d > max_d) max_d = d;
101-
LOG(LL_VERBOSE_DEBUG, ("dx %d dy %d dz %d d %d", dx, dy, dz, d));
101+
LOG(LL_VERBOSE_DEBUG,
102+
("dx %d dy %d dz %d d %d", (int) dx, (int) dy, (int) dz, (int) d));
102103
}
103104
}
104105
return (overflow ? bm222_fifo_init(ctx) : true); /* Clear the ovf flag. */

examples/CC3200/cs_dbg.h

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
/*
2-
* Copyright (c) 2014-2016 Cesanta Software Limited
2+
* Copyright (c) 2014-2018 Cesanta Software Limited
33
* All rights reserved
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the ""License"");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an ""AS IS"" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
416
*/
517

618
#ifndef CS_COMMON_CS_DBG_H_
719
#define CS_COMMON_CS_DBG_H_
820

21+
#include "common/platform.h"
22+
923
#if CS_ENABLE_STDIO
1024
#include <stdio.h>
1125
#endif
@@ -14,6 +28,10 @@
1428
#define CS_ENABLE_DEBUG 0
1529
#endif
1630

31+
#ifndef CS_LOG_PREFIX_LEN
32+
#define CS_LOG_PREFIX_LEN 24
33+
#endif
34+
1735
#ifndef CS_LOG_ENABLE_TS_DIFF
1836
#define CS_LOG_ENABLE_TS_DIFF 0
1937
#endif
@@ -22,6 +40,9 @@
2240
extern "C" {
2341
#endif /* __cplusplus */
2442

43+
/*
44+
* Log level; `LL_INFO` is the default. Use `cs_log_set_level()` to change it.
45+
*/
2546
enum cs_log_level {
2647
LL_NONE = -1,
2748
LL_ERROR = 0,
@@ -34,29 +55,78 @@ enum cs_log_level {
3455
_LL_MAX = 5,
3556
};
3657

58+
/*
59+
* Set max log level to print; messages with the level above the given one will
60+
* not be printed.
61+
*/
3762
void cs_log_set_level(enum cs_log_level level);
3863

64+
/*
65+
* A comma-separated set of prefix=level.
66+
* prefix is matched against the log prefix exactly as printed, including line
67+
* number, but partial match is ok. Check stops on first matching entry.
68+
* If nothing matches, default level is used.
69+
*
70+
* Examples:
71+
* main.c:=4 - everything from main C at verbose debug level.
72+
* mongoose.c=1,mjs.c=1,=4 - everything at verbose debug except mg_* and mjs_*
73+
*
74+
*/
75+
void cs_log_set_file_level(const char *file_level);
76+
77+
/*
78+
* Helper function which prints message prefix with the given `level`.
79+
* If message should be printed (according to the current log level
80+
* and filter), prints the prefix and returns 1, otherwise returns 0.
81+
*
82+
* Clients should typically just use `LOG()` macro.
83+
*/
84+
int cs_log_print_prefix(enum cs_log_level level, const char *fname, int line);
85+
86+
extern enum cs_log_level cs_log_level;
87+
3988
#if CS_ENABLE_STDIO
4089

90+
/*
91+
* Set file to write logs into. If `NULL`, logs go to `stderr`.
92+
*/
4193
void cs_log_set_file(FILE *file);
4294

43-
extern enum cs_log_level cs_log_threshold;
44-
void cs_log_print_prefix(const char *func);
45-
void cs_log_printf(const char *fmt, ...);
95+
/*
96+
* Prints log to the current log file, appends "\n" in the end and flushes the
97+
* stream.
98+
*/
99+
void cs_log_printf(const char *fmt, ...) PRINTF_LIKE(1, 2);
100+
101+
#if CS_ENABLE_STDIO
102+
103+
/*
104+
* Format and print message `x` with the given level `l`. Example:
105+
*
106+
* ```c
107+
* LOG(LL_INFO, ("my info message: %d", 123));
108+
* LOG(LL_DEBUG, ("my debug message: %d", 123));
109+
* ```
110+
*/
111+
#define LOG(l, x) \
112+
do { \
113+
if (cs_log_print_prefix(l, __FILE__, __LINE__)) { \
114+
cs_log_printf x; \
115+
} \
116+
} while (0)
46117

47-
#define LOG(l, x) \
48-
if (cs_log_threshold >= l) { \
49-
cs_log_print_prefix(__func__); \
50-
cs_log_printf x; \
51-
}
118+
#else
119+
120+
#define LOG(l, x) ((void) l)
121+
122+
#endif
52123

53124
#ifndef CS_NDEBUG
54125

55-
#define DBG(x) \
56-
if (cs_log_threshold >= LL_VERBOSE_DEBUG) { \
57-
cs_log_print_prefix(__func__); \
58-
cs_log_printf x; \
59-
}
126+
/*
127+
* Shortcut for `LOG(LL_VERBOSE_DEBUG, (...))`
128+
*/
129+
#define DBG(x) LOG(LL_VERBOSE_DEBUG, x)
60130

61131
#else /* NDEBUG */
62132

0 commit comments

Comments
 (0)