1 /*
2 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
210 }
211 }
212
213 /* Command reader */
214 static void JNICALL
215 reader(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
216 {
217 jdwpPacket packet;
218 jdwpCmdPacket *cmd;
219 jboolean shouldListen = JNI_TRUE;
220
221 LOG_MISC(("Begin reader thread"));
222
223 while (shouldListen) {
224 jint rc;
225
226 rc = transport_receivePacket(&packet);
227
228 /* I/O error or EOF */
229 if (rc != 0 || (rc == 0 && packet.type.cmd.len == 0)) {
230 shouldListen = JNI_FALSE;
231 notifyTransportError();
232 } else {
233 cmd = &packet.type.cmd;
234
235 LOG_MISC(("Command set %d, command %d", cmd->cmdSet, cmd->cmd));
236
237 /*
238 * FIXME! We need to deal with high priority
239 * packets and queue flushes!
240 */
241 enqueue(&packet);
242
243 shouldListen = !lastCommand(cmd);
244 }
245 }
246 LOG_MISC(("End reader thread"));
247 }
248
249 /*
|
1 /*
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
210 }
211 }
212
213 /* Command reader */
214 static void JNICALL
215 reader(jvmtiEnv* jvmti_env, JNIEnv* jni_env, void* arg)
216 {
217 jdwpPacket packet;
218 jdwpCmdPacket *cmd;
219 jboolean shouldListen = JNI_TRUE;
220
221 LOG_MISC(("Begin reader thread"));
222
223 while (shouldListen) {
224 jint rc;
225
226 rc = transport_receivePacket(&packet);
227
228 /* I/O error or EOF */
229 if (rc != 0 || (rc == 0 && packet.type.cmd.len == 0)) {
230 shouldListen = JNI_FALSE;
231 notifyTransportError();
232 } else if (packet.type.cmd.flags != JDWPTRANSPORT_FLAGS_NONE) {
233 /*
234 * Close the connection when we get a jdwpCmdPacket with an
235 * invalid flags field value. This is a protocol violation
236 * so we drop the connection. Also this could be a web
237 * browser generating an HTTP request that passes the JDWP
238 * handshake. HTTP requests requires that everything be in
239 * the ASCII printable range so a flags value of
240 * JDWPTRANSPORT_FLAGS_NONE(0) cannot be generated via HTTP.
241 */
242 ERROR_MESSAGE(("Received jdwpPacket with flags != 0x%d (actual=0x%x) when a jdwpCmdPacket was expected.",
243 JDWPTRANSPORT_FLAGS_NONE, packet.type.cmd.flags));
244 shouldListen = JNI_FALSE;
245 notifyTransportError();
246 } else {
247 cmd = &packet.type.cmd;
248
249 LOG_MISC(("Command set %d, command %d", cmd->cmdSet, cmd->cmd));
250
251 /*
252 * FIXME! We need to deal with high priority
253 * packets and queue flushes!
254 */
255 enqueue(&packet);
256
257 shouldListen = !lastCommand(cmd);
258 }
259 }
260 LOG_MISC(("End reader thread"));
261 }
262
263 /*
|