1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.transport.socket.apr;
21
22 import java.net.InetSocketAddress;
23
24 import org.apache.mina.core.RuntimeIoException;
25 import org.apache.mina.core.buffer.IoBuffer;
26 import org.apache.mina.core.service.DefaultTransportMetadata;
27 import org.apache.mina.core.service.IoProcessor;
28 import org.apache.mina.core.service.IoService;
29 import org.apache.mina.core.service.TransportMetadata;
30 import org.apache.mina.core.session.IoSession;
31 import org.apache.mina.core.session.IoSessionConfig;
32 import org.apache.mina.transport.socket.AbstractSocketSessionConfig;
33 import org.apache.mina.transport.socket.SocketSessionConfig;
34 import org.apache.tomcat.jni.Socket;
35
36
37
38
39
40
41
42 class AprSocketSession extends AprSession {
43 static final TransportMetadata METADATA =
44 new DefaultTransportMetadata(
45 "apr", "socket", false, true,
46 InetSocketAddress.class,
47 SocketSessionConfig.class,
48 IoBuffer.class);
49
50 private final SocketSessionConfig config = new SessionConfigImpl();
51
52
53
54
55
56
57 AprSocketSession(
58 IoService service, IoProcessor<AprSession> processor, long descriptor) throws Exception {
59 super(service, processor, descriptor);
60 this.config.setAll(service.getSessionConfig());
61 }
62
63
64
65
66 public SocketSessionConfig getConfig() {
67 return config;
68 }
69
70
71
72
73 public TransportMetadata getTransportMetadata() {
74 return METADATA;
75 }
76
77
78
79
80
81 private class SessionConfigImpl extends AbstractSocketSessionConfig {
82
83
84
85 public boolean isKeepAlive() {
86 try {
87 return Socket.optGet(getDescriptor(), Socket.APR_SO_KEEPALIVE) == 1;
88 } catch (Exception e) {
89 throw new RuntimeIoException("Failed to get SO_KEEPALIVE.", e);
90 }
91 }
92
93
94
95
96 public void setKeepAlive(boolean on) {
97 Socket.optSet(getDescriptor(), Socket.APR_SO_KEEPALIVE, on ? 1 : 0);
98 }
99
100
101
102
103
104 public boolean isOobInline() {
105 return false;
106 }
107
108
109
110
111
112 public void setOobInline(boolean on) {
113 }
114
115
116
117
118 public boolean isReuseAddress() {
119 try {
120 return Socket.optGet(getDescriptor(), Socket.APR_SO_REUSEADDR) == 1;
121 } catch (Exception e) {
122 throw new RuntimeIoException("Failed to get SO_REUSEADDR.", e);
123 }
124 }
125
126
127
128
129 public void setReuseAddress(boolean on) {
130 Socket.optSet(getDescriptor(), Socket.APR_SO_REUSEADDR, on ? 1 : 0);
131 }
132
133
134
135
136 public int getSoLinger() {
137 try {
138 return Socket.optGet(getDescriptor(), Socket.APR_SO_LINGER);
139 } catch (Exception e) {
140 throw new RuntimeIoException("Failed to get SO_LINGER.", e);
141 }
142 }
143
144
145
146
147 public void setSoLinger(int linger) {
148
149 Socket.optSet(getDescriptor(), Socket.APR_SO_LINGER, linger);
150 }
151
152
153
154
155 public boolean isTcpNoDelay() {
156 try {
157 return Socket.optGet(getDescriptor(), Socket.APR_TCP_NODELAY) == 1;
158 } catch (Exception e) {
159 throw new RuntimeIoException("Failed to get TCP_NODELAY.", e);
160 }
161 }
162
163
164
165
166 public void setTcpNoDelay(boolean on) {
167 Socket.optSet(getDescriptor(), Socket.APR_TCP_NODELAY, on ? 1 : 0);
168 }
169
170
171
172
173 public int getTrafficClass() {
174 return 0;
175 }
176
177
178
179
180 public void setTrafficClass(int tc) {
181 }
182
183
184
185
186 public int getSendBufferSize() {
187 try {
188 return Socket.optGet(getDescriptor(), Socket.APR_SO_SNDBUF);
189 } catch (Exception e) {
190 throw new RuntimeException("APR Exception", e);
191 }
192 }
193
194
195
196
197 public void setSendBufferSize(int size) {
198 Socket.optSet(getDescriptor(), Socket.APR_SO_SNDBUF, size);
199 }
200
201
202
203
204 public int getReceiveBufferSize() {
205 try {
206 return Socket.optGet(getDescriptor(), Socket.APR_SO_RCVBUF);
207 } catch (Exception e) {
208 throw new RuntimeException("APR Exception", e);
209 }
210 }
211
212
213
214
215 public void setReceiveBufferSize(int size) {
216 Socket.optSet(getDescriptor(), Socket.APR_SO_RCVBUF, size);
217 }
218 }
219 }