|
16 | 16 | */ |
17 | 17 | package org.apache.coyote; |
18 | 18 |
|
| 19 | +import java.io.IOException; |
19 | 20 | import java.net.InetAddress; |
20 | 21 | import java.util.concurrent.ConcurrentHashMap; |
21 | 22 | import java.util.concurrent.ConcurrentLinkedQueue; |
|
28 | 29 | import javax.management.MalformedObjectNameException; |
29 | 30 | import javax.management.ObjectName; |
30 | 31 |
|
| 32 | +import org.apache.coyote.http11.upgrade.UpgradeInbound; |
31 | 33 | import org.apache.juli.logging.Log; |
32 | 34 | import org.apache.tomcat.util.ExceptionUtils; |
33 | 35 | import org.apache.tomcat.util.modeler.Registry; |
@@ -576,9 +578,18 @@ public SocketState process(SocketWrapper<S> socket, |
576 | 578 | // closed. If it works, the socket will be re-added to the |
577 | 579 | // poller |
578 | 580 | release(socket, processor, false, false); |
579 | | - } else if (state == SocketState.UPGRADE) { |
| 581 | + } else if (state == SocketState.UPGRADED) { |
580 | 582 | // Need to keep the connection associated with the processor |
581 | | - longPoll(socket, processor); |
| 583 | + upgradePoll(socket, processor); |
| 584 | + } else if (state == SocketState.UPGRADING) { |
| 585 | + // Get the UpgradeInbound handler |
| 586 | + UpgradeInbound inbound = processor.getUpgradeInbound(); |
| 587 | + // Release the Http11 processor to be re-used |
| 588 | + release(socket, processor, false, false); |
| 589 | + // Create the light-weight upgrade processor |
| 590 | + processor = createUpgradeProcessor(socket, inbound); |
| 591 | + // Need to keep the connection associated with the processor |
| 592 | + upgradePoll(socket, processor); |
582 | 593 | } else { |
583 | 594 | // Connection closed. OK to recycle the processor. |
584 | 595 | release(socket, processor, true, false); |
@@ -610,9 +621,12 @@ public SocketState process(SocketWrapper<S> socket, |
610 | 621 | protected abstract P createProcessor(); |
611 | 622 | protected abstract void initSsl(SocketWrapper<S> socket, P processor); |
612 | 623 | protected abstract void longPoll(SocketWrapper<S> socket, P processor); |
| 624 | + protected abstract void upgradePoll(SocketWrapper<S> socket, |
| 625 | + P processor); |
613 | 626 | protected abstract void release(SocketWrapper<S> socket, P processor, |
614 | 627 | boolean socketClosing, boolean addToPoller); |
615 | | - |
| 628 | + protected abstract P createUpgradeProcessor(SocketWrapper<S> socket, |
| 629 | + UpgradeInbound inbound) throws IOException; |
616 | 630 |
|
617 | 631 | protected void register(AbstractProcessor<S> processor) { |
618 | 632 | if (getProtocol().getDomain() != null) { |
@@ -645,8 +659,12 @@ protected void unregister(AbstractProcessor<S> processor) { |
645 | 659 | if (getProtocol().getDomain() != null) { |
646 | 660 | synchronized (this) { |
647 | 661 | try { |
648 | | - RequestInfo rp = |
649 | | - processor.getRequest().getRequestProcessor(); |
| 662 | + Request r = processor.getRequest(); |
| 663 | + if (r == null) { |
| 664 | + // Probably an UpgradeProcessor |
| 665 | + return; |
| 666 | + } |
| 667 | + RequestInfo rp = r.getRequestProcessor(); |
650 | 668 | rp.setGlobalProcessor(null); |
651 | 669 | ObjectName rpName = rp.getRpName(); |
652 | 670 | if (getLog().isDebugEnabled()) { |
|
0 commit comments