stream/syslograw: remove support for iob buffer in syslog

IOB buffer participates in the calculation of the congestion strategy
in the protocol stack, if the iob buffer is exhausted or there are
too many syslog printing tasks, the behavior of the protocol stack
and log printing will unable to determined, this PR will remove support
for iob buffer in syslog

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-09-12 13:44:15 +08:00 committed by Xiang Xiao
parent 0451ead2c5
commit 2b4ab6cd29
2 changed files with 60 additions and 118 deletions

View File

@ -250,19 +250,11 @@ struct lib_syslogstream_s
int priority;
};
struct iob_s; /* Forward reference */
struct lib_syslograwstream_s
{
struct lib_outstream_s common;
#ifdef CONFIG_SYSLOG_BUFFER
# ifdef CONFIG_MM_IOB
FAR struct iob_s *iob;
# else
char buffer[CONFIG_SYSLOG_BUFSIZE];
# endif
FAR char *base;
int size;
int offset;
#endif
int last_ch;

View File

@ -26,7 +26,6 @@
#include <errno.h>
#include <stddef.h>
#include <nuttx/mm/iob.h>
#include <nuttx/streams.h>
#include <nuttx/syslog/syslog.h>
@ -39,22 +38,22 @@
* Name: syslograwstream_flush
****************************************************************************/
static int syslograwstream_flush(FAR struct lib_outstream_s *ostream)
static int syslograwstream_flush(FAR struct lib_outstream_s *self)
{
FAR struct lib_syslograwstream_s *stream = (FAR void *)ostream;
FAR struct lib_syslograwstream_s *stream = (FAR void *)self;
int ret = OK;
DEBUGASSERT(stream != NULL);
/* Do we have an IO buffer? Is there anything buffered? */
if (stream->base != NULL && stream->offset > 0)
if (stream->offset > 0)
{
/* Yes write the buffered data */
do
{
ssize_t nbytes = syslog_write(stream->base, stream->offset);
ssize_t nbytes = syslog_write(stream->buffer, stream->offset);
if (nbytes < 0)
{
ret = nbytes;
@ -80,7 +79,7 @@ static void syslograwstream_addchar(FAR struct lib_syslograwstream_s *stream,
{
/* Add the incoming character to the buffer */
stream->base[stream->offset] = ch;
stream->buffer[stream->offset] = ch;
stream->offset++;
/* Increment the total number of bytes buffered. */
@ -89,7 +88,7 @@ static void syslograwstream_addchar(FAR struct lib_syslograwstream_s *stream,
/* Is the buffer full? */
if (stream->offset >= stream->size)
if (stream->offset >= CONFIG_SYSLOG_BUFSIZE)
{
/* Yes.. then flush the buffer */
@ -109,15 +108,15 @@ syslograwstream_addstring(FAR struct lib_syslograwstream_s *stream,
do
{
int remain = stream->size - stream->offset;
int remain = CONFIG_SYSLOG_BUFSIZE - stream->offset;
remain = remain > len - ret ? len - ret : remain;
memcpy(stream->base + stream->offset, buff + ret, remain);
memcpy(stream->buffer + stream->offset, buff + ret, remain);
stream->offset += remain;
ret += remain;
/* Is the buffer enough? */
if (stream->offset >= stream->size)
if (stream->offset >= CONFIG_SYSLOG_BUFSIZE)
{
/* Yes.. then flush the buffer */
@ -139,8 +138,7 @@ syslograwstream_addstring(FAR struct lib_syslograwstream_s *stream,
static void syslograwstream_putc(FAR struct lib_outstream_s *self, int ch)
{
FAR struct lib_syslograwstream_s *stream =
(FAR struct lib_syslograwstream_s *)self;
FAR struct lib_syslograwstream_s *stream = (FAR void *)self;
DEBUGASSERT(stream != NULL);
stream->last_ch = ch;
@ -149,18 +147,11 @@ static void syslograwstream_putc(FAR struct lib_outstream_s *self, int ch)
if (ch != '\r')
{
# ifdef CONFIG_SYSLOG_BUFFER
/* Do we have an IO buffer? */
if (stream->base != NULL)
{
#ifdef CONFIG_SYSLOG_BUFFER
/* Add the incoming character to the buffer */
syslograwstream_addchar(stream, ch);
}
else
# endif
{
#else
int ret;
/* Try writing until the write was successful or until an
@ -186,16 +177,14 @@ static void syslograwstream_putc(FAR struct lib_outstream_s *self, int ch)
*/
}
while (ret == -EINTR);
}
#endif
}
}
static int syslograwstream_puts(FAR struct lib_outstream_s *self,
FAR const void *buff, int len)
{
FAR struct lib_syslograwstream_s *stream =
(FAR struct lib_syslograwstream_s *)self;
int ret;
FAR struct lib_syslograwstream_s *stream = (FAR void *)self;
DEBUGASSERT(stream != NULL);
if (len <= 0)
@ -207,17 +196,12 @@ static int syslograwstream_puts(FAR struct lib_outstream_s *self,
#ifdef CONFIG_SYSLOG_BUFFER
/* Do we have an IO buffer? */
if (stream->base != NULL)
{
/* Add the incoming string to the buffer */
ret = syslograwstream_addstring(stream, buff, len);
}
else
#endif
{
return syslograwstream_addstring(stream, buff, len);
#else
int ret;
/* Try writing until the write was successful or until an
* irrecoverable error occurs.
*/
@ -241,9 +225,10 @@ static int syslograwstream_puts(FAR struct lib_outstream_s *self,
*/
}
while (ret == -EINTR);
}
return ret;
#endif
}
/****************************************************************************
@ -278,25 +263,6 @@ void lib_syslograwstream_open(FAR struct lib_syslograwstream_s *stream)
#ifdef CONFIG_SYSLOG_BUFFER
stream->common.flush = syslograwstream_flush;
/* Allocate an IOB */
# ifdef CONFIG_MM_IOB
stream->iob = iob_tryalloc(true);
if (stream->iob != NULL)
{
stream->base = (FAR void *)stream->iob->io_data;
stream->size = sizeof(stream->iob->io_data);
}
else
{
stream->base = NULL;
stream->size = 0;
}
# else
stream->base = stream->buffer;
stream->size = sizeof(stream->buffer);
# endif
stream->offset = 0;
#else
stream->common.flush = lib_noflush;
@ -323,22 +289,6 @@ void lib_syslograwstream_close(FAR struct lib_syslograwstream_s *stream)
{
DEBUGASSERT(stream != NULL);
/* Verify that there is an IOB attached (there should be) */
# ifdef CONFIG_MM_IOB
if (stream->iob != NULL)
{
/* Flush the output buffered in the IOB */
syslograwstream_flush(&stream->common);
/* Free the IOB */
iob_free(stream->iob);
stream->iob = NULL;
}
# else
syslograwstream_flush(&stream->common);
# endif
}
#endif