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.transport.socket.AbstractDatagramSessionConfig;
32 import org.apache.mina.transport.socket.DatagramSessionConfig;
33 import org.apache.tomcat.jni.Socket;
34
35
36
37
38
39
40
41 class AprDatagramSession extends AprSession {
42
43 static final TransportMetadata METADATA =
44 new DefaultTransportMetadata(
45 "apr", "datagram", true, false,
46 InetSocketAddress.class,
47 DatagramSessionConfig.class, IoBuffer.class);
48
49 private final DatagramSessionConfig config = new SessionConfigImpl();
50
51
52
53
54
55
56 AprDatagramSession(
57 IoService service, IoProcessor<AprSession> processor,
58 long descriptor, InetSocketAddress remoteAddress) throws Exception {
59 super(service, processor, descriptor, remoteAddress);
60 this.config.setAll(service.getSessionConfig());
61 }
62
63
64
65
66 public DatagramSessionConfig 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 AbstractDatagramSessionConfig {
82
83
84
85 public boolean isReuseAddress() {
86 try {
87 return Socket.optGet(getDescriptor(), Socket.APR_SO_REUSEADDR) == 1;
88 } catch (Exception e) {
89 throw new RuntimeIoException("Failed to get SO_REUSEADDR.", e);
90 }
91 }
92
93
94
95
96 public void setReuseAddress(boolean on) {
97 Socket.optSet(getDescriptor(), Socket.APR_SO_REUSEADDR, on ? 1 : 0);
98 }
99
100
101
102
103 public int getTrafficClass() {
104 return 0;
105 }
106
107
108
109
110 public void setTrafficClass(int tc) {
111 }
112
113
114
115
116 public int getSendBufferSize() {
117 try {
118 return Socket.optGet(getDescriptor(), Socket.APR_SO_SNDBUF);
119 } catch (Exception e) {
120 throw new RuntimeException("APR Exception", e);
121 }
122 }
123
124
125
126
127 public void setSendBufferSize(int size) {
128 Socket.optSet(getDescriptor(), Socket.APR_SO_SNDBUF, size);
129 }
130
131
132
133
134 public int getReceiveBufferSize() {
135 try {
136 return Socket.optGet(getDescriptor(), Socket.APR_SO_RCVBUF);
137 } catch (Exception e) {
138 throw new RuntimeException("APR Exception", e);
139 }
140 }
141
142
143
144
145 public void setReceiveBufferSize(int size) {
146 Socket.optSet(getDescriptor(), Socket.APR_SO_RCVBUF, size);
147 }
148
149
150
151
152 public boolean isBroadcast() {
153 return false;
154 }
155
156
157
158
159 public void setBroadcast(boolean broadcast) {
160 }
161 }
162 }