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