1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)attachListener_linux.cpp 1.14 07/05/05 17:04:34 JVM"
3 #endif
4 /*
5 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
218 return 0;
219 }
220
221 // Given a socket that is connected to a peer we read the request and
222 // create an AttachOperation. As the socket is blocking there is potential
223 // for a denial-of-service if the peer does not response. However this happens
224 // after the peer credentials have been checked and in the worst case it just
225 // means that the attach listener thread is blocked.
226 //
227 LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
228 char ver_str[8];
229 sprintf(ver_str, "%d", ATTACH_PROTOCOL_VER);
230
231 // The request is a sequence of strings so we first figure out the
232 // expected count and the maximum possible length of the request.
233 // The request is:
234 // <ver>0<cmd>0<arg>0<arg>0<arg>0
235 // where <ver> is the protocol version (1), <cmd> is the command
236 // name ("load", "datadump", ...), and <arg> is an argument
237 int expected_str_count = 2 + AttachOperation::arg_count_max;
238 int max_len = (strlen(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
239 AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
240
241 char buf[max_len];
242 int str_count = 0;
243
244 // Read until all (expected) strings have been read, the buffer is
245 // full, or EOF.
246
247 int off = 0;
248 int left = max_len;
249
250 do {
251 int n;
252 RESTARTABLE(read(s, buf+off, left), n);
253 if (n == -1) {
254 return NULL; // reset by peer or other error
255 }
256 if (n == 0) {
257 break;
258 }
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)attachListener_linux.cpp 1.14 07/05/05 17:04:34 JVM"
3 #endif
4 /*
5 * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
218 return 0;
219 }
220
221 // Given a socket that is connected to a peer we read the request and
222 // create an AttachOperation. As the socket is blocking there is potential
223 // for a denial-of-service if the peer does not response. However this happens
224 // after the peer credentials have been checked and in the worst case it just
225 // means that the attach listener thread is blocked.
226 //
227 LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
228 char ver_str[8];
229 sprintf(ver_str, "%d", ATTACH_PROTOCOL_VER);
230
231 // The request is a sequence of strings so we first figure out the
232 // expected count and the maximum possible length of the request.
233 // The request is:
234 // <ver>0<cmd>0<arg>0<arg>0<arg>0
235 // where <ver> is the protocol version (1), <cmd> is the command
236 // name ("load", "datadump", ...), and <arg> is an argument
237 int expected_str_count = 2 + AttachOperation::arg_count_max;
238 const int max_len = (sizeof(ver_str) + 1) + (AttachOperation::name_length_max + 1) +
239 AttachOperation::arg_count_max*(AttachOperation::arg_length_max + 1);
240
241 char buf[max_len];
242 int str_count = 0;
243
244 // Read until all (expected) strings have been read, the buffer is
245 // full, or EOF.
246
247 int off = 0;
248 int left = max_len;
249
250 do {
251 int n;
252 RESTARTABLE(read(s, buf+off, left), n);
253 if (n == -1) {
254 return NULL; // reset by peer or other error
255 }
256 if (n == 0) {
257 break;
258 }
|