Home | History | Annotate | Download | only in jsse
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package org.apache.harmony.xnet.provider.jsse;
     19 
     20 import java.io.IOException;
     21 import java.net.InetAddress;
     22 import java.net.Socket;
     23 import java.net.SocketAddress;
     24 import java.net.SocketException;
     25 
     26 /**
     27  * This class wraps the SSL functionality over an existing connected socket.
     28  */
     29 public class OpenSSLSocketImplWrapper extends OpenSSLSocketImpl {
     30 
     31     private Socket socket;
     32 
     33     protected OpenSSLSocketImplWrapper(Socket socket, String host, int port,
     34             boolean autoClose, SSLParametersImpl sslParameters) throws IOException {
     35         super(socket, host, port, autoClose, sslParameters);
     36         if (!socket.isConnected()) {
     37             throw new SocketException("Socket is not connected.");
     38         }
     39         this.socket = socket;
     40     }
     41 
     42     @Override
     43     public void connect(SocketAddress sockaddr, int timeout)
     44         throws IOException {
     45         throw new IOException("Underlying socket is already connected.");
     46     }
     47 
     48     @Override
     49     public void connect(SocketAddress sockaddr) throws IOException {
     50         throw new IOException("Underlying socket is already connected.");
     51     }
     52 
     53     @Override
     54     public void bind(SocketAddress sockaddr) throws IOException {
     55         throw new IOException("Underlying socket is already connected.");
     56     }
     57 
     58     @Override
     59     public SocketAddress getRemoteSocketAddress() {
     60         return socket.getRemoteSocketAddress();
     61     }
     62 
     63     @Override
     64     public SocketAddress getLocalSocketAddress() {
     65         return socket.getLocalSocketAddress();
     66     }
     67 
     68     @Override
     69     public InetAddress getLocalAddress() {
     70         return socket.getLocalAddress();
     71     }
     72 
     73     @Override
     74     public InetAddress getInetAddress() {
     75         return socket.getInetAddress();
     76     }
     77 
     78     @Override
     79     public String toString() {
     80         return "SSL socket over " + socket.toString();
     81     }
     82 
     83     @Override
     84     public void setSoLinger(boolean on, int linger) throws SocketException {
     85         socket.setSoLinger(on, linger);
     86     }
     87 
     88     @Override
     89     public void setTcpNoDelay(boolean on) throws SocketException {
     90         socket.setTcpNoDelay(on);
     91     }
     92 
     93     @Override
     94     public void setReuseAddress(boolean on) throws SocketException {
     95         socket.setReuseAddress(on);
     96     }
     97 
     98     @Override
     99     public void setKeepAlive(boolean on) throws SocketException {
    100         socket.setKeepAlive(on);
    101     }
    102 
    103     @Override
    104     public void setTrafficClass(int tos) throws SocketException {
    105         socket.setTrafficClass(tos);
    106     }
    107 
    108     @Override
    109     public void setSoTimeout(int to) throws SocketException {
    110         socket.setSoTimeout(to);
    111         super.setSoTimeout(to);
    112     }
    113 
    114     @Override
    115     public void setSendBufferSize(int size) throws SocketException {
    116         socket.setSendBufferSize(size);
    117     }
    118 
    119     @Override
    120     public void setReceiveBufferSize(int size) throws SocketException {
    121         socket.setReceiveBufferSize(size);
    122     }
    123 
    124     @Override
    125     public boolean getTcpNoDelay() throws SocketException {
    126         return socket.getTcpNoDelay();
    127     }
    128 
    129     @Override
    130     public boolean getReuseAddress() throws SocketException {
    131         return socket.getReuseAddress();
    132     }
    133 
    134     @Override
    135     public boolean getOOBInline() throws SocketException {
    136         return socket.getOOBInline();
    137     }
    138 
    139     @Override
    140     public boolean getKeepAlive() throws SocketException {
    141         return socket.getKeepAlive();
    142     }
    143 
    144     @Override
    145     public int getTrafficClass() throws SocketException {
    146         return socket.getTrafficClass();
    147     }
    148 
    149     @Override
    150     public int getSoTimeout() throws SocketException {
    151         return socket.getSoTimeout();
    152     }
    153 
    154     @Override
    155     public int getSoLinger() throws SocketException {
    156         return socket.getSoLinger();
    157     }
    158 
    159     @Override
    160     public int getSendBufferSize() throws SocketException {
    161         return socket.getSendBufferSize();
    162     }
    163 
    164     @Override
    165     public int getReceiveBufferSize() throws SocketException {
    166         return socket.getReceiveBufferSize();
    167     }
    168 
    169     @Override
    170     public boolean isConnected() {
    171         return socket.isConnected();
    172     }
    173 
    174     @Override
    175     public boolean isClosed() {
    176         return socket.isClosed();
    177     }
    178 
    179     @Override
    180     public boolean isBound() {
    181         return socket.isBound();
    182     }
    183 
    184     @Override
    185     public boolean isOutputShutdown() {
    186         return socket.isOutputShutdown();
    187     }
    188 
    189     @Override
    190     public boolean isInputShutdown() {
    191         return socket.isInputShutdown();
    192     }
    193 
    194     @Override
    195     public int getPort() {
    196         return socket.getPort();
    197     }
    198 
    199     @Override
    200     public int getLocalPort() {
    201         return socket.getLocalPort();
    202     }
    203 }
    204