annotate src/org/eclipse/jetty/io/nio/ChannelEndPoint.java @ 990:83cc6e05a58f

remove special attribute handling
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 17 Oct 2016 05:50:47 -0600
parents 4f2d04c72781
children 0e96ce3db20a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 LOG.debug("close {}",this);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 _channel.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
165 @Override
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 public int fill(Buffer buffer) throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 if (_ishut)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 return -1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 Buffer buf = buffer.buffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 int len=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 if (buf instanceof NIOBuffer)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 final NIOBuffer nbuf = (NIOBuffer)buf;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 final ByteBuffer bbuf=nbuf.getByteBuffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 //noinspection SynchronizationOnLocalVariableOrMethodParameter
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 synchronized(bbuf)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 bbuf.position(buffer.putIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 len=_channel.read(bbuf);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 finally
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 buffer.setPutIndex(bbuf.position());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 bbuf.position(0);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 if (len<0 && isOpen())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 if (!isInputShutdown())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 shutdownInput();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 if (isOutputShutdown())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 _channel.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 }
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 catch (IOException x)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 LOG.debug("Exception while filling", x);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 if (_channel.isOpen())
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 _channel.close();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 catch (Exception xx)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 LOG.trace("",xx);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 if (len>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 throw x;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 len=-1;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 }
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 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 throw new IOException("Not Implemented");
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 return len;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
228 @Override
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 public int flush(Buffer buffer) throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 Buffer buf = buffer.buffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 int len=0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 if (buf instanceof NIOBuffer)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 final NIOBuffer nbuf = (NIOBuffer)buf;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 final ByteBuffer bbuf=nbuf.getByteBuffer().asReadOnlyBuffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 try
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 bbuf.position(buffer.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 bbuf.limit(buffer.putIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 len=_channel.write(bbuf);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 finally
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 if (len>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 buffer.skip(len);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 }
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 else if (buffer.array()!=null)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 ByteBuffer b = ByteBuffer.wrap(buffer.array(), buffer.getIndex(), buffer.length());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 len=_channel.write(b);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 if (len>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 buffer.skip(len);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 throw new IOException("Not Implemented");
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 return len;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
262
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
263 @Override
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
265 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 int length=0;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
267
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 Buffer buf0 = header==null?null:header.buffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 Buffer buf1 = buffer==null?null:buffer.buffer();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
270
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 if (_channel instanceof GatheringByteChannel &&
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 header!=null && header.length()!=0 && buf0 instanceof NIOBuffer &&
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
277 else
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 // flush header
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 if (header!=null && header.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 length=flush(header);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
282
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 // flush buffer
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 if ((header==null || header.length()==0) &&
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 buffer!=null && buffer.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 length+=flush(buffer);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
287
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 // flush trailer
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 if ((header==null || header.length()==0) &&
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 (buffer==null || buffer.length()==0) &&
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 trailer!=null && trailer.length()>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
292 length+=flush(trailer);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
294
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 return length;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
297
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
298 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
299 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 int length;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
301
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 synchronized(this)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 // Adjust position indexs of buf0 and buf1
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 bbuf0=bbuf0.asReadOnlyBuffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 bbuf0.position(header.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 bbuf0.limit(header.putIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 bbuf1=bbuf1.asReadOnlyBuffer();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 bbuf1.position(buffer.getIndex());
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 bbuf1.limit(buffer.putIndex());
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
311
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 _gather2[0]=bbuf0;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 _gather2[1]=bbuf1;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
314
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 // do the gathering write.
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
316 length=(int)((GatheringByteChannel)_channel).write(_gather2);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
317
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 int hl=header.length();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 if (length>hl)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 header.clear();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 buffer.skip(length-hl);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 }
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 else if (length>0)
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
326 header.skip(length);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 }
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 return length;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
330 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
331
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
332 public final SocketChannel getChannel()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 return _channel;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
336
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
337 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
338 public final String getLocalAddr()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 {
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
340 if (_local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 return StringUtil.ALL_INTERFACES;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 return _local.getAddress().getHostAddress();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
344
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
345 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
346 public final String getLocalHost()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 {
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
348 if (_local.getAddress()==null || _local.getAddress().isAnyLocalAddress())
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 return StringUtil.ALL_INTERFACES;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 return _local.getAddress().getCanonicalHostName();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
352
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
353 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
354 public final int getLocalPort()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 return _local.getPort();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
358
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
359 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
360 public final String getRemoteAddr()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 return _remote.getAddress().getHostAddress();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
364
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
365 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
366 public final String getRemoteHost()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 return _remote.getAddress().getCanonicalHostName();
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
370
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
371 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
372 public final int getRemotePort()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 {
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
374 return _remote.getPort();
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
376
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
377 @Override
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 public void flush()
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
379 throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
382
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
383 @Override
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
384 public final int getMaxIdleTime()
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 {
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 return _maxIdleTime;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
388
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
389 @Override
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 public void setMaxIdleTime(int timeMs) throws IOException
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 {
978
bdb6eb0fbf93 simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 965
diff changeset
392 if (timeMs!=_maxIdleTime)
873
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 _socket.setSoTimeout(timeMs>0?timeMs:0);
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394 _maxIdleTime=timeMs;
220ad4853cda remove StreamEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396 }