FileDocCategorySizeDatePackage
SocketHttpServerConnection.javaAPI DocAndroid 1.5 API6152Wed May 06 22:41:10 BST 2009org.apache.http.impl

SocketHttpServerConnection

public class SocketHttpServerConnection extends AbstractHttpServerConnection implements HttpInetConnection
Implementation of a server-side HTTP connection that can be bound to a network Socket in order to receive and transmit data.
author
Oleg Kalnichevski
version
$Revision: 561083 $
since
4.0

Fields Summary
private volatile boolean
open
private Socket
socket
Constructors Summary
public SocketHttpServerConnection()

    
      
        super();
    
Methods Summary
protected voidassertNotOpen()

        if (this.open) {
            throw new IllegalStateException("Connection is already open");
        }
    
protected voidassertOpen()

        if (!this.open) {
            throw new IllegalStateException("Connection is not open");
        }
    
protected voidbind(java.net.Socket socket, org.apache.http.params.HttpParams params)

        if (socket == null) {
            throw new IllegalArgumentException("Socket may not be null");
        }
        if (params == null) {
            throw new IllegalArgumentException("HTTP parameters may not be null");
        }
        this.socket = socket;
        
        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
        
        init(
                createHttpDataReceiver(socket, buffersize, params), 
                createHttpDataTransmitter(socket, buffersize, params),
                params);
        
        this.open = true;
    
public voidclose()

        if (!this.open) {
            return;
        }
        this.open = false;
        doFlush();
        try {
            this.socket.shutdownOutput();
        } catch (IOException ignore) {
        }
        try {
            this.socket.shutdownInput();
        } catch (IOException ignore) {
        }
        this.socket.close();
    
protected org.apache.http.io.SessionInputBuffercreateHttpDataReceiver(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)

        return new SocketInputBuffer(socket, buffersize, params);
    
protected org.apache.http.io.SessionOutputBuffercreateHttpDataTransmitter(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)

        return new SocketOutputBuffer(socket, buffersize, params);
    
public java.net.InetAddressgetLocalAddress()

        if (this.socket != null) {
            return this.socket.getLocalAddress();
        } else {
            return null;
        }
    
public intgetLocalPort()

        if (this.socket != null) {
            return this.socket.getLocalPort();
        } else {
            return -1;
        }
    
public java.net.InetAddressgetRemoteAddress()

        if (this.socket != null) {
            return this.socket.getInetAddress();
        } else {
            return null;
        }
    
public intgetRemotePort()

        if (this.socket != null) {
            return this.socket.getPort();
        } else {
            return -1;
        }
    
protected java.net.SocketgetSocket()

        return this.socket;
    
public intgetSocketTimeout()

        if (this.socket != null) {
            try {
                return this.socket.getSoTimeout();
            } catch (SocketException ignore) {
                return -1;
            }
        } else {
            return -1;
        }
    
public booleanisOpen()

        return this.open;
    
public voidsetSocketTimeout(int timeout)

        assertOpen();
        if (this.socket != null) {
            try {
                this.socket.setSoTimeout(timeout);
            } catch (SocketException ignore) {
                // It is not quite clear from the Sun's documentation if there are any 
                // other legitimate cases for a socket exception to be thrown when setting 
                // SO_TIMEOUT besides the socket being already closed
            }
        }
    
public voidshutdown()

        this.open = false;
        Socket tmpsocket = this.socket;
        if (tmpsocket != null) {
            tmpsocket.close();
        }