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

Side by Side Diff: runtime/bin/dbg_connection_win.cc

Issue 1497033003: - Remove the legacy debug protocol. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS)
7
8 #include "bin/dbg_connection.h"
9
10 #include "bin/eventhandler.h"
11 #include "bin/lockers.h"
12 #include "bin/log.h"
13 #include "bin/thread.h"
14
15 namespace dart {
16 namespace bin {
17
18 Monitor* DebuggerConnectionImpl::handler_monitor_ = new Monitor();
19 ThreadId DebuggerConnectionImpl::handler_thread_id_ = Thread::kInvalidThreadId;
20 bool DebuggerConnectionImpl::handler_thread_running_ = false;
21
22
23 void DebuggerConnectionImpl::NotifyThreadStarted() {
24 MonitorLocker ml(handler_monitor_);
25 ASSERT(!handler_thread_running_);
26 ASSERT(handler_thread_id_ == Thread::kInvalidThreadId);
27 handler_thread_running_ = true;
28 handler_thread_id_ = Thread::GetCurrentThreadId();
29 ml.Notify();
30 }
31
32
33 void DebuggerConnectionImpl::WaitForThreadStarted() {
34 MonitorLocker ml(handler_monitor_);
35 while (!handler_thread_running_) {
36 ml.Wait();
37 }
38 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
39 }
40
41
42 void DebuggerConnectionImpl::NotifyThreadFinished() {
43 MonitorLocker ml(handler_monitor_);
44 ASSERT(handler_thread_running_);
45 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
46 handler_thread_running_ = false;
47 ml.Notify();
48 }
49
50
51 void DebuggerConnectionImpl::WaitForThreadFinished() {
52 MonitorLocker ml(handler_monitor_);
53 while (handler_thread_running_) {
54 ml.Wait();
55 }
56 ASSERT(handler_thread_id_ != Thread::kInvalidThreadId);
57 Thread::Join(handler_thread_id_);
58 handler_thread_id_ = Thread::kInvalidThreadId;
59 }
60
61
62 void DebuggerConnectionImpl::ThreadEntry(uword args) {
63 NotifyThreadStarted();
64 ListenSocket* listen_socket =
65 reinterpret_cast<ListenSocket*>(DebuggerConnectionHandler::listener_fd_);
66 SOCKET client_socket = accept(listen_socket->socket(), NULL, NULL);
67 if (client_socket == INVALID_SOCKET) {
68 FATAL("Accepting new debugger connection failed.\n");
69 }
70 ClientSocket* socket = new ClientSocket(client_socket);
71 DebuggerConnectionHandler::AcceptDbgConnection(
72 reinterpret_cast<intptr_t>(socket));
73 NotifyThreadFinished();
74 }
75
76
77 void DebuggerConnectionImpl::StartHandler(int port_number) {
78 ASSERT(DebuggerConnectionHandler::listener_fd_ != -1);
79 int result = Thread::Start(&DebuggerConnectionImpl::ThreadEntry, 0);
80 if (result != 0) {
81 FATAL1("Failed to start debugger connection handler thread: %d\n", result);
82 }
83 WaitForThreadStarted();
84 }
85
86
87 void DebuggerConnectionImpl::StopHandler(intptr_t debug_fd) {
88 Send(debug_fd, NULL, 0);
89 WaitForThreadFinished();
90 }
91
92
93 intptr_t DebuggerConnectionImpl::Send(intptr_t socket,
94 const char* buf,
95 int len) {
96 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket);
97 return send(client_socket->socket(), buf, len, 0);
98 }
99
100
101 intptr_t DebuggerConnectionImpl::Receive(intptr_t socket, char* buf, int len) {
102 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(socket);
103 return recv(client_socket->socket(), buf, len, 0);
104 }
105
106 } // namespace bin
107 } // namespace dart
108
109 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/dbg_connection_win.h ('k') | runtime/bin/dbg_message.h » ('j') | runtime/bin/main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698