Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/ChannelEndPoint.java @ 1016:8c13b9224cff
remove returnBuffer()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 24 Oct 2016 01:38:00 -0600 |
parents | 0e96ce3db20a |
children | 921c25a05eaa |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.io.nio; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.net.InetSocketAddress; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.net.Socket; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.net.SocketException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.nio.ByteBuffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.nio.channels.ByteChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.nio.channels.GatheringByteChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import java.nio.channels.SocketChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import org.eclipse.jetty.io.EndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.util.StringUtil; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
33 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
34 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 * Channel End Point. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 * <p>Holds the channel and socket for an NIO endpoint. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 public class ChannelEndPoint implements EndPoint |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 { |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
43 private static final Logger LOG = LoggerFactory.getLogger(ChannelEndPoint.class); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
45 private final SocketChannel _channel; |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
46 private final ByteBuffer[] _gather2 = new ByteBuffer[2]; |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
47 protected final Socket _socket; |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
48 private final InetSocketAddress _local; |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
49 private final InetSocketAddress _remote; |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
50 protected volatile int _maxIdleTime; |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
51 private volatile boolean _ishut = false; |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
52 private volatile boolean _oshut = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
54 protected ChannelEndPoint(SocketChannel channel, int maxIdleTime) throws IOException |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
55 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
56 this._channel = channel; |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
57 _maxIdleTime = maxIdleTime; |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
58 _socket = channel.socket(); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
59 _local = (InetSocketAddress)_socket.getLocalSocketAddress(); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
60 _remote = (InetSocketAddress)_socket.getRemoteSocketAddress(); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
61 _socket.setSoTimeout(_maxIdleTime); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
62 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
64 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
65 public final boolean isBlocking() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
66 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
67 return _channel.isBlocking(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
68 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
69 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
70 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
71 public boolean blockReadable(long millisecs) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
72 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
73 return true; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
74 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
76 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
77 public boolean blockWritable(long millisecs) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
78 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
79 return true; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
80 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
81 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
82 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
83 public final boolean isOpen() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
84 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
85 return _channel.isOpen(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
86 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
88 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
89 public final void shutdownInput() throws IOException |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
90 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
91 LOG.debug("ishut {}", this); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
92 _ishut = true; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
93 if (_channel.isOpen()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
94 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
95 try |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
96 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
97 if (!_socket.isInputShutdown()) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
98 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
99 _socket.shutdownInput(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
100 } |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
101 } |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
102 catch (SocketException e) |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
103 { |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
104 LOG.debug(e.toString()); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
105 LOG.trace("",e); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
106 } |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
107 finally |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
108 { |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
109 if (_oshut) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
110 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
111 close(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
112 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
113 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
114 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
115 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
116 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
117 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
118 public final void shutdownOutput() throws IOException |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
119 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
120 LOG.debug("oshut {}",this); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
121 _oshut = true; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
122 if (_channel.isOpen()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
123 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
124 try |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
125 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
126 if (!_socket.isOutputShutdown()) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
127 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
128 _socket.shutdownOutput(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
129 } |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
130 } |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
131 catch (SocketException e) |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
132 { |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
133 LOG.debug(e.toString()); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
134 LOG.trace("",e); |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
135 } |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
136 finally |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
137 { |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
138 if (_ishut) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
139 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
140 close(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
141 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
142 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
143 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
144 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
146 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
147 public final boolean isOutputShutdown() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
148 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
149 return _oshut || !_channel.isOpen() || _socket.isOutputShutdown(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
150 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
151 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
152 @Override |
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
153 public final boolean isInputShutdown() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
154 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
155 return _ishut || !_channel.isOpen() || _socket.isInputShutdown(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
156 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
157 |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
958
diff
changeset
|
158 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
159 public void close() throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
160 { |
1005 | 161 //Thread.dumpStack(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
162 LOG.debug("close {}",this); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
163 _channel.close(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
164 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
166 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
167 public int fill(Buffer buffer) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
168 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
169 if (_ishut) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
170 return -1; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
171 Buffer buf = buffer.buffer(); |
1005 | 172 int len = 0; |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
173 if (buf instanceof NIOBuffer) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
174 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
175 final NIOBuffer nbuf = (NIOBuffer)buf; |
1005 | 176 final ByteBuffer bbuf = nbuf.getByteBuffer(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
177 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
178 //noinspection SynchronizationOnLocalVariableOrMethodParameter |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
179 try |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
180 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
181 synchronized(bbuf) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
182 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
183 try |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
184 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
185 bbuf.position(buffer.putIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
186 len=_channel.read(bbuf); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
187 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
188 finally |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
189 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
190 buffer.setPutIndex(bbuf.position()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
191 bbuf.position(0); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
192 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
193 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
195 if (len<0 && isOpen()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
196 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
197 if (!isInputShutdown()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
198 shutdownInput(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
199 if (isOutputShutdown()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
200 _channel.close(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
201 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
202 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
203 catch (IOException x) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
204 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
205 LOG.debug("Exception while filling", x); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
206 try |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
207 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
208 if (_channel.isOpen()) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
209 _channel.close(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
210 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
211 catch (Exception xx) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
212 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
213 LOG.trace("",xx); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
214 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
215 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
216 if (len>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
217 throw x; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
218 len=-1; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
219 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
220 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
221 else |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
222 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
223 throw new IOException("Not Implemented"); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
224 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
225 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
226 return len; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
227 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
229 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
230 public int flush(Buffer buffer) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
231 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
232 Buffer buf = buffer.buffer(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
233 int len=0; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
234 if (buf instanceof NIOBuffer) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
235 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
236 final NIOBuffer nbuf = (NIOBuffer)buf; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
237 final ByteBuffer bbuf=nbuf.getByteBuffer().asReadOnlyBuffer(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
238 try |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
239 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
240 bbuf.position(buffer.getIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
241 bbuf.limit(buffer.putIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
242 len=_channel.write(bbuf); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
243 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
244 finally |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
245 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
246 if (len>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
247 buffer.skip(len); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
248 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
249 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
250 else if (buffer.array()!=null) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
251 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
252 ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
253 len=_channel.write(b); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
254 if (len>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
255 buffer.skip(len); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
256 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
257 else |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
258 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
259 throw new IOException("Not Implemented"); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
260 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
261 return len; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
262 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
263 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
264 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
265 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
266 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
267 int length=0; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
268 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
269 Buffer buf0 = header==null?null:header.buffer(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
270 Buffer buf1 = buffer==null?null:buffer.buffer(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
272 if (_channel instanceof GatheringByteChannel && |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
273 header!=null && header.length()!=0 && buf0 instanceof NIOBuffer && |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
274 buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
275 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
276 length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
277 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
278 else |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
279 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
280 // flush header |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
281 if (header!=null && header.length()>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
282 length=flush(header); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
283 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
284 // flush buffer |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
285 if ((header==null || header.length()==0) && |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
286 buffer!=null && buffer.length()>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
287 length+=flush(buffer); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
288 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
289 // flush trailer |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
290 if ((header==null || header.length()==0) && |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
291 (buffer==null || buffer.length()==0) && |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
292 trailer!=null && trailer.length()>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
293 length+=flush(trailer); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
294 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
296 return length; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
297 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
299 private int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
300 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
301 int length; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
303 synchronized(this) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
304 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
305 // Adjust position indexs of buf0 and buf1 |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
306 bbuf0=bbuf0.asReadOnlyBuffer(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
307 bbuf0.position(header.getIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
308 bbuf0.limit(header.putIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
309 bbuf1=bbuf1.asReadOnlyBuffer(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
310 bbuf1.position(buffer.getIndex()); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
311 bbuf1.limit(buffer.putIndex()); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
312 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
313 _gather2[0]=bbuf0; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
314 _gather2[1]=bbuf1; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
316 // do the gathering write. |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
317 length=(int)((GatheringByteChannel)_channel).write(_gather2); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
318 |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
319 int hl=header.length(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
320 if (length>hl) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
321 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
322 header.clear(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
323 buffer.skip(length-hl); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
324 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
325 else if (length>0) |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
326 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
327 header.skip(length); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
328 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
329 } |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
330 return length; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
331 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
333 public final SocketChannel getChannel() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
334 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
335 return _channel; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
336 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
337 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
338 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
339 public final String getLocalAddr() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
340 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
341 if (_local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
342 return StringUtil.ALL_INTERFACES; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
343 return _local.getAddress().getHostAddress(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
344 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
346 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
347 public final String getLocalHost() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
348 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
349 if (_local.getAddress()==null || _local.getAddress().isAnyLocalAddress()) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
350 return StringUtil.ALL_INTERFACES; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
351 return _local.getAddress().getCanonicalHostName(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
352 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
353 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
354 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
355 public final int getLocalPort() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
356 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
357 return _local.getPort(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
358 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
359 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
360 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
361 public final String getRemoteAddr() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
362 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
363 return _remote.getAddress().getHostAddress(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
364 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
366 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
367 public final String getRemoteHost() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
368 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
369 return _remote.getAddress().getCanonicalHostName(); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
370 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
372 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
373 public final int getRemotePort() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
374 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
375 return _remote.getPort(); |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
376 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
378 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
379 public void flush() |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
380 throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
381 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
382 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
384 @Override |
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
385 public final int getMaxIdleTime() |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
386 { |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
387 return _maxIdleTime; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
388 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
389 |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
390 @Override |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
391 public void setMaxIdleTime(int timeMs) throws IOException |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
392 { |
978
bdb6eb0fbf93
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
965
diff
changeset
|
393 if (timeMs!=_maxIdleTime) |
873
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
394 _socket.setSoTimeout(timeMs>0?timeMs:0); |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
395 _maxIdleTime=timeMs; |
220ad4853cda
remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
820
diff
changeset
|
396 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
397 } |