1 /* Connect implementation
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include <cc1plugin-config.h>
23 #include <sys/types.h>
26 #include "marshall.hh"
27 #include "connection.hh"
31 cc1_plugin::connection::send (char c
)
33 if (write (m_fd
, &c
, 1) != 1)
39 cc1_plugin::connection::send (const void *buf
, int len
)
41 if (write (m_fd
, buf
, len
) != len
)
47 cc1_plugin::connection::require (char c
)
51 if (read (m_fd
, &result
, 1) != 1
59 cc1_plugin::connection::get (void *buf
, int len
)
61 if (read (m_fd
, buf
, len
) != len
)
67 cc1_plugin::connection::do_wait (bool want_result
)
75 FD_SET (m_fd
, &read_set
);
77 FD_SET (m_aux_fd
, &read_set
);
79 int nfds
= select (FD_SETSIZE
, &read_set
, NULL
, NULL
, NULL
);
87 // We have to check the stderr fd first, to avoid a possible
88 // blocking scenario when do_wait is called reentrantly. In
89 // such a call, if we handle the primary fd first, then we may
90 // re-enter this function, read from gcc's stderr, causing the
91 // outer invocation of this function to block when trying to
93 if (m_aux_fd
!= -1 && FD_ISSET (m_aux_fd
, &read_set
))
96 int n
= read (m_aux_fd
, buf
, sizeof (buf
) - 1);
106 if (FD_ISSET (m_fd
, &read_set
))
108 int n
= read (m_fd
, &result
, 1);
110 return want_result
? FAIL
: OK
;
117 // The reply is ready; the caller will unmarshall it.
118 return want_result
? OK
: FAIL
;
121 // While waiting for a reply, the other side made a method
124 // Use an argument_wrapper here to simplify management
125 // of the string's lifetime.
126 argument_wrapper
<char *> method_name
;
128 if (!method_name
.unmarshall (this))
131 callback_ftype
*callback
132 = m_callbacks
.find_callback (method_name
.get ());
133 // The call to CALLBACK is where we may end up in a
135 if (callback
== NULL
|| !callback (this))