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

Side by Side Diff: src/debug-agent.cc

Issue 10412021: Make socket send and receive more robust and return 0 on failure. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
Jakob Kummerow 2012/05/21 09:56:13 nit: 2012 :-)
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 const int kHeaderBufferSize = 80; 240 const int kHeaderBufferSize = 80;
241 char header_buffer[kHeaderBufferSize]; 241 char header_buffer[kHeaderBufferSize];
242 int header_buffer_position = 0; 242 int header_buffer_position = 0;
243 char c = '\0'; // One character receive buffer. 243 char c = '\0'; // One character receive buffer.
244 char prev_c = '\0'; // Previous character. 244 char prev_c = '\0'; // Previous character.
245 245
246 // Read until CRLF. 246 // Read until CRLF.
247 while (!(c == '\n' && prev_c == '\r')) { 247 while (!(c == '\n' && prev_c == '\r')) {
248 prev_c = c; 248 prev_c = c;
249 received = conn->Receive(&c, 1); 249 received = conn->Receive(&c, 1);
250 if (received <= 0) { 250 if (received == 0) {
251 PrintF("Error %d\n", Socket::LastError()); 251 PrintF("Error %d\n", Socket::LastError());
252 return SmartArrayPointer<char>(); 252 return SmartArrayPointer<char>();
253 } 253 }
254 254
255 // Add character to header buffer. 255 // Add character to header buffer.
256 if (header_buffer_position < kHeaderBufferSize) { 256 if (header_buffer_position < kHeaderBufferSize) {
257 header_buffer[header_buffer_position++] = c; 257 header_buffer[header_buffer_position++] = c;
258 } 258 }
259 } 259 }
260 260
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 447
448 return true; 448 return true;
449 } 449 }
450 450
451 451
452 // Receive the full buffer before returning unless an error occours. 452 // Receive the full buffer before returning unless an error occours.
453 int DebuggerAgentUtil::ReceiveAll(const Socket* conn, char* data, int len) { 453 int DebuggerAgentUtil::ReceiveAll(const Socket* conn, char* data, int len) {
454 int total_received = 0; 454 int total_received = 0;
455 while (total_received < len) { 455 while (total_received < len) {
456 int received = conn->Receive(data + total_received, len - total_received); 456 int received = conn->Receive(data + total_received, len - total_received);
457 if (received <= 0) { 457 if (received == 0) {
458 return total_received; 458 return total_received;
459 } 459 }
460 total_received += received; 460 total_received += received;
461 } 461 }
462 return total_received; 462 return total_received;
463 } 463 }
464 464
465 } } // namespace v8::internal 465 } } // namespace v8::internal
466 466
467 #endif // ENABLE_DEBUGGER_SUPPORT 467 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« no previous file with comments | « no previous file | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698