Use timeout when reading debugserver's port from a named pipe.
http://reviews.llvm.org/D6490 llvm-svn: 223251
This commit is contained in:
parent
d365731dd0
commit
e8fb6937ba
|
@ -13,6 +13,7 @@
|
||||||
// C Includes
|
// C Includes
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/select.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
// C++ Includes
|
// C++ Includes
|
||||||
|
@ -42,6 +43,50 @@
|
||||||
using namespace lldb;
|
using namespace lldb;
|
||||||
using namespace lldb_private;
|
using namespace lldb_private;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
Error
|
||||||
|
ReadPortFromPipe (const char *const named_pipe_path, uint16_t& port, const int timeout_secs)
|
||||||
|
{
|
||||||
|
File name_pipe_file;
|
||||||
|
auto error = name_pipe_file.Open (named_pipe_path, File::eOpenOptionRead | File::eOpenOptionNonBlocking);
|
||||||
|
if (error.Fail ())
|
||||||
|
return error;
|
||||||
|
|
||||||
|
struct timeval tv = {timeout_secs, 0};
|
||||||
|
const auto pipe_handle = name_pipe_file.GetWaitableHandle ();
|
||||||
|
fd_set rfds;
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(pipe_handle, &rfds);
|
||||||
|
|
||||||
|
const auto retval = ::select (pipe_handle + 1, &rfds, NULL, NULL, &tv);
|
||||||
|
if (retval == -1)
|
||||||
|
{
|
||||||
|
error.SetErrorToErrno ();
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (retval == 0)
|
||||||
|
{
|
||||||
|
error.SetErrorString ("timeout exceeded");
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
char port_cstr[256];
|
||||||
|
port_cstr[0] = '\0';
|
||||||
|
size_t num_bytes = sizeof(port_cstr);
|
||||||
|
error = name_pipe_file.Read (port_cstr, num_bytes);
|
||||||
|
|
||||||
|
if (error.Success ())
|
||||||
|
{
|
||||||
|
assert (num_bytes > 0 && port_cstr[num_bytes-1] == '\0');
|
||||||
|
port = Args::StringToUInt32 (port_cstr, 0);
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
GDBRemoteCommunication::History::History (uint32_t size) :
|
GDBRemoteCommunication::History::History (uint32_t size) :
|
||||||
m_packets(),
|
m_packets(),
|
||||||
m_curr_idx (0),
|
m_curr_idx (0),
|
||||||
|
@ -879,18 +924,16 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname,
|
||||||
{
|
{
|
||||||
if (named_pipe_path[0])
|
if (named_pipe_path[0])
|
||||||
{
|
{
|
||||||
File name_pipe_file;
|
error = ReadPortFromPipe(named_pipe_path, out_port, 10);
|
||||||
error = name_pipe_file.Open(named_pipe_path, File::eOpenOptionRead);
|
|
||||||
if (error.Success())
|
if (error.Success())
|
||||||
{
|
{
|
||||||
char port_cstr[256];
|
if (log)
|
||||||
port_cstr[0] = '\0';
|
log->Printf("GDBRemoteCommunication::%s() debugserver listens %u port", __FUNCTION__, out_port);
|
||||||
size_t num_bytes = sizeof(port_cstr);
|
}
|
||||||
error = name_pipe_file.Read(port_cstr, num_bytes);
|
else
|
||||||
assert (error.Success());
|
{
|
||||||
assert (num_bytes > 0 && port_cstr[num_bytes-1] == '\0');
|
if (log)
|
||||||
out_port = Args::StringToUInt32(port_cstr, 0);
|
log->Printf("GDBRemoteCommunication::%s() failed to read a port value from named pipe %s: %s", __FUNCTION__, named_pipe_path, error.AsCString());
|
||||||
name_pipe_file.Close();
|
|
||||||
}
|
}
|
||||||
FileSystem::Unlink(named_pipe_path);
|
FileSystem::Unlink(named_pipe_path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue