1 /* Event pipe for GDB, the GNU debugger.
3 Copyright (C) 2021-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/event-pipe.h"
21 #include "gdbsupport/filestuff.h"
22 #include "gdbsupport/eintr.h"
28 event_pipe::~event_pipe ()
34 /* See event-pipe.h. */
37 event_pipe::open_pipe ()
42 if (gdb_pipe_cloexec (m_fds
) == -1)
45 if (gdb::fcntl (m_fds
[0], F_SETFL
, O_NONBLOCK
) == -1
46 || gdb::fcntl (m_fds
[1], F_SETFL
, O_NONBLOCK
) == -1)
55 /* See event-pipe.h. */
58 event_pipe::close_pipe ()
60 gdb::close (m_fds
[0]);
61 gdb::close (m_fds
[1]);
66 /* See event-pipe.h. */
76 ret
= gdb::read (m_fds
[0], &buf
, 1);
81 /* See event-pipe.h. */
86 /* It doesn't really matter what the pipe contains, as long we end
87 up with something in it. Might as well flush the previous
91 gdb::write (m_fds
[1], "+", 1);
93 /* Ignore EAGAIN. If the pipe is full, the event loop will already
94 be awakened anyway. */