java.lang.Object
org.codelibs.jcifs.smb.util.transport.Transport
- All Implemented Interfaces:
AutoCloseable,Runnable
Abstract base class for network transport implementations in JCIFS.
This class handles the low-level transport protocol for SMB communication.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ObjectLock object for synchronizing input operationsprotected StringName identifier for this transport instanceprotected final ObjectLock object for synchronizing output operationsMap for tracking pending responses by their keyprotected intCurrent state of the transport connection -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquire()Acquires a reference to this transport, incrementing the usage count.voidclose()booleanconnect(long timeout) Connect the transportbooleandisconnect(boolean hard) Disconnect the transportbooleandisconnect(boolean hard, boolean inUse) Disconnect the transportprotected abstract voidEstablish the transport connectionprotected abstract booleandoDisconnect(boolean hard, boolean inUse) Disconnect the transport connectionprotected abstract voidReceive a response from the transportprotected abstract voidSend a request over the transportprotected <T extends Response>
longdoSend(Request request, T response, Set<RequestParam> params, long timeout) Sends a request and manages the response handling.protected abstract voidSkip a response with the given keyprotected voidfinalize()protected abstract intgetResponseTimeout(Request request) Gets the response timeout for a specific request.protected longGets the current usage count for this transport.protected <T extends Response>
booleanhandleIntermediate(Request request, T response) Handles intermediate responses during request processing.booleanChecks if the transport is disconnected.booleanisFailed()Checks if the transport is in a failed state.protected abstract longGenerate a unique key for the given requestprotected abstract LongpeekKey()Peek at the next key without removing it from the input streamstatic intreadn(InputStream in, byte[] b, int off, int len) Read bytes from the input stream into a buffervoidrelease()Releases a reference to this transport, decrementing the usage count.voidrun()<T extends Response>
Tsendrecv(Request request, T response, Set<RequestParam> params) Send a request message and recieve responsetoString()
-
Field Details
-
state
protected volatile int stateCurrent state of the transport connection -
name
Name identifier for this transport instance -
inLock
Lock object for synchronizing input operations -
outLock
Lock object for synchronizing output operations -
response_map
Map for tracking pending responses by their key
-
-
Constructor Details
-
Transport
protected Transport()Default constructor for Transport
-
-
Method Details
-
readn
Read bytes from the input stream into a 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:
- number of bytes read
- Throws:
IOException- if an I/O error occurs
-
acquire
Acquires a reference to this transport, incrementing the usage count.- Returns:
- session increased usage count
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- See Also:
-
release
public void release()Releases a reference to this transport, decrementing the usage count. -
finalize
-
getUsageCount
protected long getUsageCount()Gets the current usage count for this transport.- Returns:
- the number of known usages
-
makeKey
Generate a unique key for the given request- Parameters:
request- the request to generate a key for- Returns:
- the generated key
- Throws:
IOException- if an I/O error occurs
-
peekKey
Peek at the next key without removing it from the input stream- Returns:
- the next key or null if none available
- Throws:
IOException- if an I/O error occurs
-
doSend
Send a request over the transport- Parameters:
request- the request to send- Throws:
IOException- if an I/O error occurs
-
doRecv
Receive a response from the transport- Parameters:
response- the response object to populate- Throws:
IOException- if an I/O error occurs
-
doSkip
Skip a response with the given key- Parameters:
key- the key of the response to skip- Throws:
IOException- if an I/O error occurs
-
isDisconnected
public boolean isDisconnected()Checks if the transport is disconnected.- Returns:
- whether the transport is disconnected
-
isFailed
public boolean isFailed()Checks if the transport is in a failed state.- Returns:
- whether the transport is marked failed
-
sendrecv
public <T extends Response> T sendrecv(Request request, T response, Set<RequestParam> params) throws IOException Send a request message and recieve response- Type Parameters:
T- the response type- Parameters:
request- the request to sendresponse- the response object to populateparams- additional parameters for the request- Returns:
- the response
- Throws:
IOException- if an I/O error occurs
-
doSend
protected <T extends Response> long doSend(Request request, T response, Set<RequestParam> params, long timeout) throws IOException Sends a request and manages the response handling.- Type Parameters:
T- the response type- Parameters:
request- the request to sendresponse- the response object to populateparams- additional parameters for the requesttimeout- the maximum time to wait for the response in milliseconds- Returns:
- the key associated with the request
- Throws:
IOException- if an I/O error occurs
-
handleIntermediate
Handles intermediate responses during request processing.- Type Parameters:
T- the response type- Parameters:
request- the request being processedresponse- the intermediate response- Returns:
- true if more responses are expected, false otherwise
-
getResponseTimeout
Gets the response timeout for a specific request.- Parameters:
request- the request to get timeout for- Returns:
- the timeout in milliseconds
-
doConnect
Establish the transport connection- Throws:
Exception- if the connection fails
-
doDisconnect
Disconnect the transport connection- Parameters:
hard- if true, force immediate disconnection without waiting for pending requestsinUse- whether the transport is currently in use- Returns:
- true if the disconnection was successful
- Throws:
IOException- if an I/O error occurs
-
connect
Connect the transport- Parameters:
timeout- the maximum time to wait for the connection in milliseconds- Returns:
- whether the transport was connected
- Throws:
TransportException- if the connection fails
-
disconnect
Disconnect the transport- Parameters:
hard- if true, disconnect immediately without waiting for outstanding requests- Returns:
- whether connection was in use
- Throws:
IOException- if an I/O error occurs during disconnection
-
disconnect
Disconnect the transport- Parameters:
hard- if true, disconnect immediately without waiting for outstanding requestsinUse- whether the caller is holding a usage reference on the transport- Returns:
- whether connection was in use
- Throws:
IOException- if an I/O error occurs during disconnection
-
run
public void run() -
toString
-