Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1129)

Unified Diff: chrome/browser/debugger/devtools_remote_listen_socket.cc

Issue 150229: Handle partial sends over the ChromeDevToolsProtocol (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/debugger/devtools_remote_listen_socket.cc
===================================================================
--- chrome/browser/debugger/devtools_remote_listen_socket.cc (revision 19109)
+++ chrome/browser/debugger/devtools_remote_listen_socket.cc (working copy)
@@ -245,20 +245,33 @@
}
void DevToolsRemoteListenSocket::SendInternal(const char* bytes, int len) {
- int sent = HANDLE_EINTR(send(socket_, bytes, len, 0));
- if (sent == kSocketError) {
+ char* send_buf = const_cast<char *>(bytes);
+ int len_left = len;
+ while (true) {
+ int sent = HANDLE_EINTR(send(socket_, send_buf, len_left, 0));
+ if (sent == len_left) { // A shortcut to avoid extraneous checks.
+ break;
+ }
+ if (sent == kSocketError) {
#if defined(OS_WIN)
- while (WSAGetLastError() == WSAEWOULDBLOCK) {
+ if (WSAGetLastError() != WSAEWOULDBLOCK) {
+ LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError();
#elif defined(OS_POSIX)
- while (errno == EWOULDBLOCK || errno == EAGAIN) {
+ if (errno != EWOULDBLOCK && errno != EAGAIN) {
+ LOG(ERROR) << "send failed: errno==" << errno;
#endif
- PlatformThread::YieldCurrentThread();
- sent = HANDLE_EINTR(send(socket_, bytes, len, 0));
+ break;
+ }
+ // Otherwise we would block, and now we have to wait for a retry.
+ // Fall through to PlatformThread::YieldCurrentThread()
+ } else {
+ // sent != len_left according to the shortcut above.
+ // Shift the buffer start and send the remainder after a short while.
+ send_buf += sent;
+ len_left -= sent;
}
+ PlatformThread::YieldCurrentThread();
}
- if (sent != len) {
- LOG(ERROR) << "send failed: ";
- }
}
void DevToolsRemoteListenSocket::Close() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698