diff options
author | Nathan Binkert <nate@binkert.org> | 2008-09-19 09:42:31 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2008-09-19 09:42:31 -0700 |
commit | ce3d8c2b038605fa5ceb6d1ad8e27b51c1aca980 (patch) | |
tree | d1330c84f7f0a203daeab8fc7fd3c6ec37b80497 /src/dev/terminal.cc | |
parent | af9c5e05f73f6899a405230e66dfa75a5b39822a (diff) | |
download | gem5-ce3d8c2b038605fa5ceb6d1ad8e27b51c1aca980.tar.xz |
atomicio: provide atomic read and write functions.
These functions keep trying to read and write until all data has been
transferred, or an error occurrs. In the case where an end of file
hasn't been reached, but all of the bytes have not been read/written,
try again. On EINTR, try again.
Diffstat (limited to 'src/dev/terminal.cc')
-rw-r--r-- | src/dev/terminal.cc | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/dev/terminal.cc b/src/dev/terminal.cc index 58371a2bd..8c18e3bbc 100644 --- a/src/dev/terminal.cc +++ b/src/dev/terminal.cc @@ -35,16 +35,17 @@ #include <sys/ioctl.h> #include <sys/termios.h> -#include <sys/types.h> #include <errno.h> #include <poll.h> #include <unistd.h> +#include <cctype> #include <iostream> #include <fstream> #include <sstream> #include <string> +#include "base/atomicio.hh" #include "base/misc.hh" #include "base/output.hh" #include "base/socket.hh" @@ -156,7 +157,7 @@ Terminal::accept() int fd = listener.accept(true); if (data_fd != -1) { char message[] = "terminal already attached!\n"; - ::write(fd, message, sizeof(message)); + atomic_write(fd, message, sizeof(message)); ::close(fd); return; } @@ -238,16 +239,9 @@ Terminal::write(const uint8_t *buf, size_t len) if (data_fd < 0) panic("Terminal not properly attached.\n"); - size_t ret; - for (;;) { - ret = ::write(data_fd, buf, len); - - if (ret >= 0) - break; - - if (errno != EINTR) - detach(); - } + ssize_t ret = atomic_write(data_fd, buf, len); + if (ret < len) + detach(); return ret; } |