annotate agent/src/os/win32/serverLists.hpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #ifndef _SERVER_LISTS_
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #define _SERVER_LISTS_
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #include <vector>
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #include <winsock2.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #include "IOBuf.hpp"
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 //
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // NOTE:
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // All of these lists are guarded by the global lock managed by the
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Lists class. Lists::init() must be called at the start of the
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // program.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class Lists {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 friend class ListsLocker;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 static void init();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
45 static void lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static void unlock();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static CRITICAL_SECTION crit;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 };
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Should be allocated on stack. Ensures proper locking/unlocking
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // pairing.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 class ListsLocker {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ListsLocker();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 ~ListsLocker();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 };
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // We must keep track of all of the child processes we have forked to
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // handle attaching to a target process. This is necessary because we
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // allow clients to detach from processes, but the child processes we
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // fork must necessarily stay alive for the duration of the target
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // application. A subsequent attach operation to the target process
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // results in the same child process being reused. For this reason,
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // child processes are known to be in one of two states: attached and
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // detached.
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 class ClientInfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 class ChildInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
71 /** The pid of the ChildInfo indicates the process ID of the target
a61af66fc99e Initial load
duke
parents:
diff changeset
72 process which the subprocess was created to debug, not the pid
a61af66fc99e Initial load
duke
parents:
diff changeset
73 of the subprocess itself. */
a61af66fc99e Initial load
duke
parents:
diff changeset
74 ChildInfo(DWORD pid, HANDLE childProcessHandle,
a61af66fc99e Initial load
duke
parents:
diff changeset
75 HANDLE writeToStdinHandle, HANDLE readFromStdoutHandle,
a61af66fc99e Initial load
duke
parents:
diff changeset
76 HANDLE auxHandle1, HANDLE auxHandle2);
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 DWORD getPid();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 HANDLE getChildProcessHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 HANDLE getWriteToStdinHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 HANDLE getReadFromStdoutHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 /** Set the client which is currently attached to the target process
a61af66fc99e Initial load
duke
parents:
diff changeset
84 via this child process. Set this to NULL to indicate that the
a61af66fc99e Initial load
duke
parents:
diff changeset
85 child process is ready to accept another attachment. */
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void setClient(ClientInfo* clientInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 ClientInfo* getClient();
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 /** This is NOT automatically called in the destructor */
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void closeAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
94 DWORD pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 HANDLE childProcessHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 HANDLE writeToStdinHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 HANDLE readFromStdoutHandle;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 HANDLE auxHandle1;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 HANDLE auxHandle2;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ClientInfo* client;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 };
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // We keep track of a list of child debugger processes, each of which
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // is responsible for debugging a certain target process. These
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // debugger processes can serve multiple clients during their
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // lifetime. When a client detaches from a given process or tells the
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // debugger to "exit", the debug server is notified that the child
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // process is once again available to accept connections from clients.
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 class ChildList {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
112 typedef std::vector<ChildInfo*> ChildInfoList;
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ChildList();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ~ChildList();
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void addChild(ChildInfo*);
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 /** Removes and returns the ChildInfo* associated with the given
a61af66fc99e Initial load
duke
parents:
diff changeset
121 child process handle. */
a61af66fc99e Initial load
duke
parents:
diff changeset
122 ChildInfo* removeChild(HANDLE childProcessHandle);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 /** Removes the given ChildInfo. */
a61af66fc99e Initial load
duke
parents:
diff changeset
125 void removeChild(ChildInfo* info);
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 /** Return the ChildInfo* associated with a given process ID without
a61af66fc99e Initial load
duke
parents:
diff changeset
128 removing it from the list. */
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ChildInfo* getChildByPid(DWORD pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 /** Iteration support */
a61af66fc99e Initial load
duke
parents:
diff changeset
132 int size();
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 /** Iteration support */
a61af66fc99e Initial load
duke
parents:
diff changeset
135 ChildInfo* getChildByIndex(int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
138 ChildInfoList childList;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 };
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // We also keep a list of clients whose requests we are responsible
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // for serving. Clients can attach and detach from child processes.
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 class ClientInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
146 ClientInfo(SOCKET dataSocket);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 ~ClientInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 SOCKET getDataSocket();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 /** Gets an IOBuf configured for the data socket, which should be
a61af66fc99e Initial load
duke
parents:
diff changeset
151 used for all communication with the client. */
a61af66fc99e Initial load
duke
parents:
diff changeset
152 IOBuf* getIOBuf();
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 /** Set the information for the process to which this client is
a61af66fc99e Initial load
duke
parents:
diff changeset
155 attached. Set this to NULL to indicate that the client is not
a61af66fc99e Initial load
duke
parents:
diff changeset
156 currently attached to any target process. */
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void setTarget(ChildInfo* childInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 /** Get the information for the process to which this client is
a61af66fc99e Initial load
duke
parents:
diff changeset
160 currently attached, or NULL if none. */
a61af66fc99e Initial load
duke
parents:
diff changeset
161 ChildInfo* getTarget();
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 /** Close down the socket connection to this client. This is NOT
a61af66fc99e Initial load
duke
parents:
diff changeset
164 automatically called by the destructor. */
a61af66fc99e Initial load
duke
parents:
diff changeset
165 void closeAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
168 SOCKET dataSocket;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 IOBuf* buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 ChildInfo* target;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 };
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 class ClientList {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
175 typedef std::vector<ClientInfo*> ClientInfoList;
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
178 ClientList();
a61af66fc99e Initial load
duke
parents:
diff changeset
179 ~ClientList();
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 /** Adds a client to the list. */
a61af66fc99e Initial load
duke
parents:
diff changeset
182 void addClient(ClientInfo* info);
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 /** Check to see whether the parent socket of any of the ClientInfo
a61af66fc99e Initial load
duke
parents:
diff changeset
185 objects is readable in the given fd_set. If so, returns TRUE and
a61af66fc99e Initial load
duke
parents:
diff changeset
186 sets the given ClientInfo* (a non-NULL pointer to which must be
a61af66fc99e Initial load
duke
parents:
diff changeset
187 given) appropriately. */
a61af66fc99e Initial load
duke
parents:
diff changeset
188 bool isAnyDataSocketSet(fd_set* fds, ClientInfo** info);
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 /** Removes a client from the list. User is responsible for deleting
a61af66fc99e Initial load
duke
parents:
diff changeset
191 the ClientInfo* using operator delete. */
a61af66fc99e Initial load
duke
parents:
diff changeset
192 void removeClient(ClientInfo* client);
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 /** Iteration support. */
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int size();
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 /** Iteration support. */
a61af66fc99e Initial load
duke
parents:
diff changeset
198 ClientInfo* get(int num);
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
201 ClientInfoList clientList;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 };
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 #endif // #defined _SERVER_LISTS_