diff options
author | Mike McLaughlin <mikem@microsoft.com> | 2015-09-05 15:39:17 -0700 |
---|---|---|
committer | Mike McLaughlin <mikem@microsoft.com> | 2015-09-07 10:22:41 -0700 |
commit | 101564176e170f639053f9ed8155d962cd8275c5 (patch) | |
tree | dce928044749bdfacce5fdab0204ed5609966e87 /src | |
parent | 248e8e447409274392ff284e58dfc2202fa0a15f (diff) | |
download | coreclr-101564176e170f639053f9ed8155d962cd8275c5.tar.gz coreclr-101564176e170f639053f9ed8155d962cd8275c5.tar.bz2 coreclr-101564176e170f639053f9ed8155d962cd8275c5.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/debug/debug-pal/unix/twowaypipe.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
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. |