[rtems commit] termios: Implement non-blocking write
Sebastian Huber
sebh at rtems.org
Tue Feb 28 08:43:55 UTC 2017
Module: rtems
Branch: master
Commit: 36635433921323438501e1ffc21392c094773765
Changeset: http://git.rtems.org/rtems/commit/?id=36635433921323438501e1ffc21392c094773765
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Feb 24 14:44:04 2017 +0100
termios: Implement non-blocking write
---
cpukit/libcsupport/src/termios.c | 10 ++++++----
testsuites/libtests/termios09/init.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index e59f977..d105899 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -1214,9 +1214,10 @@ oproc (unsigned char c, rtems_termios_tty *tty, bool wait)
}
static uint32_t
-rtems_termios_write_tty (rtems_termios_tty *tty, const char *buf, uint32_t len)
+rtems_termios_write_tty (rtems_libio_t *iop, rtems_termios_tty *tty,
+ const char *buf, uint32_t len)
{
- bool wait = true;
+ bool wait = ((iop->flags & LIBIO_FLAGS_NO_DELAY) == 0);
if (tty->termios.c_oflag & OPOST) {
uint32_t todo = len;
@@ -1252,7 +1253,8 @@ rtems_termios_write (void *arg)
rtems_semaphore_release (tty->osem);
return sc;
}
- args->bytes_moved = rtems_termios_write_tty (tty, args->buffer, args->count);
+ args->bytes_moved = rtems_termios_write_tty (args->iop, tty,
+ args->buffer, args->count);
rtems_semaphore_release (tty->osem);
return sc;
}
@@ -2162,7 +2164,7 @@ rtems_termios_imfs_write (rtems_libio_t *iop, const void *buffer, size_t count)
return (ssize_t) args.bytes_moved;
}
- bytes_moved = rtems_termios_write_tty (tty, buffer, count);
+ bytes_moved = rtems_termios_write_tty (iop, tty, buffer, count);
rtems_semaphore_release (tty->osem);
return (ssize_t) bytes_moved;
}
diff --git a/testsuites/libtests/termios09/init.c b/testsuites/libtests/termios09/init.c
index 648d1bf..f13804d 100644
--- a/testsuites/libtests/termios09/init.c
+++ b/testsuites/libtests/termios09/init.c
@@ -199,6 +199,24 @@ static void input(test_context *ctx, size_t i, char c)
}
}
+static void enable_non_blocking(test_context *ctx, size_t i, bool enable)
+{
+ int flags;
+ int rv;
+
+ flags = fcntl(ctx->fds[i], F_GETFL, 0);
+ rtems_test_assert(flags >= 0);
+
+ if (enable) {
+ flags |= O_NONBLOCK;
+ } else {
+ flags &= ~O_NONBLOCK;
+ }
+
+ rv = fcntl(ctx->fds[i], F_SETFL, flags);
+ rtems_test_assert(rv == 0);
+}
+
static void clear_set_iflag(
test_context *ctx,
size_t i,
@@ -968,6 +986,11 @@ static void test_write(test_context *ctx)
rtems_test_assert(ctx->context_switch_counter == 0);
+ enable_non_blocking(ctx, i, true);
+ n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 1], 1);
+ rtems_test_assert(n == 0);
+
+ enable_non_blocking(ctx, i, false);
n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 1], 1);
rtems_test_assert(n == 1);
@@ -994,6 +1017,11 @@ static void test_write(test_context *ctx)
rtems_test_assert(ctx->context_switch_counter == 2);
+ enable_non_blocking(ctx, i, true);
+ n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 2], 1);
+ rtems_test_assert(n == 0);
+
+ enable_non_blocking(ctx, i, false);
n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 2], 1);
rtems_test_assert(n == 1);
@@ -1020,6 +1048,11 @@ static void test_write(test_context *ctx)
rtems_test_assert(ctx->context_switch_counter == 4);
+ enable_non_blocking(ctx, i, true);
+ n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 8], 1);
+ rtems_test_assert(n == 0);
+
+ enable_non_blocking(ctx, i, false);
n = write(ctx->fds[i], &buf[OUTPUT_BUFFER_SIZE - 8], 1);
rtems_test_assert(n == 1);
More information about the vc
mailing list