class PseudoTcpSocketImpl extends SocketImpl implements PseudoTcpNotify
Modifier and Type | Class and Description |
---|---|
(package private) class |
PseudoTcpSocketImpl.PseudoTcpInputStream
This class implements java.io.InputStream
|
(package private) class |
PseudoTcpSocketImpl.PseudoTcpOutputStream
Implements java.io.OutputStream
|
Modifier and Type | Field and Description |
---|---|
private static ScheduledThreadPoolExecutor |
clockExecutor |
private Runnable |
clockTaskRunner |
private ScheduledFuture<?> |
currentlyScheduledClockTask |
private int |
DATAGRAM_RCV_BUFFER_SIZE
Receive buffer size used for receiving packets TODO: this should be
checked with MTU ?
|
private IOException |
exception
Exception which occurred in pseudotcp logic and must be propagated to
threads blocked on any operations.
|
private PseudoTcpSocketImpl.PseudoTcpInputStream |
inputStream |
private static Logger |
logger
The logger.
|
private Map<Integer,Object> |
options |
private PseudoTcpSocketImpl.PseudoTcpOutputStream |
outputstream |
private PseudoTCPBase |
pseudoTcp
Pseudotcp logic instance
|
private Object |
read_notify
Monitor object used to block threads on read operation.
|
private long |
readTimeout
Write operations timeout in ms
|
private Thread |
receiveThread
Thread receiving packets from the network
|
private SocketAddress |
remoteAddr
Current socket address of remote socket that we are connected to
|
private boolean |
runClock
The run flag for clock thread
|
private boolean |
runReceive
Flag which enables packets receive thread
|
private DatagramSocket |
socket
Datagram socket used to handle network operations
|
private Object |
state_notify
Monitor object used to block thread waiting for change of TCP state.
|
private Object |
write_notify
Monitor object used to block threads on write operation.
|
private long |
writeTimeout
Read operations timeout in ms
|
address, fd, localport, port
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
Constructor and Description |
---|
PseudoTcpSocketImpl(long conv_id)
This constructor creates DatagramSocket with random port.
|
PseudoTcpSocketImpl(long conv_id,
DatagramSocket sock) |
PseudoTcpSocketImpl(long conv_id,
int local_port)
Binds DatagramSocket to given local_port
|
PseudoTcpSocketImpl(long conv_id,
String local_ip,
int local_port)
Creates DatagramSocket for local_ip:local_port
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
accept(int timeout)
Blocking method waits for connection.
|
(package private) void |
accept(SocketAddress remoteAddress,
int timeout)
Blocking method waits for connection.
|
protected void |
accept(SocketImpl s)
Accepts a connection.
|
protected int |
available()
Returns the number of bytes that can be read from this socket without blocking.
|
void |
bind(InetAddress host,
int port)
Binds this socket to the specified port number on the specified host.
|
private void |
cancelClockTask(boolean interruptIfRunning) |
void |
close()
Closes this socket.
|
protected void |
connect(InetAddress address,
int port)
Connects this socket to the specified port number on the specified host.
|
protected void |
connect(SocketAddress address,
int timeout)
Connects this socket to the specified port number on the specified host.
|
protected void |
connect(String host,
int port)
Connects this socket to the specified port on the named host.
|
protected void |
create(boolean stream)
Creates either a stream or a datagram socket.
|
(package private) void |
doConnect(InetSocketAddress remoteAddress,
long timeout)
Start connection procedure
|
(package private) long |
getConversationID() |
protected FileDescriptor |
getFileDescriptor() |
protected InetAddress |
getInetAddress() |
InputStream |
getInputStream()
Returns an input stream for this socket.
|
protected int |
getLocalPort() |
int |
getMTU() |
Object |
getOption(int optID) |
OutputStream |
getOutputStream()
Returns an output stream for this socket.
|
protected int |
getPort() |
long |
getPTCPOption(Option opt) |
PseudoTcpState |
getState() |
private void |
joinAllThreads()
Joins all running threads
|
protected void |
listen(int backlog)
Sets the maximum queue length for incoming connection
indications (a request to connect) to the count argument.
|
void |
onTcpClosed(PseudoTCPBase tcp,
IOException e)
Implements PseudoTcpNotify
|
void |
onTcpOpen(PseudoTCPBase tcp)
Implements PseudoTcpNotify
Called when TCP enters connected state.
|
void |
onTcpReadable(PseudoTCPBase tcp)
Implements PseudoTcpNotify
|
void |
onTcpWriteable(PseudoTCPBase tcp)
Implements PseudoTcpNotify
|
private void |
receivePackets()
Receives packets from the network and passes them to TCP logic class
|
private void |
releaseAllLocks()
Releases all monitor objects so that the threads will check their "run
flags"
|
private void |
runClock()
Method runs cyclic notification about time progress for TCP logic class
It runs in a separate thread
|
private void |
scheduleClockTask(long sleep) |
protected void |
sendUrgentData(int data)
Send one byte of urgent data on the socket.
|
(package private) void |
setConversationID(long convID) |
void |
setDebugName(String debugName)
Sets debug name that will be displayed in log messages for this socket
|
void |
setMTU(int mtu)
Sets the MTU parameter for this socket
|
void |
setOption(int optID,
Object value) |
protected void |
setPerformancePreferences(int connectionTime,
int latency,
int bandwidth) |
void |
setPTCPOption(Option opt,
long optValue) |
protected void |
shutdownInput() |
protected void |
shutdownOutput() |
private void |
startThreads()
Starts all threads required by the socket
|
protected boolean |
supportsUrgentData() |
WriteResult |
tcpWritePacket(PseudoTCPBase tcp,
byte[] buffer,
int len)
Implements PseudoTcpNotify
|
private void |
updateClock()
Interrupts clock thread's wait method to force time update
|
toString
private static final Logger logger
private final PseudoTCPBase pseudoTcp
private DatagramSocket socket
private SocketAddress remoteAddr
private int DATAGRAM_RCV_BUFFER_SIZE
private final Object write_notify
private final Object read_notify
private final Object state_notify
private IOException exception
private long writeTimeout
private long readTimeout
private PseudoTcpSocketImpl.PseudoTcpInputStream inputStream
private PseudoTcpSocketImpl.PseudoTcpOutputStream outputstream
private boolean runReceive
private Thread receiveThread
private boolean runClock
private static final ScheduledThreadPoolExecutor clockExecutor
private volatile ScheduledFuture<?> currentlyScheduledClockTask
private Runnable clockTaskRunner
public PseudoTcpSocketImpl(long conv_id, DatagramSocket sock)
conv_id
- conversation id, must be the same on both sidessock
- datagram socket used for network operationspublic PseudoTcpSocketImpl(long conv_id) throws SocketException
conv_id
- conversation id, must be the same on both sidesSocketException
public PseudoTcpSocketImpl(long conv_id, int local_port) throws SocketException
conv_id
- conversation id, must be the same on both sideslocal_port
- the local port that will be used for this socketSocketException
public PseudoTcpSocketImpl(long conv_id, String local_ip, int local_port) throws SocketException, UnknownHostException
conv_id
- conversation id, must be the same on both sideslocal_ip
- used by DatagramSocketlocal_port
- used by DatagramSocketSocketException
UnknownHostException
public void setMTU(int mtu)
mtu
- the MTU valuepublic int getMTU()
long getConversationID()
void setConversationID(long convID)
public void setDebugName(String debugName)
debugName
- the debug name to setprotected void create(boolean stream) throws IOException
create
in class SocketImpl
stream
- if true, create a stream socket; otherwise, create a datagram socket.IOException
- if an I/O error occurs while creating the socket.protected void connect(String host, int port) throws IOException
connect
in class SocketImpl
host
- the name of the remote host.port
- the port number.IOException
protected void connect(InetAddress address, int port) throws IOException
connect
in class SocketImpl
address
- the IP address of the remote host.port
- the port number.IOException
- if an I/O error occurs when attempting a connection.protected void connect(SocketAddress address, int timeout) throws IOException
connect
in class SocketImpl
address
- the Socket address of the remote host.timeout
- the timeout value, in milliseconds, or zero for no timeout.IOException
- if an I/O error occurs when attempting a connection.public void bind(InetAddress host, int port) throws IOException
bind
in class SocketImpl
host
- the IP address of the remote host.port
- the port number.IOException
protected void listen(int backlog) throws IOException
listen
in class SocketImpl
backlog
- the maximum length of the queue.IOException
- if an I/O error occurs when creating the queue.public void setOption(int optID, Object value) throws SocketException
setOption
in interface SocketOptions
SocketException
public Object getOption(int optID) throws SocketException
getOption
in interface SocketOptions
SocketException
public long getPTCPOption(Option opt)
public void setPTCPOption(Option opt, long optValue)
void doConnect(InetSocketAddress remoteAddress, long timeout) throws IOException
remoteAddress
- to which this socket connects totimeout
- for this operation in msIOException
void accept(SocketAddress remoteAddress, int timeout) throws IOException
remoteAddress
- the one and only address that will be
accepted as the source for remote packetstimeout
- for this operation in msIOException
- If socket gets closed or timeout expiresvoid accept(int timeout) throws IOException
timeout
- for this operation in msIOException
- If socket gets closed or timeout expiresprotected void accept(SocketImpl s) throws IOException
accept
in class SocketImpl
s
- the accepted connection.IOException
- if an I/O error occurs when accepting the connection.public PseudoTcpState getState()
private void updateClock()
private void startThreads()
public void onTcpOpen(PseudoTCPBase tcp)
onTcpOpen
in interface PseudoTcpNotify
tcp
- the PseudoTCPBase
that caused an eventPseudoTcpNotify.onTcpOpen(PseudoTCPBase)
public void onTcpReadable(PseudoTCPBase tcp)
onTcpReadable
in interface PseudoTcpNotify
tcp
- the PseudoTCPBase
that caused an eventPseudoTcpNotify.onTcpReadable(PseudoTCPBase)
public void onTcpWriteable(PseudoTCPBase tcp)
onTcpWriteable
in interface PseudoTcpNotify
tcp
- the PseudoTCPBase
that caused an eventPseudoTcpNotify.onTcpWriteable(PseudoTCPBase)
public void onTcpClosed(PseudoTCPBase tcp, IOException e)
onTcpClosed
in interface PseudoTcpNotify
tcp
- the PseudoTCPBase
that caused an evente
- the Exception which is the reason for closing socket,
or null if there wasn't anyPseudoTcpNotify.onTcpClosed(PseudoTCPBase, IOException)
private void releaseAllLocks()
private void joinAllThreads() throws InterruptedException
InterruptedException
public WriteResult tcpWritePacket(PseudoTCPBase tcp, byte[] buffer, int len)
tcpWritePacket
in interface PseudoTcpNotify
tcp
- the PseudoTCPBase
that caused an eventbuffer
- the buffer containing packet datalen
- packet data length in bytesPseudoTcpNotify.tcpWritePacket(PseudoTCPBase, byte[], int)
private void receivePackets()
private void runClock()
private void scheduleClockTask(long sleep)
private void cancelClockTask(boolean interruptIfRunning)
public OutputStream getOutputStream() throws IOException
getOutputStream
in class SocketImpl
IOException
- if an I/O error occurs when creating the output stream.public InputStream getInputStream() throws IOException
getInputStream
in class SocketImpl
IOException
protected int available() throws IOException
available
in class SocketImpl
IOException
- if an I/O error occurs when determining the number of bytes available.public void close() throws IOException
close
in class SocketImpl
IOException
protected void sendUrgentData(int data) throws IOException
sendUrgentData
in class SocketImpl
data
- The byte of data to sendIOException
- if there is an error sending the data.protected FileDescriptor getFileDescriptor()
getFileDescriptor
in class SocketImpl
protected void shutdownInput() throws IOException
shutdownInput
in class SocketImpl
IOException
protected void shutdownOutput() throws IOException
shutdownOutput
in class SocketImpl
IOException
protected InetAddress getInetAddress()
getInetAddress
in class SocketImpl
protected int getPort()
getPort
in class SocketImpl
protected boolean supportsUrgentData()
supportsUrgentData
in class SocketImpl
protected int getLocalPort()
getLocalPort
in class SocketImpl
protected void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
setPerformancePreferences
in class SocketImpl
Copyright © 2018. All rights reserved.