From 101564176e170f639053f9ed8155d962cd8275c5 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Sat, 5 Sep 2015 15:39:17 -0700 Subject: Fix debugger/debuggee connection on OSx. The reason there were problems connecting on OS X was that the read on the debugger/debuggee pipe didn't return the full number of bytes requested on the first read. There are times (depending on the size of the read request) that multiple reads to be made to get all the bytes requested. This change adds code to retry the read or write until all the bytes requested are read or written. --- src/debug/debug-pal/unix/twowaypipe.cpp | 40 +++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/debug/debug-pal') diff --git a/src/debug/debug-pal/unix/twowaypipe.cpp b/src/debug/debug-pal/unix/twowaypipe.cpp index d97cc8ec4e..18881616f2 100644 --- a/src/debug/debug-pal/unix/twowaypipe.cpp +++ b/src/debug/debug-pal/unix/twowaypipe.cpp @@ -123,18 +123,54 @@ bool TwoWayPipe::WaitForConnection() // Reads data from pipe. Returns number of bytes read or a negative number in case of an error. // use GetLastError() for more details +// UNIXTODO - mjm 9/6/15 - does not set last error on failure int TwoWayPipe::Read(void *buffer, DWORD bufferSize) { _ASSERTE(m_state == ServerConnected || m_state == ClientConnected); - return (int)read(m_inboundPipe, buffer, bufferSize); + + int totalBytesRead = 0; + int bytesRead; + int cb = bufferSize; + + while ((bytesRead = (int)read(m_inboundPipe, buffer, cb)) > 0) + { + totalBytesRead += bytesRead; + _ASSERTE(totalBytesRead <= bufferSize); + if (totalBytesRead >= bufferSize) + { + break; + } + buffer = (char*)buffer + bytesRead; + cb -= bytesRead; + } + + return bytesRead == -1 ? -1 : totalBytesRead; } // Writes data to pipe. Returns number of bytes written or a negative number in case of an error. // use GetLastError() for more details +// UNIXTODO - mjm 9/6/15 - does not set last error on failure int TwoWayPipe::Write(const void *data, DWORD dataSize) { _ASSERTE(m_state == ServerConnected || m_state == ClientConnected); - return (int)write(m_outboundPipe, data, dataSize); + + int totalBytesWritten = 0; + int bytesWritten; + int cb = dataSize; + + while ((bytesWritten = (int)write(m_outboundPipe, data, cb)) > 0) + { + totalBytesWritten += bytesWritten; + _ASSERTE(totalBytesWritten <= dataSize); + if (totalBytesWritten >= dataSize) + { + break; + } + data = (char*)data + bytesWritten; + cb -= bytesWritten; + } + + return bytesWritten == -1 ? -1 : totalBytesWritten; } // Disconnect server or client side of the pipe. -- cgit v1.2.3