java.lang.Object
net.i2p.client.streaming.impl.I2PSocketFull
- All Implemented Interfaces:
Closeable, AutoCloseable, I2PSocket
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicBooleanTrue once the event has been consumed.private ConnectionThe connection the socket is full on, if any.private final DestinationThe local end of the connection.private final DestinationThe remote end of the connection.private final LogLogger for this class.Constructor Summary
ConstructorsConstructorDescriptionI2PSocketFull(Connection con, I2PAppContext context) Bridge between a connection and the I2PSocket API.Method Summary
Public MethodsModifier and TypeMethodDescriptionvoidclose()Closes this socket.(package private) voiddestroy()Release the connection reference.(package private) voiddestroy2()Call fromConnection.disconnectComplete().(package private) ConnectionUnderlying connection.Stream for data received on this connection.longTotal bytes received over the socket's lifetime.longTotal bytes sent over the socket's lifetime.intThe local port.Socket options for this socket.Output stream for sending data over this connection.Gets the remote peer's destination.intgetPort()The remote port.longRead timeout for this socket.Gets this side's destination.booleanisClosed()Whether the socket is closed or not connected.voidreset()Resets and closes this socket.voidsetOptions(I2PSocketOptions options) New socket options.voidsetReadTimeout(long ms) Read timeout in milliseconds.toString()Description of this socket.
Field Details
log
Logger for this class._connection
The connection the socket is full on, if any._remotePeer
The remote end of the connection._localPeer
The local end of the connection._closed
True once the event has been consumed.
Constructor Details
I2PSocketFull
Bridge between a connection and the I2PSocket API.- Parameters:
con- the underlying connection, may be nullcontext- the I2P application context
Method Details
close
Closes this socket.Nonblocking: Any thread currently blocked in an I/O operation upon this socket will throw an IOException. Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created. Closing this socket will also close the socket's InputStream and OutputStream.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs
reset
Resets and closes this socket. Sends a RESET indication to the far-end. This is the equivalent of setSoLinger(true, 0) followed byclose()on a Java Socket.Nonblocking. Any thread currently blocked in an I/O operation upon this socket will throw an IOException. Once a socket has been reset, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created. Resetting this socket will also close the socket's InputStream and OutputStream.
- Specified by:
resetin interfaceI2PSocket- Throws:
IOException- if an I/O error occurs
getConnection
Connection getConnection()Underlying connection.- Returns:
- the Connection carrying this socket's packets
getInputStream
Stream for data received on this connection.- Specified by:
getInputStreamin interfaceI2PSocket- Returns:
- non-null input stream
- Throws:
IOException- if the socket is closed
getOptions
Socket options for this socket.- Specified by:
getOptionsin interfaceI2PSocket- Returns:
- the socket options, or null if the socket is closed
getOutputStream
Output stream for sending data over this connection.- Specified by:
getOutputStreamin interfaceI2PSocket- Returns:
- non-null output stream
- Throws:
IOException- if the socket is closed
getPeerDestination
Gets the remote peer's destination.- Specified by:
getPeerDestinationin interfaceI2PSocket- Returns:
- the destination at the other end of the connection
getReadTimeout
public long getReadTimeout()Read timeout for this socket.- Specified by:
getReadTimeoutin interfaceI2PSocket- Returns:
- the read timeout in milliseconds, or -1 if no options are set
getThisDestination
Gets this side's destination.- Specified by:
getThisDestinationin interfaceI2PSocket- Returns:
- the destination of the local session
setOptions
New socket options.- Specified by:
setOptionsin interfaceI2PSocket- Parameters:
options- the new socket options
setReadTimeout
public void setReadTimeout(long ms) Read timeout in milliseconds.- Specified by:
setReadTimeoutin interfaceI2PSocket- Parameters:
ms- the read timeout in milliseconds
isClosed
destroy
void destroy()Release the connection reference.destroy2
void destroy2()Call fromConnection.disconnectComplete().getPort
getLocalPort
public int getLocalPort()The local port.- Specified by:
getLocalPortin interfaceI2PSocket- Returns:
- the port or 0 if unknown
getLifetimeBytesSent
public long getLifetimeBytesSent()Total bytes sent over the socket's lifetime.- Specified by:
getLifetimeBytesSentin interfaceI2PSocket- Returns:
- total bytes sent over this socket's lifetime, or 0 if not connected
getLifetimeBytesReceived
public long getLifetimeBytesReceived()Total bytes received over the socket's lifetime.- Specified by:
getLifetimeBytesReceivedin interfaceI2PSocket- Returns:
- total bytes received over this socket's lifetime, or 0 if not connected
toString