Skip to content

Commit

Permalink
stream/syslograw: remove support for iob buffer in syslog
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
anchao committed Sep 12, 2024
1 parent 75ed9a4 commit 007135a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 117 deletions.
10 changes: 1 addition & 9 deletions include/nuttx/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,12 @@ 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;
int offset;
#endif
int last_ch;
};
Expand Down
166 changes: 58 additions & 108 deletions libs/libc/stream/lib_syslograwstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <errno.h>
#include <stddef.h>

#include <nuttx/mm/iob.h>
#include <nuttx/streams.h>
#include <nuttx/syslog/syslog.h>

Expand All @@ -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;
Expand All @@ -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. */
Expand All @@ -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 */

Expand All @@ -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 */

Expand All @@ -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;
Expand All @@ -149,53 +147,44 @@ 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? */
#ifdef CONFIG_SYSLOG_BUFFER
/* Add the incoming character to the buffer */

if (stream->base != NULL)
{
/* Add the incoming character to the buffer */
syslograwstream_addchar(stream, ch);
#else
int ret;

syslograwstream_addchar(stream, ch);
}
else
# endif
{
int ret;
/* Try writing until the write was successful or until an
* irrecoverable error occurs.
*/

/* Try writing until the write was successful or until an
* irrecoverable error occurs.
do
{
/* Write the character to the supported logging device. On
* failure, syslog_putc returns a negated errno value.
*/

do
ret = syslog_putc(ch);
if (ret >= 0)
{
/* Write the character to the supported logging device. On
* failure, syslog_putc returns a negated errno value.
*/

ret = syslog_putc(ch);
if (ret >= 0)
{
self->nput++;
return;
}

/* The special return value -EINTR means that syslog_putc() was
* awakened by a signal. This is not a real error and must be
* ignored in this context.
*/
self->nput++;
return;
}
while (ret == -EINTR);

/* The special return value -EINTR means that syslog_putc() was
* awakened by a signal. This is not a real error and must be
* ignored in this context.
*/
}
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)
Expand All @@ -207,43 +196,39 @@ static int syslograwstream_puts(FAR struct lib_outstream_s *self,

#ifdef CONFIG_SYSLOG_BUFFER

/* Do we have an IO buffer? */
/* Add the incoming string to the buffer */

if (stream->base != NULL)
{
/* Add the incoming string to the buffer */
return syslograwstream_addstring(stream, buff, len);
#else
int ret;

ret = syslograwstream_addstring(stream, buff, len);
}
else
#endif
/* Try writing until the write was successful or until an
* irrecoverable error occurs.
*/

do
{
/* Try writing until the write was successful or until an
* irrecoverable error occurs.
/* Write the buffer to the supported logging device. On
* failure, syslog_write returns a negated errno value.
*/

do
ret = syslog_write(buff, len);
if (ret >= 0)
{
/* Write the buffer to the supported logging device. On
* failure, syslog_write returns a negated errno value.
*/

ret = syslog_write(buff, len);
if (ret >= 0)
{
self->nput += ret;
return ret;
}

/* The special return value -EINTR means that syslog_putc() was
* awakened by a signal. This is not a real error and must be
* ignored in this context.
*/
self->nput += ret;
return ret;
}
while (ret == -EINTR);

/* The special return value -EINTR means that syslog_putc() was
* awakened by a signal. This is not a real error and must be
* ignored in this context.
*/
}
while (ret == -EINTR);

return ret;

#endif
}

/****************************************************************************
Expand Down Expand Up @@ -278,26 +263,7 @@ 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;
stream->offset = 0;
#else
stream->common.flush = lib_noflush;
#endif
Expand All @@ -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

0 comments on commit 007135a

Please sign in to comment.