01: package org.apache.mina.transport.socket.apr;
02:
03: import java.net.InetSocketAddress;
04:
05: import org.apache.mina.common.DefaultTransportMetadata;
06: import org.apache.mina.common.IoBuffer;
07: import org.apache.mina.common.IoProcessor;
08: import org.apache.mina.common.IoService;
09: import org.apache.mina.common.RuntimeIoException;
10: import org.apache.mina.common.TransportMetadata;
11: import org.apache.mina.transport.socket.AbstractDatagramSessionConfig;
12: import org.apache.mina.transport.socket.DatagramSession;
13: import org.apache.mina.transport.socket.DatagramSessionConfig;
14: import org.apache.tomcat.jni.Socket;
15:
16: class AprDatagramSession extends AprSession implements DatagramSession {
17:
18: static final TransportMetadata METADATA = new DefaultTransportMetadata(
19: "apr", "datagram", true, false, InetSocketAddress.class,
20: DatagramSessionConfig.class, IoBuffer.class);
21:
22: private final DatagramSessionConfig config = new SessionConfigImpl();
23:
24: AprDatagramSession(IoService service,
25: IoProcessor<AprSession> processor, long descriptor,
26: InetSocketAddress remoteAddress) throws Exception {
27: super (service, processor, descriptor, remoteAddress);
28: this .config.setAll(service.getSessionConfig());
29: }
30:
31: public DatagramSessionConfig getConfig() {
32: return config;
33: }
34:
35: public TransportMetadata getTransportMetadata() {
36: return METADATA;
37: }
38:
39: private class SessionConfigImpl extends
40: AbstractDatagramSessionConfig {
41:
42: public boolean isReuseAddress() {
43: try {
44: return Socket.optGet(getDescriptor(),
45: Socket.APR_SO_REUSEADDR) == 1;
46: } catch (Exception e) {
47: throw new RuntimeIoException(
48: "Failed to get SO_REUSEADDR.", e);
49: }
50: }
51:
52: public void setReuseAddress(boolean on) {
53: Socket.optSet(getDescriptor(), Socket.APR_SO_REUSEADDR,
54: on ? 1 : 0);
55: }
56:
57: public int getTrafficClass() {
58: return 0;
59: }
60:
61: public void setTrafficClass(int tc) {
62: }
63:
64: public int getSendBufferSize() {
65: try {
66: return Socket.optGet(getDescriptor(),
67: Socket.APR_SO_SNDBUF);
68: } catch (Exception e) {
69: throw new RuntimeException("APR Exception", e);
70: }
71: }
72:
73: public void setSendBufferSize(int size) {
74: Socket.optSet(getDescriptor(), Socket.APR_SO_SNDBUF, size);
75: }
76:
77: public int getReceiveBufferSize() {
78: try {
79: return Socket.optGet(getDescriptor(),
80: Socket.APR_SO_RCVBUF);
81: } catch (Exception e) {
82: throw new RuntimeException("APR Exception", e);
83: }
84: }
85:
86: public void setReceiveBufferSize(int size) {
87: Socket.optSet(getDescriptor(), Socket.APR_SO_RCVBUF, size);
88: }
89:
90: public boolean isBroadcast() {
91: return false;
92: }
93:
94: public void setBroadcast(boolean broadcast) {
95: }
96: }
97: }
|