Skip to content

Commit a08d48e

Browse files
jukkarhenrikbrixandersen
authored andcommitted
logging: backend: net: Discard all received data from TCP or UDP socket
If there is received data in the TCP or UDP socket, discard it in order to avoid leaking net_bufs because we are only sending data out and should not receive anything. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent f7c1431 commit a08d48e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

subsys/logging/backends/log_backend_net.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ static struct log_backend_net_ctx {
4646
static int line_out(uint8_t *data, size_t length, void *output_ctx)
4747
{
4848
struct log_backend_net_ctx *ctx = (struct log_backend_net_ctx *)output_ctx;
49-
int ret = -ENOMEM;
5049
struct msghdr msg = { 0 };
5150
struct iovec io_vector[2];
5251
int pos = 0;
52+
int ret;
5353

5454
if (ctx == NULL) {
5555
return length;
@@ -132,6 +132,16 @@ static int do_net_init(struct log_backend_net_ctx *ctx)
132132
goto err;
133133
}
134134

135+
/* Close the reading side of the TCP or UDP socket just in case so that we will
136+
* not run out of RX buffers because we do not read anything.
137+
*/
138+
ret = zsock_shutdown(ctx->sock, ZSOCK_SHUT_RD);
139+
if (ret < 0) {
140+
ret = -errno;
141+
DBG("Cannot shutdown reading side of the socket (%d)\n", ret);
142+
goto err;
143+
}
144+
135145
log_output_ctx_set(&log_output_net, ctx);
136146
log_output_hostname_set(&log_output_net, dev_hostname);
137147

0 commit comments

Comments
 (0)