mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
mm/iob/iob_copyin.c: iob_copyin() should wait for each buffer and adjust the return value of iob_copyin_internal return to simplify the code
This commit is contained in:
+8
-30
@@ -49,20 +49,6 @@
|
|||||||
|
|
||||||
#include "iob.h"
|
#include "iob.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef MIN
|
|
||||||
# define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
typedef CODE struct iob_s *(*iob_alloc_t)(bool throttled);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -198,23 +184,22 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src,
|
|||||||
{
|
{
|
||||||
/* Yes.. allocate a new buffer.
|
/* Yes.. allocate a new buffer.
|
||||||
*
|
*
|
||||||
* Copy as many bytes as possible. If we have successfully copied
|
* Copy as many bytes as possible. Block if we're allowed.
|
||||||
* any already don't block, otherwise block if we're allowed.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!can_block || len < total)
|
if (can_block)
|
||||||
{
|
{
|
||||||
next = iob_tryalloc(throttled);
|
next = iob_alloc(throttled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
next = iob_alloc(throttled);
|
next = iob_tryalloc(throttled);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
{
|
{
|
||||||
ioberr("ERROR: Failed to allocate I/O buffer\n");
|
ioberr("ERROR: Failed to allocate I/O buffer\n");
|
||||||
return len;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the new, empty I/O buffer to the end of the buffer chain. */
|
/* Add the new, empty I/O buffer to the end of the buffer chain. */
|
||||||
@@ -227,7 +212,7 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src,
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -246,7 +231,7 @@ static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src,
|
|||||||
int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
|
int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
|
||||||
unsigned int len, unsigned int offset, bool throttled)
|
unsigned int len, unsigned int offset, bool throttled)
|
||||||
{
|
{
|
||||||
return len - iob_copyin_internal(iob, src, len, offset, throttled, true);
|
return iob_copyin_internal(iob, src, len, offset, throttled, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -262,12 +247,5 @@ int iob_copyin(FAR struct iob_s *iob, FAR const uint8_t *src,
|
|||||||
int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
|
int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src,
|
||||||
unsigned int len, unsigned int offset, bool throttled)
|
unsigned int len, unsigned int offset, bool throttled)
|
||||||
{
|
{
|
||||||
if (iob_copyin_internal(iob, src, len, offset, throttled, false) == 0)
|
return iob_copyin_internal(iob, src, len, offset, throttled, false);
|
||||||
{
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user