📄 aprsocketsession.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */package org.apache.mina.transport.socket.apr;import java.net.InetSocketAddress;import org.apache.mina.core.RuntimeIoException;import org.apache.mina.core.buffer.IoBuffer;import org.apache.mina.core.service.DefaultTransportMetadata;import org.apache.mina.core.service.IoProcessor;import org.apache.mina.core.service.IoService;import org.apache.mina.core.service.TransportMetadata;import org.apache.mina.core.session.IoSession;import org.apache.mina.core.session.IoSessionConfig;import org.apache.mina.transport.socket.AbstractSocketSessionConfig;import org.apache.mina.transport.socket.SocketSessionConfig;import org.apache.tomcat.jni.Socket;/** * An {@link IoSession} for APR TCP socket based session. * It's implementing the usual common features for {@SocketSession}. * * @author The Apache MINA Project (dev@mina.apache.org) * @version $Rev: 671827 $, $Date: 2008-06-26 10:49:48 +0200 (Thu, 26 Jun 2008) $ */class AprSocketSession extends AprSession { static final TransportMetadata METADATA = new DefaultTransportMetadata( "apr", "socket", false, true, InetSocketAddress.class, SocketSessionConfig.class, IoBuffer.class); private final SocketSessionConfig config = new SessionConfigImpl(); /** * Create an instance of {@link AprSocketSession}. * * {@inheritDoc} */ AprSocketSession( IoService service, IoProcessor<AprSession> processor, long descriptor) throws Exception { super(service, processor, descriptor); this.config.setAll(service.getSessionConfig()); } /** * {@inheritDoc} */ public SocketSessionConfig getConfig() { return config; } /** * {@inheritDoc} */ public TransportMetadata getTransportMetadata() { return METADATA; } /** * The implementation for the {@link IoSessionConfig} related to APR TCP socket. * @author The Apache MINA Project (dev@mina.apache.org) */ private class SessionConfigImpl extends AbstractSocketSessionConfig { /** * {@inheritDoc} */ public boolean isKeepAlive() { try { return Socket.optGet(getDescriptor(), Socket.APR_SO_KEEPALIVE) == 1; } catch (Exception e) { throw new RuntimeIoException("Failed to get SO_KEEPALIVE.", e); } } /** * {@inheritDoc} */ public void setKeepAlive(boolean on) { Socket.optSet(getDescriptor(), Socket.APR_SO_KEEPALIVE, on ? 1 : 0); } /** * {@inheritDoc} * not supported for the moment */ public boolean isOobInline() { return false; } /** * {@inheritDoc} * not supported for the moment */ public void setOobInline(boolean on) { } /** * {@inheritDoc} */ public boolean isReuseAddress() { try { return Socket.optGet(getDescriptor(), Socket.APR_SO_REUSEADDR) == 1; } catch (Exception e) { throw new RuntimeIoException("Failed to get SO_REUSEADDR.", e); } } /** * {@inheritDoc} */ public void setReuseAddress(boolean on) { Socket.optSet(getDescriptor(), Socket.APR_SO_REUSEADDR, on ? 1 : 0); } /** * {@inheritDoc} */ public int getSoLinger() { try { return Socket.optGet(getDescriptor(), Socket.APR_SO_LINGER); } catch (Exception e) { throw new RuntimeIoException("Failed to get SO_LINGER.", e); } } /** * {@inheritDoc} */ public void setSoLinger(int linger) { // TODO: Figure out how to disable this. Socket.optSet(getDescriptor(), Socket.APR_SO_LINGER, linger); } /** * {@inheritDoc} */ public boolean isTcpNoDelay() { try { return Socket.optGet(getDescriptor(), Socket.APR_TCP_NODELAY) == 1; } catch (Exception e) { throw new RuntimeIoException("Failed to get TCP_NODELAY.", e); } } /** * {@inheritDoc} */ public void setTcpNoDelay(boolean on) { Socket.optSet(getDescriptor(), Socket.APR_TCP_NODELAY, on ? 1 : 0); } /** * {@inheritDoc} */ public int getTrafficClass() { return 0; } /** * {@inheritDoc} */ public void setTrafficClass(int tc) { } /** * {@inheritDoc} */ public int getSendBufferSize() { try { return Socket.optGet(getDescriptor(), Socket.APR_SO_SNDBUF); } catch (Exception e) { throw new RuntimeException("APR Exception", e); } } /** * {@inheritDoc} */ public void setSendBufferSize(int size) { Socket.optSet(getDescriptor(), Socket.APR_SO_SNDBUF, size); } /** * {@inheritDoc} */ public int getReceiveBufferSize() { try { return Socket.optGet(getDescriptor(), Socket.APR_SO_RCVBUF); } catch (Exception e) { throw new RuntimeException("APR Exception", e); } } /** * {@inheritDoc} */ public void setReceiveBufferSize(int size) { Socket.optSet(getDescriptor(), Socket.APR_SO_RCVBUF, size); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -