/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4636628
* @summary HttpURLConnection duplicates HTTP GET requests when used with multiple threads
*/
/*
* This tests keep-alive behavior using chunkedinputstreams
* It checks that keep-alive connections are used and also
* that requests are not being repeated (due to errors)
*
* It also checks that the keepalive connections are closed eventually
* because the test will not terminate if the connections
* are not closed by the keep-alive timer.
*/
/*
* Is debugging enabled - start with -d to enable.
*/
static boolean debug = false;
if (debug)
}
reqnum ++;
byte b[] = new byte[100];
int total = 0;
int n;
do {
if (n > 0) total += n;
} while (n > 0);
http.disconnect();
}
byte[] b;
int requests;
uri = "http://localhost:" +
b = new byte [256];
synchronized (threadlock) {
threadCounter ++;
}
}
public void run () {
try {
for (int i=0; i<requests; i++) {
}
} catch (Exception e) {
throw new RuntimeException (e.getMessage());
} finally {
synchronized (threadlock) {
threadCounter --;
if (threadCounter == 0) {
}
}
}
}
int requests = 20;
debug = true;
x = 1;
arg_len --;
}
if (arg_len > 0) {
}
/* start the server */
synchronized (lock) {
for (int i=0; i<threads; i++) {
t.start ();
}
try {
} catch (InterruptedException e) {}
}
// shutdown server - we're done.
}
}
}
}
/*
* Server thread to accept connection and create worker threads
* to service each connection.
*/
int connectionCount;
boolean shutdown = false;
}
public synchronized int connectionCount() {
return connectionCount;
}
public synchronized void shutdown() {
shutdown = true;
}
public void run() {
try {
for (;;) {
Socket s;
try {
} catch (SocketTimeoutException te) {
synchronized (this) {
if (shutdown) {
return;
}
}
continue;
}
int id;
synchronized (this) {
id = connectionCount++;
}
w.start();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
} catch (Exception e) { }
}
}
}
/*
* Worker thread to service single connection - can service
* multiple http requests on same connection.
*/
Socket s;
int id;
this.s = s;
}
public static int getRequests () {
synchronized (rlock) {
return requests;
}
}
public static void incRequests () {
synchronized (rlock) {
requests++;
}
}
while (true) {
if (c == -1)
return -1;
count++;
if (c == seq[i]) {
i++;
return count;
continue;
} else {
i = 0;
}
}
}
public void run() {
try {
int max = 400;
byte b[] = new byte[1000];
// response to client
new BufferedOutputStream(
s.getOutputStream() ));
for (;;) {
// read entire request from client
int n=0;
if (n <= 0) {
s.close();
return;
}
": Read request from client " +
"(" + n + " bytes).");
incRequests();
if (--max == 0) {
s.close();
return;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
s.close();
} catch (Exception e) { }
}
}
}