Package org.apache.tomcat.jni.socket
Class AprSocket
- java.lang.Object
-
- org.apache.tomcat.jni.socket.AprSocket
-
- All Implemented Interfaces:
Runnable
public class AprSocket extends Object implements Runnable
Native socket, using JNI + APR + openssl. The socket is non-blocking - you can register either a blocking or non blocking callback. There is no explicit method to register/unregister poll interest - it is done automatically, when read/write methods return 0. To keep the socket polling you must read all the available data, until read() returns 0. If you want to pause - don't read all input. To resume - read again until it returns 0. Same for write - when write() returns 0 the socket is registered for write interest. You can also use the blocking read/write methods.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
blockingStartTLS()
This is a blocking call ! ( can be made non-blocking, but too complex ) Will be called automatically after connect() or accept if 'secure' is true.void
close()
void
connect()
String
getCipherSuite()
AprSocketContext
getContext()
AprSocketContext.BlockingPollHandler
getHandler()
HostInfo
getHost()
long
getIOTimeout()
int
getKeySize()
String
getLocalAddress()
String
getLocalHostname()
int
getLocalPort()
byte[][]
getPeerCert(boolean check)
X509Certificate[]
getPeerX509Cert()
String
getRemoteAddress()
String
getRemoteHostname()
int
getRemotePort()
boolean
isBlocking()
boolean
isClosed()
boolean
isError()
boolean
isPolling()
Check if the socket is currently registered with a poller.int
read(byte[] data, int off, int len)
int
read(byte[] data, int off, int len, long to)
int
readNB(byte[] data, int off, int len)
void
recycle()
void
reset()
Close input and output, potentially sending RST, than close the socket.void
run()
void
setHandler(AprSocketContext.BlockingPollHandler l)
String
toString()
int
write(byte[] data, int off, int len)
int
write(byte[] data, int off, int len, long to)
Write as much data as possible to the socket.
-
-
-
Method Detail
-
recycle
public void recycle()
-
setHandler
public void setHandler(AprSocketContext.BlockingPollHandler l)
-
isPolling
public boolean isPolling()
Check if the socket is currently registered with a poller.
-
getHandler
public AprSocketContext.BlockingPollHandler getHandler()
-
getContext
public AprSocketContext getContext()
-
connect
public void connect() throws IOException
- Throws:
IOException
-
getHost
public HostInfo getHost()
-
write
public int write(byte[] data, int off, int len, long to) throws IOException
Write as much data as possible to the socket.- Parameters:
data
-off
-len
-- Returns:
- For both blocking and non-blocking, returns the number of bytes written. If no data can be written (e.g. if the buffers are full) 0 will be returned.
- Throws:
IOException
-
write
public int write(byte[] data, int off, int len) throws IOException
- Throws:
IOException
-
read
public int read(byte[] data, int off, int len, long to) throws IOException
- Throws:
IOException
-
read
public int read(byte[] data, int off, int len) throws IOException
- Throws:
IOException
-
readNB
public int readNB(byte[] data, int off, int len) throws IOException
- Throws:
IOException
-
close
public void close()
-
reset
public void reset()
Close input and output, potentially sending RST, than close the socket. The proper way to close when gracefully done is by calling writeEnd() and reading all remaining input until -1 (EOF) is received. If EOF is received, the proper way to close is send whatever is remaining and call writeEnd();
-
isClosed
public boolean isClosed()
-
getIOTimeout
public long getIOTimeout() throws IOException
- Throws:
IOException
-
getPeerCert
public byte[][] getPeerCert(boolean check) throws IOException
- Throws:
IOException
-
getPeerX509Cert
public X509Certificate[] getPeerX509Cert() throws IOException
- Throws:
IOException
-
getCipherSuite
public String getCipherSuite() throws IOException
- Throws:
IOException
-
getKeySize
public int getKeySize() throws IOException
- Throws:
IOException
-
getRemotePort
public int getRemotePort() throws IOException
- Throws:
IOException
-
getRemoteAddress
public String getRemoteAddress() throws IOException
- Throws:
IOException
-
getRemoteHostname
public String getRemoteHostname() throws IOException
- Throws:
IOException
-
getLocalPort
public int getLocalPort() throws IOException
- Throws:
IOException
-
getLocalAddress
public String getLocalAddress() throws IOException
- Throws:
IOException
-
getLocalHostname
public String getLocalHostname() throws IOException
- Throws:
IOException
-
isBlocking
public boolean isBlocking()
-
isError
public boolean isError()
-
blockingStartTLS
public void blockingStartTLS() throws IOException
This is a blocking call ! ( can be made non-blocking, but too complex ) Will be called automatically after connect() or accept if 'secure' is true. Can be called manually to upgrade the channel- Throws:
IOException
-
-