You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2012/11/25 11:55:55 UTC
svn commit: r1413328 - in /tomcat/trunk:
java/org/apache/coyote/http11/upgrade/ test/org/apache/coyote/http11/upgrade/
Author: kkolinko
Date: Sun Nov 25 10:55:52 2012
New Revision: 1413328
URL: http://svn.apache.org/viewvc?rev=1413328&view=rev
Log:
svn:eol-style = native
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java (contents, props changed)
tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java (contents, props changed)
tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java (contents, props changed)
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java Sun Nov 25 10:55:52 2012
@@ -1,157 +1,157 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-
-import javax.servlet.ReadListener;
-import javax.servlet.ServletInputStream;
-
-import org.apache.tomcat.util.res.StringManager;
-
-public abstract class AbstractServletInputStream extends ServletInputStream {
-
- protected static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
-
- // Start in blocking-mode
- private volatile Boolean ready = Boolean.TRUE;
- private volatile ReadListener listener = null;
-
-
- @Override
- public final boolean isFinished() {
- if (listener == null) {
- throw new IllegalStateException(
- sm.getString("upgrade.sis.isFinished.ise"));
- }
- // The only way to finish an HTTP Upgrade connection is to close the
- // socket.
- return false;
- }
-
-
- @Override
- public final boolean isReady() {
- if (listener == null) {
- throw new IllegalStateException(
- sm.getString("upgrade.sis.isReady.ise"));
- }
-
- // If we already know the current state, return it.
- if (ready != null) {
- return ready.booleanValue();
- }
-
- try {
- ready = Boolean.valueOf(doIsReady());
- } catch (IOException e) {
- listener.onError(e);
- }
- return ready.booleanValue();
- }
-
-
- @Override
- public final void setReadListener(ReadListener listener) {
- if (listener == null) {
- throw new IllegalArgumentException(
- sm.getString("upgrade.sis.readListener.null"));
- }
- this.listener = listener;
- // Switching to non-blocking. Don't know if data is available.
- ready = null;
- }
-
-
- @Override
- public final int read() throws IOException {
- preReadChecks();
-
- return readInternal();
- }
-
-
- @Override
- public final int readLine(byte[] b, int off, int len) throws IOException {
- preReadChecks();
-
- if (len <= 0) {
- return 0;
- }
- int count = 0, c;
-
- while ((c = readInternal()) != -1) {
- b[off++] = (byte) c;
- count++;
- if (c == '\n' || count == len) {
- break;
- }
- }
- return count > 0 ? count : -1;
- }
-
-
- @Override
- public final int read(byte[] b, int off, int len) throws IOException {
- preReadChecks();
-
- return doRead(listener == null, b, off, len);
- }
-
-
- private void preReadChecks() {
- if (listener != null && (ready == null || !ready.booleanValue())) {
- throw new IllegalStateException(
- sm.getString("upgrade.sis.read.ise"));
- }
- // No longer know if data is available
- ready = null;
- }
-
-
- private int readInternal() throws IOException {
- // Single byte reads for non-blocking need special handling so all
- // single byte reads run through this method.
- ReadListener readListener = this.listener;
- byte[] b = new byte[1];
- int result = doRead(readListener == null, b, 0, 1);
- if (result == 0) {
- return -1;
- } else if (result == -1) {
- // Will never happen with a network socket. An IOException will be
- // thrown when the client closes the connection.
- // Echo back the -1 to be safe.
- return -1;
- } else {
- return b[0] & 0xFF;
- }
- }
-
-
- protected final void onDataAvailable() {
- ready = Boolean.TRUE;
- listener.onDataAvailable();
- }
-
-
- protected abstract boolean doIsReady() throws IOException;
-
- protected abstract int doRead(boolean block, byte[] b, int off, int len)
- throws IOException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+
+import org.apache.tomcat.util.res.StringManager;
+
+public abstract class AbstractServletInputStream extends ServletInputStream {
+
+ protected static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
+ // Start in blocking-mode
+ private volatile Boolean ready = Boolean.TRUE;
+ private volatile ReadListener listener = null;
+
+
+ @Override
+ public final boolean isFinished() {
+ if (listener == null) {
+ throw new IllegalStateException(
+ sm.getString("upgrade.sis.isFinished.ise"));
+ }
+ // The only way to finish an HTTP Upgrade connection is to close the
+ // socket.
+ return false;
+ }
+
+
+ @Override
+ public final boolean isReady() {
+ if (listener == null) {
+ throw new IllegalStateException(
+ sm.getString("upgrade.sis.isReady.ise"));
+ }
+
+ // If we already know the current state, return it.
+ if (ready != null) {
+ return ready.booleanValue();
+ }
+
+ try {
+ ready = Boolean.valueOf(doIsReady());
+ } catch (IOException e) {
+ listener.onError(e);
+ }
+ return ready.booleanValue();
+ }
+
+
+ @Override
+ public final void setReadListener(ReadListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException(
+ sm.getString("upgrade.sis.readListener.null"));
+ }
+ this.listener = listener;
+ // Switching to non-blocking. Don't know if data is available.
+ ready = null;
+ }
+
+
+ @Override
+ public final int read() throws IOException {
+ preReadChecks();
+
+ return readInternal();
+ }
+
+
+ @Override
+ public final int readLine(byte[] b, int off, int len) throws IOException {
+ preReadChecks();
+
+ if (len <= 0) {
+ return 0;
+ }
+ int count = 0, c;
+
+ while ((c = readInternal()) != -1) {
+ b[off++] = (byte) c;
+ count++;
+ if (c == '\n' || count == len) {
+ break;
+ }
+ }
+ return count > 0 ? count : -1;
+ }
+
+
+ @Override
+ public final int read(byte[] b, int off, int len) throws IOException {
+ preReadChecks();
+
+ return doRead(listener == null, b, off, len);
+ }
+
+
+ private void preReadChecks() {
+ if (listener != null && (ready == null || !ready.booleanValue())) {
+ throw new IllegalStateException(
+ sm.getString("upgrade.sis.read.ise"));
+ }
+ // No longer know if data is available
+ ready = null;
+ }
+
+
+ private int readInternal() throws IOException {
+ // Single byte reads for non-blocking need special handling so all
+ // single byte reads run through this method.
+ ReadListener readListener = this.listener;
+ byte[] b = new byte[1];
+ int result = doRead(readListener == null, b, 0, 1);
+ if (result == 0) {
+ return -1;
+ } else if (result == -1) {
+ // Will never happen with a network socket. An IOException will be
+ // thrown when the client closes the connection.
+ // Echo back the -1 to be safe.
+ return -1;
+ } else {
+ return b[0] & 0xFF;
+ }
+ }
+
+
+ protected final void onDataAvailable() {
+ ready = Boolean.TRUE;
+ listener.onDataAvailable();
+ }
+
+
+ protected abstract boolean doIsReady() throws IOException;
+
+ protected abstract int doRead(boolean block, byte[] b, int off, int len)
+ throws IOException;
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java Sun Nov 25 10:55:52 2012
@@ -1,113 +1,113 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.WriteListener;
-
-import org.apache.tomcat.util.res.StringManager;
-
-public abstract class AbstractServletOutputStream extends ServletOutputStream {
-
- protected static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
-
- // Start in blocking-mode
- private volatile WriteListener listener = null;
- private byte[] buffer;
-
- @Override
- public final boolean canWrite() {
- if (listener == null) {
- throw new IllegalStateException(
- sm.getString("upgrade.sos.canWrite.is"));
- }
-
- return buffer == null;
- }
-
- @Override
- public final void setWriteListener(WriteListener listener) {
- if (listener == null) {
- throw new IllegalArgumentException(
- sm.getString("upgrade.sos.writeListener.null"));
- }
- this.listener = listener;
- }
-
- @Override
- public void write(int b) throws IOException {
- preWriteChecks();
-
- writeInternal(new byte[] { (byte) b }, 0, 1);
- }
-
-
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- preWriteChecks();
-
- writeInternal(b, off, len);
- }
-
-
- private void preWriteChecks() {
- if (buffer != null) {
- throw new IllegalStateException(
- sm.getString("upgrade.sis.write.ise"));
- }
- }
-
-
- private void writeInternal(byte[] b, int off, int len) throws IOException {
- if (listener == null) {
- // Simple case - blocking IO
- doWrite(true, b, off, len);
- } else {
- // Non-blocking IO
- int written = doWrite(false, b, off, len);
- if (written < len) {
- // TODO: - Reuse the buffer
- // - Only reallocate if it gets too big (>8k?)
- buffer = new byte[len - written];
- System.arraycopy(b, off + written, buffer, 0, len - written);
- } else {
- buffer = null;
- }
- }
- }
-
-
- protected final void onWritePossible() {
- try {
- writeInternal(buffer, 0, buffer.length);
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- if (buffer == null) {
- listener.onWritePossible();
- }
- }
-
- protected abstract int doWrite(boolean block, byte[] b, int off, int len)
- throws IOException;
-
- protected abstract void doFlush() throws IOException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
+
+import org.apache.tomcat.util.res.StringManager;
+
+public abstract class AbstractServletOutputStream extends ServletOutputStream {
+
+ protected static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+
+ // Start in blocking-mode
+ private volatile WriteListener listener = null;
+ private byte[] buffer;
+
+ @Override
+ public final boolean canWrite() {
+ if (listener == null) {
+ throw new IllegalStateException(
+ sm.getString("upgrade.sos.canWrite.is"));
+ }
+
+ return buffer == null;
+ }
+
+ @Override
+ public final void setWriteListener(WriteListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException(
+ sm.getString("upgrade.sos.writeListener.null"));
+ }
+ this.listener = listener;
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ preWriteChecks();
+
+ writeInternal(new byte[] { (byte) b }, 0, 1);
+ }
+
+
+ @Override
+ public void write(byte[] b, int off, int len) throws IOException {
+ preWriteChecks();
+
+ writeInternal(b, off, len);
+ }
+
+
+ private void preWriteChecks() {
+ if (buffer != null) {
+ throw new IllegalStateException(
+ sm.getString("upgrade.sis.write.ise"));
+ }
+ }
+
+
+ private void writeInternal(byte[] b, int off, int len) throws IOException {
+ if (listener == null) {
+ // Simple case - blocking IO
+ doWrite(true, b, off, len);
+ } else {
+ // Non-blocking IO
+ int written = doWrite(false, b, off, len);
+ if (written < len) {
+ // TODO: - Reuse the buffer
+ // - Only reallocate if it gets too big (>8k?)
+ buffer = new byte[len - written];
+ System.arraycopy(b, off + written, buffer, 0, len - written);
+ } else {
+ buffer = null;
+ }
+ }
+ }
+
+
+ protected final void onWritePossible() {
+ try {
+ writeInternal(buffer, 0, buffer.length);
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ if (buffer == null) {
+ listener.onWritePossible();
+ }
+ }
+
+ protected abstract int doWrite(boolean block, byte[] b, int off, int len)
+ throws IOException;
+
+ protected abstract void doFlush() throws IOException;
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AbstractServletOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java Sun Nov 25 10:55:52 2012
@@ -1,81 +1,81 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class AprServletInputStream extends AbstractServletInputStream {
-
- private final long socket;
-
-
- public AprServletInputStream(SocketWrapper<Long> wrapper) {
- this.socket = wrapper.getSocket().longValue();
- }
-/*
- @Override
- protected int doRead() throws IOException {
- byte[] bytes = new byte[1];
- int result = Socket.recv(socket, bytes, 0, 1);
- if (result == -1) {
- return -1;
- } else {
- return bytes[0] & 0xFF;
- }
- }
-
- @Override
- protected int doRead(byte[] b, int off, int len) throws IOException {
- boolean block = true;
- if (!block) {
- Socket.optSet(socket, Socket.APR_SO_NONBLOCK, -1);
- }
- try {
- int result = Socket.recv(socket, b, off, len);
- if (result > 0) {
- return result;
- } else if (-result == Status.EAGAIN) {
- return 0;
- } else {
- throw new IOException(sm.getString("apr.error",
- Integer.valueOf(-result)));
- }
- } finally {
- if (!block) {
- Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 0);
- }
- }
- }
-}
-*/
-
- @Override
- protected int doRead(boolean block, byte[] b, int off, int len)
- throws IOException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- protected boolean doIsReady() {
- // TODO Auto-generated method stub
- return false;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class AprServletInputStream extends AbstractServletInputStream {
+
+ private final long socket;
+
+
+ public AprServletInputStream(SocketWrapper<Long> wrapper) {
+ this.socket = wrapper.getSocket().longValue();
+ }
+/*
+ @Override
+ protected int doRead() throws IOException {
+ byte[] bytes = new byte[1];
+ int result = Socket.recv(socket, bytes, 0, 1);
+ if (result == -1) {
+ return -1;
+ } else {
+ return bytes[0] & 0xFF;
+ }
+ }
+
+ @Override
+ protected int doRead(byte[] b, int off, int len) throws IOException {
+ boolean block = true;
+ if (!block) {
+ Socket.optSet(socket, Socket.APR_SO_NONBLOCK, -1);
+ }
+ try {
+ int result = Socket.recv(socket, b, off, len);
+ if (result > 0) {
+ return result;
+ } else if (-result == Status.EAGAIN) {
+ return 0;
+ } else {
+ throw new IOException(sm.getString("apr.error",
+ Integer.valueOf(-result)));
+ }
+ } finally {
+ if (!block) {
+ Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 0);
+ }
+ }
+ }
+}
+*/
+
+ @Override
+ protected int doRead(boolean block, byte[] b, int off, int len)
+ throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ protected boolean doIsReady() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java Sun Nov 25 10:55:52 2012
@@ -1,44 +1,44 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class AprServletOutputStream extends AbstractServletOutputStream {
-
- private final long socket;
-
-
- public AprServletOutputStream(SocketWrapper<Long> wrapper) {
- this.socket = wrapper.getSocket().longValue();
- }
-
-
- @Override
- protected int doWrite(boolean block, byte[] b, int off, int len)
- throws IOException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- protected void doFlush() throws IOException {
- // TODO Auto-generated method stub
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class AprServletOutputStream extends AbstractServletOutputStream {
+
+ private final long socket;
+
+
+ public AprServletOutputStream(SocketWrapper<Long> wrapper) {
+ this.socket = wrapper.getSocket().longValue();
+ }
+
+
+ @Override
+ protected int doWrite(boolean block, byte[] b, int off, int len)
+ throws IOException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ protected void doFlush() throws IOException {
+ // TODO Auto-generated method stub
+ }
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprServletOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java Sun Nov 25 10:55:52 2012
@@ -1,45 +1,45 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.Socket;
-
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class BioServletInputStream extends AbstractServletInputStream {
-
- private final InputStream inputStream;
-
- public BioServletInputStream(SocketWrapper<Socket> wrapper)
- throws IOException {
- inputStream = wrapper.getSocket().getInputStream();
- }
-
- @Override
- protected int doRead(boolean block, byte[] b, int off, int len)
- throws IOException {
- return inputStream.read(b, off, len);
- }
-
- @Override
- protected boolean doIsReady() {
- // Always returns true for BIO
- return true;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Socket;
+
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class BioServletInputStream extends AbstractServletInputStream {
+
+ private final InputStream inputStream;
+
+ public BioServletInputStream(SocketWrapper<Socket> wrapper)
+ throws IOException {
+ inputStream = wrapper.getSocket().getInputStream();
+ }
+
+ @Override
+ protected int doRead(boolean block, byte[] b, int off, int len)
+ throws IOException {
+ return inputStream.read(b, off, len);
+ }
+
+ @Override
+ protected boolean doIsReady() {
+ // Always returns true for BIO
+ return true;
+ }
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java Sun Nov 25 10:55:52 2012
@@ -1,45 +1,45 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.Socket;
-
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class BioServletOutputStream extends AbstractServletOutputStream {
-
- private final OutputStream os;
-
- public BioServletOutputStream(SocketWrapper<Socket> wrapper)
- throws IOException {
- os = wrapper.getSocket().getOutputStream();
- }
-
- @Override
- protected int doWrite(boolean block, byte[] b, int off, int len)
- throws IOException {
- os.write(b, off, len);
- return len;
- }
-
- @Override
- protected void doFlush() throws IOException {
- os.flush();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class BioServletOutputStream extends AbstractServletOutputStream {
+
+ private final OutputStream os;
+
+ public BioServletOutputStream(SocketWrapper<Socket> wrapper)
+ throws IOException {
+ os = wrapper.getSocket().getOutputStream();
+ }
+
+ @Override
+ protected int doWrite(boolean block, byte[] b, int off, int len)
+ throws IOException {
+ os.write(b, off, len);
+ return len;
+ }
+
+ @Override
+ protected void doFlush() throws IOException {
+ os.flush();
+ }
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/BioServletOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java Sun Nov 25 10:55:52 2012
@@ -1,133 +1,133 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.Selector;
-
-import org.apache.tomcat.util.net.NioChannel;
-import org.apache.tomcat.util.net.NioEndpoint;
-import org.apache.tomcat.util.net.NioSelectorPool;
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class NioServletInputStream extends AbstractServletInputStream {
-
- private final NioChannel channel;
- private final NioSelectorPool pool;
-
- public NioServletInputStream(SocketWrapper<NioChannel> wrapper,
- NioSelectorPool pool) {
- this.channel = wrapper.getSocket();
- this.pool = pool;
- }
-
- @Override
- protected boolean doIsReady() throws IOException {
- ByteBuffer readBuffer = channel.getBufHandler().getReadBuffer();
-
- if (readBuffer.remaining() > 0) {
- return true;
- }
-
- readBuffer.clear();
- fillReadBuffer(false);
-
- boolean isReady = readBuffer.position() > 0;
- readBuffer.flip();
- return isReady;
- }
-
- @Override
- protected int doRead(boolean block, byte[] b, int off, int len)
- throws IOException {
-
- ByteBuffer readBuffer = channel.getBufHandler().getReadBuffer();
- int remaining = readBuffer.remaining();
-
- // Is there enough data in the read buffer to satisfy this request?
- if (remaining >= len) {
- readBuffer.get(b, off, len);
- return len;
- }
-
- // Copy what data there is in the read buffer to the byte array
- int leftToWrite = len;
- int newOffset = off;
- if (remaining > 0) {
- readBuffer.get(b, off, remaining);
- leftToWrite -= remaining;
- newOffset += remaining;
- }
-
- // Fill the read buffer as best we can
- readBuffer.clear();
- int nRead = fillReadBuffer(block);
-
- // Full as much of the remaining byte array as possible with the data
- // that was just read
- if (nRead > 0) {
- readBuffer.flip();
- readBuffer.limit(nRead);
- if (nRead > leftToWrite) {
- readBuffer.get(b, newOffset, leftToWrite);
- leftToWrite = 0;
- } else {
- readBuffer.get(b, newOffset, nRead);
- leftToWrite -= nRead;
- }
- } else if (nRead == 0) {
- readBuffer.flip();
- } else if (nRead == -1) {
- // TODO i18n
- throw new EOFException();
- }
-
- return len - leftToWrite;
- }
-
- private int fillReadBuffer(boolean block) throws IOException {
- int nRead;
- if (block) {
- Selector selector = null;
- try {
- selector = pool.get();
- } catch ( IOException x ) {
- // Ignore
- }
- try {
- NioEndpoint.KeyAttachment att =
- (NioEndpoint.KeyAttachment) channel.getAttachment(false);
- if (att == null) {
- throw new IOException("Key must be cancelled.");
- }
- nRead = pool.read(channel.getBufHandler().getReadBuffer(),
- channel, selector, att.getTimeout());
- } catch (EOFException eof) {
- nRead = -1;
- } finally {
- if (selector != null) {
- pool.put(selector);
- }
- }
- } else {
- nRead = channel.read(channel.getBufHandler().getReadBuffer());
- }
- return nRead;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Selector;
+
+import org.apache.tomcat.util.net.NioChannel;
+import org.apache.tomcat.util.net.NioEndpoint;
+import org.apache.tomcat.util.net.NioSelectorPool;
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class NioServletInputStream extends AbstractServletInputStream {
+
+ private final NioChannel channel;
+ private final NioSelectorPool pool;
+
+ public NioServletInputStream(SocketWrapper<NioChannel> wrapper,
+ NioSelectorPool pool) {
+ this.channel = wrapper.getSocket();
+ this.pool = pool;
+ }
+
+ @Override
+ protected boolean doIsReady() throws IOException {
+ ByteBuffer readBuffer = channel.getBufHandler().getReadBuffer();
+
+ if (readBuffer.remaining() > 0) {
+ return true;
+ }
+
+ readBuffer.clear();
+ fillReadBuffer(false);
+
+ boolean isReady = readBuffer.position() > 0;
+ readBuffer.flip();
+ return isReady;
+ }
+
+ @Override
+ protected int doRead(boolean block, byte[] b, int off, int len)
+ throws IOException {
+
+ ByteBuffer readBuffer = channel.getBufHandler().getReadBuffer();
+ int remaining = readBuffer.remaining();
+
+ // Is there enough data in the read buffer to satisfy this request?
+ if (remaining >= len) {
+ readBuffer.get(b, off, len);
+ return len;
+ }
+
+ // Copy what data there is in the read buffer to the byte array
+ int leftToWrite = len;
+ int newOffset = off;
+ if (remaining > 0) {
+ readBuffer.get(b, off, remaining);
+ leftToWrite -= remaining;
+ newOffset += remaining;
+ }
+
+ // Fill the read buffer as best we can
+ readBuffer.clear();
+ int nRead = fillReadBuffer(block);
+
+ // Full as much of the remaining byte array as possible with the data
+ // that was just read
+ if (nRead > 0) {
+ readBuffer.flip();
+ readBuffer.limit(nRead);
+ if (nRead > leftToWrite) {
+ readBuffer.get(b, newOffset, leftToWrite);
+ leftToWrite = 0;
+ } else {
+ readBuffer.get(b, newOffset, nRead);
+ leftToWrite -= nRead;
+ }
+ } else if (nRead == 0) {
+ readBuffer.flip();
+ } else if (nRead == -1) {
+ // TODO i18n
+ throw new EOFException();
+ }
+
+ return len - leftToWrite;
+ }
+
+ private int fillReadBuffer(boolean block) throws IOException {
+ int nRead;
+ if (block) {
+ Selector selector = null;
+ try {
+ selector = pool.get();
+ } catch ( IOException x ) {
+ // Ignore
+ }
+ try {
+ NioEndpoint.KeyAttachment att =
+ (NioEndpoint.KeyAttachment) channel.getAttachment(false);
+ if (att == null) {
+ throw new IOException("Key must be cancelled.");
+ }
+ nRead = pool.read(channel.getBufHandler().getReadBuffer(),
+ channel, selector, att.getTimeout());
+ } catch (EOFException eof) {
+ nRead = -1;
+ } finally {
+ if (selector != null) {
+ pool.put(selector);
+ }
+ }
+ } else {
+ nRead = channel.read(channel.getBufHandler().getReadBuffer());
+ }
+ return nRead;
+ }
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java Sun Nov 25 10:55:52 2012
@@ -1,128 +1,128 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.IOException;
-import java.nio.channels.Selector;
-
-import org.apache.tomcat.util.net.NioChannel;
-import org.apache.tomcat.util.net.NioEndpoint;
-import org.apache.tomcat.util.net.NioSelectorPool;
-import org.apache.tomcat.util.net.SocketWrapper;
-
-public class NioServletOutputStream extends AbstractServletOutputStream {
-
- private final NioChannel nioChannel;
- private final NioSelectorPool pool;
- private final int maxWrite;
-
-
- public NioServletOutputStream(
- SocketWrapper<NioChannel> wrapper, NioSelectorPool pool) {
- nioChannel = wrapper.getSocket();
- this.pool = pool;
- maxWrite = nioChannel.getBufHandler().getWriteBuffer().capacity();
- }
-
-
- @Override
- protected int doWrite(boolean block, byte[] b, int off, int len)
- throws IOException {
- int leftToWrite = len;
- int count = 0;
- int offset = off;
-
- while (leftToWrite > 0) {
- int writeThisLoop;
- int writtenThisLoop;
-
- if (leftToWrite > maxWrite) {
- writeThisLoop = maxWrite;
- } else {
- writeThisLoop = leftToWrite;
- }
-
- writtenThisLoop = doWriteInternal(block, b, offset, writeThisLoop);
- count += writtenThisLoop;
- leftToWrite -= writtenThisLoop;
-
- if (writtenThisLoop < writeThisLoop) {
- break;
- }
- }
-
- return count;
- }
-
- private int doWriteInternal (boolean block, byte[] b, int off, int len)
- throws IOException {
- nioChannel.getBufHandler().getWriteBuffer().clear();
- nioChannel.getBufHandler().getWriteBuffer().put(b, off, len);
- nioChannel.getBufHandler().getWriteBuffer().flip();
-
- int written = 0;
- NioEndpoint.KeyAttachment att =
- (NioEndpoint.KeyAttachment) nioChannel.getAttachment(false);
- if (att == null) {
- throw new IOException("Key must be cancelled");
- }
- long writeTimeout = att.getTimeout();
- Selector selector = null;
- try {
- selector = pool.get();
- } catch ( IOException x ) {
- //ignore
- }
- try {
- written = pool.write(nioChannel.getBufHandler().getWriteBuffer(),
- nioChannel, selector, writeTimeout, block);
- } finally {
- if (selector != null) {
- pool.put(selector);
- }
- }
- return written;
- }
-
-
- @Override
- protected void doFlush() throws IOException {
- NioEndpoint.KeyAttachment att =
- (NioEndpoint.KeyAttachment) nioChannel.getAttachment(false);
- if (att == null) {
- throw new IOException("Key must be cancelled");
- }
- long writeTimeout = att.getTimeout();
- Selector selector = null;
- try {
- selector = pool.get();
- } catch ( IOException x ) {
- //ignore
- }
- try {
- do {
- if (nioChannel.flush(true, selector, writeTimeout)) {
- break;
- }
- } while (true);
- } finally {
- if (selector != null) {
- pool.put(selector);
- }
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.IOException;
+import java.nio.channels.Selector;
+
+import org.apache.tomcat.util.net.NioChannel;
+import org.apache.tomcat.util.net.NioEndpoint;
+import org.apache.tomcat.util.net.NioSelectorPool;
+import org.apache.tomcat.util.net.SocketWrapper;
+
+public class NioServletOutputStream extends AbstractServletOutputStream {
+
+ private final NioChannel nioChannel;
+ private final NioSelectorPool pool;
+ private final int maxWrite;
+
+
+ public NioServletOutputStream(
+ SocketWrapper<NioChannel> wrapper, NioSelectorPool pool) {
+ nioChannel = wrapper.getSocket();
+ this.pool = pool;
+ maxWrite = nioChannel.getBufHandler().getWriteBuffer().capacity();
+ }
+
+
+ @Override
+ protected int doWrite(boolean block, byte[] b, int off, int len)
+ throws IOException {
+ int leftToWrite = len;
+ int count = 0;
+ int offset = off;
+
+ while (leftToWrite > 0) {
+ int writeThisLoop;
+ int writtenThisLoop;
+
+ if (leftToWrite > maxWrite) {
+ writeThisLoop = maxWrite;
+ } else {
+ writeThisLoop = leftToWrite;
+ }
+
+ writtenThisLoop = doWriteInternal(block, b, offset, writeThisLoop);
+ count += writtenThisLoop;
+ leftToWrite -= writtenThisLoop;
+
+ if (writtenThisLoop < writeThisLoop) {
+ break;
+ }
+ }
+
+ return count;
+ }
+
+ private int doWriteInternal (boolean block, byte[] b, int off, int len)
+ throws IOException {
+ nioChannel.getBufHandler().getWriteBuffer().clear();
+ nioChannel.getBufHandler().getWriteBuffer().put(b, off, len);
+ nioChannel.getBufHandler().getWriteBuffer().flip();
+
+ int written = 0;
+ NioEndpoint.KeyAttachment att =
+ (NioEndpoint.KeyAttachment) nioChannel.getAttachment(false);
+ if (att == null) {
+ throw new IOException("Key must be cancelled");
+ }
+ long writeTimeout = att.getTimeout();
+ Selector selector = null;
+ try {
+ selector = pool.get();
+ } catch ( IOException x ) {
+ //ignore
+ }
+ try {
+ written = pool.write(nioChannel.getBufHandler().getWriteBuffer(),
+ nioChannel, selector, writeTimeout, block);
+ } finally {
+ if (selector != null) {
+ pool.put(selector);
+ }
+ }
+ return written;
+ }
+
+
+ @Override
+ protected void doFlush() throws IOException {
+ NioEndpoint.KeyAttachment att =
+ (NioEndpoint.KeyAttachment) nioChannel.getAttachment(false);
+ if (att == null) {
+ throw new IOException("Key must be cancelled");
+ }
+ long writeTimeout = att.getTimeout();
+ Selector selector = null;
+ try {
+ selector = pool.get();
+ } catch ( IOException x ) {
+ //ignore
+ }
+ try {
+ do {
+ if (nioChannel.flush(true, selector, writeTimeout)) {
+ break;
+ }
+ } while (true);
+ } finally {
+ if (selector != null) {
+ pool.put(selector);
+ }
+ }
+ }
+}
Propchange: tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioServletOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java?rev=1413328&r1=1413327&r2=1413328&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java Sun Nov 25 10:55:52 2012
@@ -1,273 +1,273 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.coyote.http11.upgrade;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.Writer;
-import java.net.Socket;
-
-import javax.net.SocketFactory;
-import javax.servlet.ReadListener;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.WriteListener;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.ProtocolHandler;
-import javax.servlet.http.WebConnection;
-
-import junit.framework.Assert;
-
-import org.junit.Test;
-
-import static org.apache.catalina.startup.SimpleHttpClient.CRLF;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.catalina.startup.TomcatBaseTest;
-import org.apache.catalina.util.IOTools;
-
-public class TestUpgrade extends TomcatBaseTest {
-
- private static final String MESSAGE = "This is a test.";
-
- @Test
- public void testSimpleUpgradeBlocking() throws Exception {
- doUpgrade(EchoBlocking.class);
- }
-
- @Test
- public void testSimpleUpgradeNonBlocking() throws Exception {
- doUpgrade(EchoNonBlocking.class);
- }
-
- @Test
- public void testMessagesBlocking() throws Exception {
- doTestMessages(EchoBlocking.class);
- }
-
- @Test
- public void testMessagesNonBlocking() throws Exception {
- doTestMessages(EchoNonBlocking.class);
- }
-
- private void doTestMessages (
- Class<? extends ProtocolHandler> upgradeHandlerClass)
- throws Exception {
- UpgradeConnection conn = doUpgrade(upgradeHandlerClass);
- PrintWriter pw = new PrintWriter(conn.getWriter());
- BufferedReader reader = conn.getReader();
-
- pw.println(MESSAGE);
- pw.flush();
-
- Thread.sleep(500);
-
- pw.println(MESSAGE);
- pw.flush();
-
- String response = reader.readLine();
-
- // Note: BufferedReader.readLine() strips new lines
- // ServletInputStream.readLine() does not strip new lines
- Assert.assertEquals(MESSAGE, response);
- }
-
-
- private UpgradeConnection doUpgrade(
- Class<? extends ProtocolHandler> upgradeHandlerClass) throws Exception {
- // Setup Tomcat instance
- Tomcat tomcat = getTomcatInstance();
-
- // Must have a real docBase - just use temp
- Context ctx =
- tomcat.addContext("", System.getProperty("java.io.tmpdir"));
-
- UpgradeServlet servlet = new UpgradeServlet(upgradeHandlerClass);
- Tomcat.addServlet(ctx, "servlet", servlet);
- ctx.addServletMapping("/", "servlet");
-
- tomcat.start();
-
- // Use raw socket so the necessary control is available after the HTTP
- // upgrade
- Socket socket =
- SocketFactory.getDefault().createSocket("localhost", getPort());
-
- socket.setSoTimeout(300000);
-
- InputStream is = socket.getInputStream();
- OutputStream os = socket.getOutputStream();
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- Writer writer = new OutputStreamWriter(os);
-
- writer.write("GET / HTTP/1.1" + CRLF);
- writer.write("Host: whatever" + CRLF);
- writer.write(CRLF);
- writer.flush();
-
- String status = reader.readLine();
-
- Assert.assertEquals("HTTP/1.1 101 Switching Protocols",
- status.substring(0, 32));
-
- // Skip the remaining response headers
- while (reader.readLine().length() > 0) {
- // Skip
- }
-
- return new UpgradeConnection(writer, reader);
- }
-
- private static class UpgradeServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- private final Class<? extends ProtocolHandler> upgradeHandlerClass;
-
- public UpgradeServlet(Class<? extends ProtocolHandler> upgradeHandlerClass) {
- this.upgradeHandlerClass = upgradeHandlerClass;
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
-
- ProtocolHandler upgradeHandler;
- try {
- upgradeHandler = upgradeHandlerClass.newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
- throw new ServletException(e);
- }
-
- req.upgrade(upgradeHandler);
- }
- }
-
- private static class UpgradeConnection {
- private final Writer writer;
- private final BufferedReader reader;
-
- public UpgradeConnection(Writer writer, BufferedReader reader) {
- this.writer = writer;
- this.reader = reader;
- }
-
- public Writer getWriter() {
- return writer;
- }
-
- public BufferedReader getReader() {
- return reader;
- }
- }
-
-
- protected static class EchoBlocking implements ProtocolHandler {
- @Override
- public void init(WebConnection connection) {
-
- try (ServletInputStream sis = connection.getInputStream();
- ServletOutputStream sos = connection.getOutputStream()){
-
- IOTools.flow(sis, sos);
- } catch (IOException ioe) {
- throw new IllegalStateException(ioe);
- }
- }
- }
-
-
- protected static class EchoNonBlocking implements ProtocolHandler {
-
- private ServletInputStream sis;
- private ServletOutputStream sos;
-
- @Override
- public void init(WebConnection connection) {
-
- try {
- sis = connection.getInputStream();
- sos = connection.getOutputStream();
- } catch (IOException ioe) {
- throw new IllegalStateException(ioe);
- }
-
- sis.setReadListener(new EchoReadListener());
- sos.setWriteListener(new EchoWriteListener());
- }
-
- private class EchoReadListener implements ReadListener {
-
- private byte[] buffer = new byte[8096];
-
- @Override
- public void onDataAvailable() {
- try {
- while (sis.isReady()) {
- int read = sis.read(buffer);
- if (read > 0) {
- if (sos.canWrite()) {
- sos.write(buffer, 0, read);
- } else {
- throw new IOException("Unable to echo data. " +
- "canWrite() returned false");
- }
- }
- }
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
-
- @Override
- public void onAllDataRead() {
- // NO-OP for HTTP Upgrade
- }
-
- @Override
- public void onError(Throwable throwable) {
- // TODO Auto-generated method stub
-
- }
- }
-
- private class EchoWriteListener implements WriteListener {
-
- @Override
- public void onWritePossible() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onError(Throwable throwable) {
- // TODO Auto-generated method stub
-
- }
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http11.upgrade;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.Socket;
+
+import javax.net.SocketFactory;
+import javax.servlet.ReadListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.ProtocolHandler;
+import javax.servlet.http.WebConnection;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import static org.apache.catalina.startup.SimpleHttpClient.CRLF;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.util.IOTools;
+
+public class TestUpgrade extends TomcatBaseTest {
+
+ private static final String MESSAGE = "This is a test.";
+
+ @Test
+ public void testSimpleUpgradeBlocking() throws Exception {
+ doUpgrade(EchoBlocking.class);
+ }
+
+ @Test
+ public void testSimpleUpgradeNonBlocking() throws Exception {
+ doUpgrade(EchoNonBlocking.class);
+ }
+
+ @Test
+ public void testMessagesBlocking() throws Exception {
+ doTestMessages(EchoBlocking.class);
+ }
+
+ @Test
+ public void testMessagesNonBlocking() throws Exception {
+ doTestMessages(EchoNonBlocking.class);
+ }
+
+ private void doTestMessages (
+ Class<? extends ProtocolHandler> upgradeHandlerClass)
+ throws Exception {
+ UpgradeConnection conn = doUpgrade(upgradeHandlerClass);
+ PrintWriter pw = new PrintWriter(conn.getWriter());
+ BufferedReader reader = conn.getReader();
+
+ pw.println(MESSAGE);
+ pw.flush();
+
+ Thread.sleep(500);
+
+ pw.println(MESSAGE);
+ pw.flush();
+
+ String response = reader.readLine();
+
+ // Note: BufferedReader.readLine() strips new lines
+ // ServletInputStream.readLine() does not strip new lines
+ Assert.assertEquals(MESSAGE, response);
+ }
+
+
+ private UpgradeConnection doUpgrade(
+ Class<? extends ProtocolHandler> upgradeHandlerClass) throws Exception {
+ // Setup Tomcat instance
+ Tomcat tomcat = getTomcatInstance();
+
+ // Must have a real docBase - just use temp
+ Context ctx =
+ tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+ UpgradeServlet servlet = new UpgradeServlet(upgradeHandlerClass);
+ Tomcat.addServlet(ctx, "servlet", servlet);
+ ctx.addServletMapping("/", "servlet");
+
+ tomcat.start();
+
+ // Use raw socket so the necessary control is available after the HTTP
+ // upgrade
+ Socket socket =
+ SocketFactory.getDefault().createSocket("localhost", getPort());
+
+ socket.setSoTimeout(300000);
+
+ InputStream is = socket.getInputStream();
+ OutputStream os = socket.getOutputStream();
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ Writer writer = new OutputStreamWriter(os);
+
+ writer.write("GET / HTTP/1.1" + CRLF);
+ writer.write("Host: whatever" + CRLF);
+ writer.write(CRLF);
+ writer.flush();
+
+ String status = reader.readLine();
+
+ Assert.assertEquals("HTTP/1.1 101 Switching Protocols",
+ status.substring(0, 32));
+
+ // Skip the remaining response headers
+ while (reader.readLine().length() > 0) {
+ // Skip
+ }
+
+ return new UpgradeConnection(writer, reader);
+ }
+
+ private static class UpgradeServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Class<? extends ProtocolHandler> upgradeHandlerClass;
+
+ public UpgradeServlet(Class<? extends ProtocolHandler> upgradeHandlerClass) {
+ this.upgradeHandlerClass = upgradeHandlerClass;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ ProtocolHandler upgradeHandler;
+ try {
+ upgradeHandler = upgradeHandlerClass.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new ServletException(e);
+ }
+
+ req.upgrade(upgradeHandler);
+ }
+ }
+
+ private static class UpgradeConnection {
+ private final Writer writer;
+ private final BufferedReader reader;
+
+ public UpgradeConnection(Writer writer, BufferedReader reader) {
+ this.writer = writer;
+ this.reader = reader;
+ }
+
+ public Writer getWriter() {
+ return writer;
+ }
+
+ public BufferedReader getReader() {
+ return reader;
+ }
+ }
+
+
+ protected static class EchoBlocking implements ProtocolHandler {
+ @Override
+ public void init(WebConnection connection) {
+
+ try (ServletInputStream sis = connection.getInputStream();
+ ServletOutputStream sos = connection.getOutputStream()){
+
+ IOTools.flow(sis, sos);
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+ }
+ }
+
+
+ protected static class EchoNonBlocking implements ProtocolHandler {
+
+ private ServletInputStream sis;
+ private ServletOutputStream sos;
+
+ @Override
+ public void init(WebConnection connection) {
+
+ try {
+ sis = connection.getInputStream();
+ sos = connection.getOutputStream();
+ } catch (IOException ioe) {
+ throw new IllegalStateException(ioe);
+ }
+
+ sis.setReadListener(new EchoReadListener());
+ sos.setWriteListener(new EchoWriteListener());
+ }
+
+ private class EchoReadListener implements ReadListener {
+
+ private byte[] buffer = new byte[8096];
+
+ @Override
+ public void onDataAvailable() {
+ try {
+ while (sis.isReady()) {
+ int read = sis.read(buffer);
+ if (read > 0) {
+ if (sos.canWrite()) {
+ sos.write(buffer, 0, read);
+ } else {
+ throw new IOException("Unable to echo data. " +
+ "canWrite() returned false");
+ }
+ }
+ }
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ @Override
+ public void onAllDataRead() {
+ // NO-OP for HTTP Upgrade
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ private class EchoWriteListener implements WriteListener {
+
+ @Override
+ public void onWritePossible() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+ // TODO Auto-generated method stub
+
+ }
+ }
+ }
+}
Propchange: tomcat/trunk/test/org/apache/coyote/http11/upgrade/TestUpgrade.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org