| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // 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 |
| 59 // make the agent take over the port when it becomes free. | 59 // make the agent take over the port when it becomes free. |
| 60 if (!bound) { | 60 if (!bound) { |
| 61 terminate_now_->Wait(kOneSecondInMicros); | 61 terminate_now_->Wait(kOneSecondInMicros); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Accept connections on the bound port. | 65 // Accept connections on the bound port. |
| 66 while (!terminate_) { | 66 while (!terminate_) { |
| 67 bool ok = server_->Listen(1); | 67 bool ok = server_->Listen(1); |
| 68 listening_->Signal(); |
| 68 if (ok) { | 69 if (ok) { |
| 69 // Accept the new connection. | 70 // Accept the new connection. |
| 70 Socket* client = server_->Accept(); | 71 Socket* client = server_->Accept(); |
| 71 ok = client != NULL; | 72 ok = client != NULL; |
| 72 if (ok) { | 73 if (ok) { |
| 73 // Create and start a new session. | 74 // Create and start a new session. |
| 74 CreateSession(client); | 75 CreateSession(client); |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 | 81 |
| 81 void DebuggerAgent::Shutdown() { | 82 void DebuggerAgent::Shutdown() { |
| 82 // Set the termination flag. | 83 // Set the termination flag. |
| 83 terminate_ = true; | 84 terminate_ = true; |
| 84 | 85 |
| 85 // Signal termination and make the server exit either its listen call or its | 86 // Signal termination and make the server exit either its listen call or its |
| 86 // binding loop. This makes sure that no new sessions can be established. | 87 // binding loop. This makes sure that no new sessions can be established. |
| 87 terminate_now_->Signal(); | 88 terminate_now_->Signal(); |
| 88 server_->Shutdown(); | 89 server_->Shutdown(); |
| 89 Join(); | 90 Join(); |
| 90 | 91 |
| 91 // Close existing session if any. | 92 // Close existing session if any. |
| 92 CloseSession(); | 93 CloseSession(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 | 96 |
| 97 void DebuggerAgent::WaitUntilListening() { |
| 98 listening_->Wait(); |
| 99 } |
| 100 |
| 96 void DebuggerAgent::CreateSession(Socket* client) { | 101 void DebuggerAgent::CreateSession(Socket* client) { |
| 97 ScopedLock with(session_access_); | 102 ScopedLock with(session_access_); |
| 98 | 103 |
| 99 // If another session is already established terminate this one. | 104 // If another session is already established terminate this one. |
| 100 if (session_ != NULL) { | 105 if (session_ != NULL) { |
| 101 static const char* message = "Remote debugging session already active\r\n"; | 106 static const char* message = "Remote debugging session already active\r\n"; |
| 102 | 107 |
| 103 client->Send(message, strlen(message)); | 108 client->Send(message, strlen(message)); |
| 104 delete client; | 109 delete client; |
| 105 return; | 110 return; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 return total_received; | 414 return total_received; |
| 410 } | 415 } |
| 411 total_received += received; | 416 total_received += received; |
| 412 } | 417 } |
| 413 return total_received; | 418 return total_received; |
| 414 } | 419 } |
| 415 | 420 |
| 416 } } // namespace v8::internal | 421 } } // namespace v8::internal |
| 417 | 422 |
| 418 #endif // ENABLE_DEBUGGER_SUPPORT | 423 #endif // ENABLE_DEBUGGER_SUPPORT |
| OLD | NEW |