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