mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 15:13:34 +08:00
drivers/serial/serial.c open, read, write, and poll methods will not return a short transfer or an EINTR error if a signal is received while waiting (only)
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5022 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* lib/stdio/lib_libfwrite.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_lowinstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -42,7 +42,9 @@
|
||||
#ifdef CONFIG_ARCH_LOWGETC
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
@@ -57,10 +59,19 @@
|
||||
|
||||
static int lowinstream_getc(FAR struct lib_instream_s *this)
|
||||
{
|
||||
if (this && up_getc(ch) != EOF)
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(this);
|
||||
|
||||
/* Get the next character from the incoming stream */
|
||||
|
||||
ret = up_getc(ch)
|
||||
if (ret != EOF)
|
||||
{
|
||||
this->nget++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#ifdef CONFIG_ARCH_LOWPUTC
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
@@ -57,7 +58,9 @@
|
||||
|
||||
static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
if (this && up_putc(ch) != EOF)
|
||||
DEBUGASSERT(this);
|
||||
|
||||
if (up_putc(ch) != EOF)
|
||||
{
|
||||
this->nput++;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_meminstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,8 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -52,7 +54,11 @@ static int meminstream_getc(FAR struct lib_instream_s *this)
|
||||
FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this;
|
||||
int ret;
|
||||
|
||||
if (this && this->nget < mthis->buflen)
|
||||
DEBUGASSERT(this);
|
||||
|
||||
/* Get the next character (if any) from the buffer */
|
||||
|
||||
if (this->nget < mthis->buflen)
|
||||
{
|
||||
ret = mthis->buffer[this->nget];
|
||||
this->nget++;
|
||||
@@ -61,6 +67,7 @@ static int meminstream_getc(FAR struct lib_instream_s *this)
|
||||
{
|
||||
ret = EOF;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -51,12 +53,14 @@ static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this;
|
||||
|
||||
DEBUGASSERT(this);
|
||||
|
||||
/* If this will not overrun the buffer, then write the character to the
|
||||
* buffer. Not that buflen was pre-decremented when the stream was
|
||||
* created so it is okay to write past the end of the buflen by one.
|
||||
*/
|
||||
|
||||
if (this && this->nput < mthis->buflen)
|
||||
if (this->nput < mthis->buflen)
|
||||
{
|
||||
mthis->buffer[this->nput] = ch;
|
||||
this->nput++;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_nullinstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -47,6 +49,7 @@
|
||||
|
||||
static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
DEBUGASSERT(this);
|
||||
this->nput++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_rawinstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -38,7 +38,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -52,23 +54,27 @@
|
||||
static int rawinstream_getc(FAR struct lib_instream_s *this)
|
||||
{
|
||||
FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this;
|
||||
int nwritten;
|
||||
char ch;
|
||||
|
||||
if (this && rthis->fd >= 0)
|
||||
DEBUGASSERT(this && rthis->fd >= 0);
|
||||
|
||||
/* Attempt to read one character */
|
||||
|
||||
nwritten = read(rthis->fd, &ch, 1);
|
||||
if (nwritten == 1)
|
||||
{
|
||||
int nwritten;
|
||||
do
|
||||
{
|
||||
nwritten = read(rthis->fd, &ch, 1);
|
||||
if (nwritten == 1)
|
||||
{
|
||||
this->nget++;
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
while (nwritten < 0 && get_errno() == EINTR);
|
||||
this->nget++;
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* Return EOF on any failure to read from the incoming byte stream. The
|
||||
* only expected error is EINTER meaning that the read was interrupted
|
||||
* by a signal. A Zero return value would indicated an end-of-file
|
||||
* confition.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(nwritten == 0 || get_errno() == EINTR);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -52,19 +54,28 @@
|
||||
static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this;
|
||||
int nwritten;
|
||||
char buffer = ch;
|
||||
if (this && rthis->fd >= 0)
|
||||
|
||||
DEBUGASSERT(this && rthis->fd >= 0);
|
||||
|
||||
/* Loop until the character is successfully transferred */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int nwritten;
|
||||
do
|
||||
nwritten = write(rthis->fd, &buffer, 1);
|
||||
if (nwritten == 1)
|
||||
{
|
||||
nwritten = write(rthis->fd, &buffer, 1);
|
||||
if (nwritten == 1)
|
||||
{
|
||||
this->nput++;
|
||||
}
|
||||
this->nput++;
|
||||
return;
|
||||
}
|
||||
while (nwritten < 0 && get_errno() == EINTR);
|
||||
|
||||
/* The only expected error is EINTR, meaning that the write operation
|
||||
* was awakened by a signal. Zero would not be a valid return value
|
||||
* either.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(nwritten < 0 && get_errno() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_stdinstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -37,6 +37,8 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
@@ -50,16 +52,19 @@
|
||||
static int stdinstream_getc(FAR struct lib_instream_s *this)
|
||||
{
|
||||
FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this;
|
||||
if (this)
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(this);
|
||||
|
||||
/* Get the next character from the incoming stream */
|
||||
|
||||
ret = getc(sthis->stream);
|
||||
if (ret != EOF)
|
||||
{
|
||||
int ret = getc(sthis->stream);
|
||||
if (ret != EOF)
|
||||
{
|
||||
this->nget++;
|
||||
}
|
||||
return ret;
|
||||
this->nget++;
|
||||
}
|
||||
return EOF;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/****************************************************************************
|
||||
* lib/stdio/lib_stdoutstream.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -38,6 +38,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lib_internal.h"
|
||||
|
||||
@@ -52,12 +54,26 @@
|
||||
static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this;
|
||||
if (this)
|
||||
int result;
|
||||
|
||||
DEBUGASSERT(this && sthis->stream);
|
||||
|
||||
/* Loop until the character is successfully transferred */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (putc(ch, sthis->stream) != EOF)
|
||||
result = fputc(ch, sthis->stream);
|
||||
if (result != EOF)
|
||||
{
|
||||
this->nput++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* EINTR (meaning that fputc was interrupted by a signal) is the only
|
||||
* expected error.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(get_errno() == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/syslog.h>
|
||||
@@ -62,10 +63,31 @@
|
||||
|
||||
static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||
{
|
||||
/* Write the character to the supported logging device */
|
||||
int ret;
|
||||
|
||||
(void)syslog_putc(ch);
|
||||
this->nput++;
|
||||
/* Try writing until the write was successful or until an irrecoverable
|
||||
* error occurs.
|
||||
*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Write the character to the supported logging device */
|
||||
|
||||
ret = syslog_putc(ch);
|
||||
if (ret == OK)
|
||||
{
|
||||
this->nput++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* On failure syslog_putc will return a negated errno value. The
|
||||
* errno variable will not be set. The special value -EINTR means that
|
||||
* syslog_putc() was awakened by a signal. This is not a real error and
|
||||
* must be ignored in this context.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == -EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user