Merge branch 'ieee802154'

This commit is contained in:
Gregory Nutt 2017-05-12 07:36:08 -06:00
commit 3587a010c3
4 changed files with 104 additions and 72 deletions

2
TODO
View File

@ -490,7 +490,7 @@ o pthreads (sched/pthreads)
Status: Not really open. This is just the way it is. Status: Not really open. This is just the way it is.
Priority: Nothing additional is planned. Priority: Nothing additional is planned.
Title: PTHREAD FILES IN WRONG LOCATTION Title: PTHREAD FILES IN WRONG LOCATION
Description: There are many pthread interface functions in files located in Description: There are many pthread interface functions in files located in
sched/pthread. These should be moved from that location to sched/pthread. These should be moved from that location to
libc/pthread. In the flat build, this really does not matter, libc/pthread. In the flat build, this really does not matter,

View File

@ -518,9 +518,22 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
remaining > 0; remaining > 0;
endptr++, remaining--) endptr++, remaining--)
{ {
bool crlf = false;
/* Check for a CR-LF sequence */
if (remaining > 1 &&
((endptr[0] == '\r' && endptr[1] == '\n') ||
(endptr[0] == '\n' && endptr[1] == '\r')))
{
endptr++;
remaining--;
crlf = true;
}
/* Special case carriage return and line feed */ /* Special case carriage return and line feed */
if (*endptr == '\r' || *endptr == '\n') if (!crlf && (*endptr == '\r' || *endptr == '\n'))
{ {
/* Write everything up to this point, ignore the special /* Write everything up to this point, ignore the special
* character. * character.

View File

@ -54,6 +54,73 @@
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: syslogstream_flush
****************************************************************************/
#ifdef CONFIG_SYSLOG_BUFFER
static int syslogstream_flush(FAR struct lib_syslogstream_s *stream)
{
FAR struct iob_s *iob;
int ret = OK;
DEBUGASSERT(stream != NULL);
iob = stream->iob;
/* Do we have an IO buffer? Is there anything buffered? */
if (iob != NULL && iob->io_len > 0)
{
/* Yes write the buffered data */
do
{
ssize_t nbytes = syslog_write((FAR const char *)iob->io_data,
(size_t)iob->io_len);
if (nbytes < 0)
{
ret = -get_errno();
}
else
{
iob->io_len = 0;
ret = OK;
}
}
while (ret == -EINTR);
}
return ret;
}
#endif
/****************************************************************************
* Name: syslogstream_addchar
****************************************************************************/
static void syslogstream_addchar(FAR struct lib_syslogstream_s *stream, int ch)
{
FAR struct iob_s *iob = stream->iob;
/* Add the incoming character to the buffer */
iob->io_data[iob->io_len] = ch;
iob->io_len++;
/* Increment the total number of bytes buffered. */
stream->public.nput++;
/* Is the buffer full? */
if (iob->io_len >= CONFIG_IOB_BUFSIZE)
{
/* Yes.. then flush the buffer */
syslogstream_flush(stream);
}
}
/**************************************************************************** /****************************************************************************
* Name: syslogstream_putc * Name: syslogstream_putc
****************************************************************************/ ****************************************************************************/
@ -65,31 +132,27 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
if (ch != '\r') if (ch != '\r')
{ {
#ifdef CONFIG_SYSLOG_BUFFER #ifdef CONFIG_SYSLOG_BUFFER
FAR struct lib_syslogstream_s *stream; FAR struct lib_syslogstream_s *stream =
FAR struct iob_s *iob; (FAR struct lib_syslogstream_s *)this;
DEBUGASSERT(this != NULL); DEBUGASSERT(stream != NULL);
stream = (FAR struct lib_syslogstream_s *)this;
iob = stream->iob;
/* Do we have an IO buffer? */ /* Do we have an IO buffer? */
if (iob != NULL) if (stream->iob != NULL)
{ {
/* Yes.. Add the incoming character to the buffer */ /* Is this a linefeed? */
iob->io_data[iob->io_len] = ch; if (ch == '\n')
iob->io_len++;
this->nput++;
/* Is the buffer full? */
if (iob->io_len >= CONFIG_IOB_BUFSIZE)
{ {
/* Yes.. then flush the buffer */ /* Yes... pre-pend carriage return */
(void)this->flush(this); syslogstream_addchar(stream, '\r');
} }
/* Add the incoming character to the buffer */
syslogstream_addchar(stream, ch);
} }
else else
#endif #endif
@ -123,48 +186,6 @@ static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
} }
} }
/****************************************************************************
* Name: syslogstream_flush
****************************************************************************/
#ifdef CONFIG_SYSLOG_BUFFER
static int syslogstream_flush(FAR struct lib_outstream_s *this)
{
FAR struct lib_syslogstream_s *stream;
FAR struct iob_s *iob;
int ret = OK;
DEBUGASSERT(this != NULL);
stream = (FAR struct lib_syslogstream_s *)this;
iob = stream->iob;
/* Do we have an IO buffer? Is there anything buffered? */
if (iob != NULL && iob->io_len > 0)
{
/* Yes write the buffered data */
do
{
ssize_t nbytes = syslog_write((FAR const char *)iob->io_data,
(size_t)iob->io_len);
if (nbytes < 0)
{
ret = -get_errno();
}
else
{
iob->io_len = 0;
ret = OK;
}
}
while (ret == -EINTR);
}
return ret;
}
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -187,17 +208,19 @@ static int syslogstream_flush(FAR struct lib_outstream_s *this)
void syslogstream_create(FAR struct lib_syslogstream_s *stream) void syslogstream_create(FAR struct lib_syslogstream_s *stream)
{ {
DEBUGASSERT(stream != NULL);
#ifdef CONFIG_SYSLOG_BUFFER #ifdef CONFIG_SYSLOG_BUFFER
FAR struct iob_s *iob; FAR struct iob_s *iob;
#endif
DEBUGASSERT(stream != NULL);
/* Initialize the common fields */ /* Initialize the common fields */
stream->public.put = syslogstream_putc; stream->public.put = syslogstream_putc;
stream->public.flush = syslogstream_flush; stream->public.flush = lib_noflush;
stream->public.nput = 0; stream->public.nput = 0;
#ifdef CONFIG_SYSLOG_BUFFER
/* Allocate an IOB */ /* Allocate an IOB */
iob = iob_alloc(true); iob = iob_alloc(true);
@ -211,10 +234,6 @@ void syslogstream_create(FAR struct lib_syslogstream_s *stream)
iob->io_offset = 0; iob->io_offset = 0;
iob->io_pktlen = 0; iob->io_pktlen = 0;
} }
#else
stream->public.put = syslogstream_putc;
stream->public.flush = lib_noflush;
stream->public.nput = 0;
#endif #endif
} }
@ -242,6 +261,10 @@ void syslogstream_destroy(FAR struct lib_syslogstream_s *stream)
if (stream->iob != NULL) if (stream->iob != NULL)
{ {
/* Flush the output buffered in the IOB */
syslogstream_flush(stream);
/* Free the IOB */ /* Free the IOB */
iob_free(stream->iob); iob_free(stream->iob);

View File

@ -131,12 +131,8 @@ int _vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
ret = lib_vsprintf(&stream.public, fmt, *ap); ret = lib_vsprintf(&stream.public, fmt, *ap);
/* Flush the output */
stream.public.flush(&stream.public);
#ifdef CONFIG_SYSLOG_BUFFER #ifdef CONFIG_SYSLOG_BUFFER
/* Destroy the syslog stream buffer */ /* Flush and destroy the syslog stream buffer */
if (priority != LOG_EMERG) if (priority != LOG_EMERG)
{ {