java.lang.Object
org.codelibs.jcifs.smb1.util.transport.Transport
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SmbTransport
This class simplifies communication for protocols that support
multiplexing requests. It encapsulates a stream and some protocol
knowledge (provided by a concrete subclass) so that connecting,
disconnecting, sending, and receiving can be syncronized
properly. Apparatus is provided to send and receive requests
concurrently.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected HashMapMap of pending requests to their corresponding responses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(long timeout) Establishes a connection to the remote endpoint.voiddisconnect(boolean hard) Disconnects from the remote endpoint.protected abstract voidEstablishes a connection to the remote endpoint.protected abstract voiddoDisconnect(boolean hard) Tears down the connection to the remote endpoint.protected abstract voidReceives a response from the remote endpoint.protected abstract voidSends a request to the remote endpoint.protected abstract voiddoSkip()Skips an unexpected or unrecognized message.protected abstract voidCreates a key for the specified request for response matching.protected abstract RequestpeekKey()Reads and returns the key of the next message without consuming it.static intreadn(InputStream in, byte[] b, int off, int len) Reads exactly len bytes from the input stream into the buffer.voidrun()voidSends a request and waits for the corresponding response.toString()
-
Field Details
-
response_map
Map of pending requests to their corresponding responses.
-
-
Constructor Details
-
Transport
public Transport()Default constructor for Transport.
-
-
Method Details
-
readn
Reads exactly len bytes from the input stream into the buffer.- Parameters:
in- the input stream to read fromb- the buffer to read intooff- the offset in the buffer to start writinglen- the number of bytes to read- Returns:
- the number of bytes actually read
- Throws:
IOException- if an I/O error occurs
-
makeKey
Creates a key for the specified request for response matching.- Parameters:
request- the request to create a key for- Throws:
IOException- if an I/O error occurs
-
peekKey
Reads and returns the key of the next message without consuming it.- Returns:
- the request key of the next message
- Throws:
IOException- if an I/O error occurs
-
doSend
Sends a request to the remote endpoint.- Parameters:
request- the request to send- Throws:
IOException- if an I/O error occurs
-
doRecv
Receives a response from the remote endpoint.- Parameters:
response- the response object to populate- Throws:
IOException- if an I/O error occurs
-
doSkip
Skips an unexpected or unrecognized message.- Throws:
IOException- if an I/O error occurs
-
sendrecv
Sends a request and waits for the corresponding response.- Parameters:
request- the request to sendresponse- the response object to populatetimeout- the maximum time to wait for the response in milliseconds- Throws:
IOException- if an I/O error occurs during communication
-
doConnect
Establishes a connection to the remote endpoint.- Throws:
Exception- if the connection fails
-
doDisconnect
Tears down the connection to the remote endpoint.- Parameters:
hard- if true, disconnect immediately without waiting for outstanding requests- Throws:
IOException- if an I/O error occurs
-
connect
Establishes a connection to the remote endpoint.- Parameters:
timeout- the maximum time to wait for the connection in milliseconds- Throws:
TransportException- if the connection fails or times out
-
disconnect
Disconnects from the remote endpoint.- Parameters:
hard- if true, disconnect immediately without waiting for outstanding requests- Throws:
IOException- if an I/O error occurs during disconnection
-
run
public void run() -
toString
-