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

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

Issue 50007: Better handling of startup and shutdown of the debugger agent (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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.cc ('k') | src/debug-agent.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 26 matching lines...) Expand all
37 // Forward decelrations. 37 // Forward decelrations.
38 class DebuggerAgentSession; 38 class DebuggerAgentSession;
39 39
40 40
41 // Debugger agent which starts a socket listener on the debugger port and 41 // Debugger agent which starts a socket listener on the debugger port and
42 // handles connection from a remote debugger. 42 // handles connection from a remote debugger.
43 class DebuggerAgent: public Thread { 43 class DebuggerAgent: public Thread {
44 public: 44 public:
45 explicit DebuggerAgent(int port) 45 explicit DebuggerAgent(int port)
46 : port_(port), server_(OS::CreateSocket()), terminate_(false), 46 : port_(port), server_(OS::CreateSocket()), terminate_(false),
47 session_access_(OS::CreateMutex()), session_(NULL) {} 47 session_access_(OS::CreateMutex()), session_(NULL),
48 ~DebuggerAgent() {} 48 terminate_now_(OS::CreateSemaphore(0)) {}
49 ~DebuggerAgent() { delete server_; }
49 50
50 void Shutdown(); 51 void Shutdown();
51 52
52 private: 53 private:
53 void Run(); 54 void Run();
54 void CreateSession(Socket* socket); 55 void CreateSession(Socket* socket);
55 void DebuggerMessage(const uint16_t* message, int length); 56 void DebuggerMessage(const uint16_t* message, int length);
56 void SessionClosed(DebuggerAgentSession* session); 57 void CloseSession();
58 void OnSessionClosed(DebuggerAgentSession* session);
57 59
58 int port_; // Port to use for the agent. 60 int port_; // Port to use for the agent.
59 Socket* server_; // Server socket for listen/accept. 61 Socket* server_; // Server socket for listen/accept.
60 bool terminate_; // Termination flag. 62 bool terminate_; // Termination flag.
61 Mutex* session_access_; // Mutex guarging access to session_. 63 Mutex* session_access_; // Mutex guarging access to session_.
62 DebuggerAgentSession* session_; // Current active session if any. 64 DebuggerAgentSession* session_; // Current active session if any.
65 Semaphore* terminate_now_; // Semaphore to signal termination.
63 66
64 friend class DebuggerAgentSession; 67 friend class DebuggerAgentSession;
65 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length, 68 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length,
66 void *data); 69 void *data);
67 70
68 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); 71 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent);
69 }; 72 };
70 73
71 74
72 // Debugger agent session. The session receives requests from the remote 75 // Debugger agent session. The session receives requests from the remote
73 // debugger and sends debugger events/responses to the remote debugger. 76 // debugger and sends debugger events/responses to the remote debugger.
74 class DebuggerAgentSession: public Thread { 77 class DebuggerAgentSession: public Thread {
75 public: 78 public:
76 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) 79 DebuggerAgentSession(DebuggerAgent* agent, Socket* client)
77 : agent_(agent), client_(client) {} 80 : agent_(agent), client_(client) {}
78 81
79 void DebuggerMessage(Vector<uint16_t> message); 82 void DebuggerMessage(Vector<uint16_t> message);
83 void Shutdown();
80 84
81 private: 85 private:
82 void Run(); 86 void Run();
83 87
84 void DebuggerMessage(Vector<char> message); 88 void DebuggerMessage(Vector<char> message);
85 89
86 DebuggerAgent* agent_; 90 DebuggerAgent* agent_;
87 const Socket* client_; 91 Socket* client_;
88 92
89 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession); 93 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession);
90 }; 94 };
91 95
92 96
93 // Utility methods factored out to be used by the D8 shell as well. 97 // Utility methods factored out to be used by the D8 shell as well.
94 class DebuggerAgentUtil { 98 class DebuggerAgentUtil {
95 public: 99 public:
96 static const char* kContentLength; 100 static const char* kContentLength;
97 static int kContentLengthSize; 101 static int kContentLengthSize;
98 102
99 static SmartPointer<char> ReceiveMessage(const Socket* conn); 103 static SmartPointer<char> ReceiveMessage(const Socket* conn);
100 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); 104 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message);
101 static bool SendMessage(const Socket* conn, 105 static bool SendMessage(const Socket* conn,
102 const v8::Handle<v8::String> message); 106 const v8::Handle<v8::String> message);
103 static int ReceiveAll(const Socket* conn, char* data, int len); 107 static int ReceiveAll(const Socket* conn, char* data, int len);
104 }; 108 };
105 109
106 110
107 } } // namespace v8::internal 111 } } // namespace v8::internal
108 112
109 #endif // V8_V8_DEBUG_AGENT_H_ 113 #endif // V8_V8_DEBUG_AGENT_H_
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/debug-agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698