#include "ser-event.h"
#include "serial.h"
#include "gdbsupport/filestuff.h"
+#include "gdbsupport/eintr.h"
/* On POSIX hosts, a serial_event is basically an abstraction for the
classical self-pipe trick.
if (gdb_pipe_cloexec (fds) == -1)
internal_error ("creating serial event pipe failed.");
- fcntl (fds[0], F_SETFL, O_NONBLOCK);
- fcntl (fds[1], F_SETFL, O_NONBLOCK);
+ gdb::fcntl (fds[0], F_SETFL, O_NONBLOCK);
+ gdb::fcntl (fds[1], F_SETFL, O_NONBLOCK);
scb->fd = fds[0];
state->write_fd = fds[1];
{
struct serial_event_state *state = (struct serial_event_state *) scb->state;
- close (scb->fd);
+ gdb::close (scb->fd);
#ifndef USE_WIN32API
- close (state->write_fd);
+ gdb::close (state->write_fd);
#else
CloseHandle (state->event);
#endif
struct serial *ser = (struct serial *) event;
struct serial_event_state *state = (struct serial_event_state *) ser->state;
#ifndef USE_WIN32API
- int r;
char c = '+'; /* Anything. */
- do
- {
- r = write (state->write_fd, &c, 1);
- }
- while (r < 0 && errno == EINTR);
+ gdb::write (state->write_fd, &c, 1);
#else
SetEvent (state->event);
#endif
{
char c;
- r = read (ser->fd, &c, 1);
+ r = gdb::read (ser->fd, &c, 1);
}
- while (r > 0 || (r < 0 && errno == EINTR));
+ while (r > 0);
#else
struct serial_event_state *state = (struct serial_event_state *) ser->state;
ResetEvent (state->event);
return gdb::handle_eintr (-1, ::read, fd, buf, count);
}
+template<typename... Args> int fcntl (int fd, int op, Args... args)
+{
+ return gdb::handle_eintr (-1, ::fcntl, fd, op, args...);
+}
+
+inline ssize_t
+write (int fd, const void *buf, size_t count)
+{
+ return gdb::handle_eintr (-1, ::write, fd, buf, count);
+}
+
} /* namespace gdb */
#endif /* GDBSUPPORT_EINTR_H */