summaryrefslogtreecommitdiff
path: root/src/dev/terminal.cc
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-09-19 09:42:31 -0700
committerNathan Binkert <nate@binkert.org>2008-09-19 09:42:31 -0700
commitce3d8c2b038605fa5ceb6d1ad8e27b51c1aca980 (patch)
treed1330c84f7f0a203daeab8fc7fd3c6ec37b80497 /src/dev/terminal.cc
parentaf9c5e05f73f6899a405230e66dfa75a5b39822a (diff)
downloadgem5-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.cc18
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;
}