ch.configureBlocking(false);
} catch (IOException e) {
throw new MinaRuntimeException("can't configure socket as non-blocking", e);
}
UdpSessionConfig config = getSessionConfig();
NioSelectorLoop loop = (NioSelectorLoop) readWriteSelectorPool.getSelectorLoop();
NioUdpSession session = new NioUdpSession(this, idleChecker, ch, null, remoteAddress, loop);
session.setConnected();
// apply idle configuration
session.getConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
session.getConfig().setIdleTimeInMillis(IdleStatus.WRITE_IDLE,
config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));
// Manage the Idle status
idleChecker.sessionRead(session, System.currentTimeMillis());
idleChecker.sessionWritten(session, System.currentTimeMillis());
// apply the default service socket configuration
Boolean reuseAddress = config.isReuseAddress();
if (reuseAddress != null) {
session.getConfig().setReuseAddress(reuseAddress);
}
Integer readBufferSize = config.getReadBufferSize();
if (readBufferSize != null) {
session.getConfig().setReadBufferSize(readBufferSize);
} else {
int rcvBufferSize;
try {
rcvBufferSize = ch.socket().getReceiveBufferSize();
session.getConfig().setReadBufferSize(rcvBufferSize);
} catch (SocketException e) {
throw new MinaRuntimeException("can't configure socket receive buffer size", e);
}
}
Integer sendBufferSize = config.getSendBufferSize();
if (sendBufferSize != null) {
session.getConfig().setSendBufferSize(sendBufferSize);
} else {
int sndBufferSize;
try {
sndBufferSize = ch.socket().getSendBufferSize();
session.getConfig().setSendBufferSize(sndBufferSize);
} catch (SocketException e) {
throw new MinaRuntimeException("can't configure socket send buffe size", e);
}
}
Integer trafficClass = config.getTrafficClass();
if (trafficClass != null) {
session.getConfig().setTrafficClass(trafficClass);
}