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

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

Issue 23748003: Cleanup Semaphore class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Build fix for Mac OS X. Created 7 years, 3 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 | « src/debug-agent.h ('k') | src/isolate.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
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
(...skipping 28 matching lines...) Expand all
39 // to the debugger agent through it's data parameter. 39 // to the debugger agent through it's data parameter.
40 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) { 40 void DebuggerAgentMessageHandler(const v8::Debug::Message& message) {
41 DebuggerAgent* agent = Isolate::Current()->debugger_agent_instance(); 41 DebuggerAgent* agent = Isolate::Current()->debugger_agent_instance();
42 ASSERT(agent != NULL); 42 ASSERT(agent != NULL);
43 agent->DebuggerMessage(message); 43 agent->DebuggerMessage(message);
44 } 44 }
45 45
46 46
47 // Debugger agent main thread. 47 // Debugger agent main thread.
48 void DebuggerAgent::Run() { 48 void DebuggerAgent::Run() {
49 const int kOneSecondInMicros = 1000000;
50
51 // Allow this socket to reuse port even if still in TIME_WAIT. 49 // Allow this socket to reuse port even if still in TIME_WAIT.
52 server_->SetReuseAddress(true); 50 server_->SetReuseAddress(true);
53 51
54 // First bind the socket to the requested port. 52 // First bind the socket to the requested port.
55 bool bound = false; 53 bool bound = false;
56 while (!bound && !terminate_) { 54 while (!bound && !terminate_) {
57 bound = server_->Bind(port_); 55 bound = server_->Bind(port_);
58 56
59 // If an error occurred wait a bit before retrying. The most common error 57 // If an error occurred wait a bit before retrying. The most common error
60 // would be that the port is already in use so this avoids a busy loop and 58 // would be that the port is already in use so this avoids a busy loop and
61 // make the agent take over the port when it becomes free. 59 // make the agent take over the port when it becomes free.
62 if (!bound) { 60 if (!bound) {
61 const TimeDelta kTimeout = TimeDelta::FromSeconds(1);
63 PrintF("Failed to open socket on port %d, " 62 PrintF("Failed to open socket on port %d, "
64 "waiting %d ms before retrying\n", port_, kOneSecondInMicros / 1000); 63 "waiting %d ms before retrying\n", port_,
65 terminate_now_->Wait(kOneSecondInMicros); 64 static_cast<int>(kTimeout.InMilliseconds()));
65 if (!terminate_now_.WaitFor(kTimeout)) {
66 if (terminate_) return;
67 }
66 } 68 }
67 } 69 }
68 70
69 // Accept connections on the bound port. 71 // Accept connections on the bound port.
70 while (!terminate_) { 72 while (!terminate_) {
71 bool ok = server_->Listen(1); 73 bool ok = server_->Listen(1);
72 listening_->Signal(); 74 listening_.Signal();
73 if (ok) { 75 if (ok) {
74 // Accept the new connection. 76 // Accept the new connection.
75 Socket* client = server_->Accept(); 77 Socket* client = server_->Accept();
76 ok = client != NULL; 78 ok = client != NULL;
77 if (ok) { 79 if (ok) {
78 // Create and start a new session. 80 // Create and start a new session.
79 CreateSession(client); 81 CreateSession(client);
80 } 82 }
81 } 83 }
82 } 84 }
83 } 85 }
84 86
85 87
86 void DebuggerAgent::Shutdown() { 88 void DebuggerAgent::Shutdown() {
87 // Set the termination flag. 89 // Set the termination flag.
88 terminate_ = true; 90 terminate_ = true;
89 91
90 // Signal termination and make the server exit either its listen call or its 92 // Signal termination and make the server exit either its listen call or its
91 // binding loop. This makes sure that no new sessions can be established. 93 // binding loop. This makes sure that no new sessions can be established.
92 terminate_now_->Signal(); 94 terminate_now_.Signal();
93 server_->Shutdown(); 95 server_->Shutdown();
94 Join(); 96 Join();
95 97
96 // Close existing session if any. 98 // Close existing session if any.
97 CloseSession(); 99 CloseSession();
98 } 100 }
99 101
100 102
101 void DebuggerAgent::WaitUntilListening() { 103 void DebuggerAgent::WaitUntilListening() {
102 listening_->Wait(); 104 listening_.Wait();
103 } 105 }
104 106
105 static const char* kCreateSessionMessage = 107 static const char* kCreateSessionMessage =
106 "Remote debugging session already active\r\n"; 108 "Remote debugging session already active\r\n";
107 109
108 void DebuggerAgent::CreateSession(Socket* client) { 110 void DebuggerAgent::CreateSession(Socket* client) {
109 LockGuard<RecursiveMutex> session_access_guard(&session_access_); 111 LockGuard<RecursiveMutex> session_access_guard(&session_access_);
110 112
111 // If another session is already established terminate this one. 113 // If another session is already established terminate this one.
112 if (session_ != NULL) { 114 if (session_ != NULL) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 return total_received; 455 return total_received;
454 } 456 }
455 total_received += received; 457 total_received += received;
456 } 458 }
457 return total_received; 459 return total_received;
458 } 460 }
459 461
460 } } // namespace v8::internal 462 } } // namespace v8::internal
461 463
462 #endif // ENABLE_DEBUGGER_SUPPORT 464 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« no previous file with comments | « src/debug-agent.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698