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