Module jcifs

Class Transport

java.lang.Object
org.codelibs.jcifs.smb.util.transport.Transport
All Implemented Interfaces:
AutoCloseable, Runnable

public abstract class Transport extends Object implements Runnable, AutoCloseable
Abstract base class for network transport implementations in JCIFS. This class handles the low-level transport protocol for SMB communication.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Object
    Lock object for synchronizing input operations
    protected String
    Name identifier for this transport instance
    protected final Object
    Lock object for synchronizing output operations
    protected final Map<Long,Response>
    Map for tracking pending responses by their key
    protected int
    Current state of the transport connection
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default constructor for Transport
  • Method Summary

    Modifier and Type
    Method
    Description
    Acquires a reference to this transport, incrementing the usage count.
    void
    boolean
    connect(long timeout)
    Connect the transport
    boolean
    disconnect(boolean hard)
    Disconnect the transport
    boolean
    disconnect(boolean hard, boolean inUse)
    Disconnect the transport
    protected abstract void
    Establish the transport connection
    protected abstract boolean
    doDisconnect(boolean hard, boolean inUse)
    Disconnect the transport connection
    protected abstract void
    doRecv(Response response)
    Receive a response from the transport
    protected abstract void
    doSend(Request request)
    Send a request over the transport
    protected <T extends Response>
    long
    doSend(Request request, T response, Set<RequestParam> params, long timeout)
    Sends a request and manages the response handling.
    protected abstract void
    doSkip(Long key)
    Skip a response with the given key
    protected void
    protected abstract int
    Gets the response timeout for a specific request.
    protected long
    Gets the current usage count for this transport.
    protected <T extends Response>
    boolean
    handleIntermediate(Request request, T response)
    Handles intermediate responses during request processing.
    boolean
    Checks if the transport is disconnected.
    boolean
    Checks if the transport is in a failed state.
    protected abstract long
    makeKey(Request request)
    Generate a unique key for the given request
    protected abstract Long
    Peek at the next key without removing it from the input stream
    static int
    readn(InputStream in, byte[] b, int off, int len)
    Read bytes from the input stream into a buffer
    void
    Releases a reference to this transport, decrementing the usage count.
    void
    run()
     
    <T extends Response>
    T
    sendrecv(Request request, T response, Set<RequestParam> params)
    Send a request message and recieve response
     

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • state

      protected volatile int state
      Current state of the transport connection
    • name

      protected String name
      Name identifier for this transport instance
    • inLock

      protected final Object inLock
      Lock object for synchronizing input operations
    • outLock

      protected final Object outLock
      Lock object for synchronizing output operations
    • response_map

      protected final Map<Long,Response> response_map
      Map for tracking pending responses by their key
  • Constructor Details

    • Transport

      protected Transport()
      Default constructor for Transport
  • Method Details

    • readn

      public static int readn(InputStream in, byte[] b, int off, int len) throws IOException
      Read bytes from the input stream into a buffer
      Parameters:
      in - the input stream to read from
      b - the buffer to read into
      off - the offset in the buffer to start writing
      len - the number of bytes to read
      Returns:
      number of bytes read
      Throws:
      IOException - if an I/O error occurs
    • acquire

      public Transport acquire()
      Acquires a reference to this transport, incrementing the usage count.
      Returns:
      session increased usage count
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      See Also:
    • release

      public void release()
      Releases a reference to this transport, decrementing the usage count.
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
      See Also:
    • getUsageCount

      protected long getUsageCount()
      Gets the current usage count for this transport.
      Returns:
      the number of known usages
    • makeKey

      protected abstract long makeKey(Request request) throws IOException
      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

      protected abstract Long peekKey() throws IOException
      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

      protected abstract void doSend(Request request) throws IOException
      Send a request over the transport
      Parameters:
      request - the request to send
      Throws:
      IOException - if an I/O error occurs
    • doRecv

      protected abstract void doRecv(Response response) throws IOException
      Receive a response from the transport
      Parameters:
      response - the response object to populate
      Throws:
      IOException - if an I/O error occurs
    • doSkip

      protected abstract void doSkip(Long key) throws IOException
      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 send
      response - the response object to populate
      params - 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 send
      response - the response object to populate
      params - additional parameters for the request
      timeout - 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

      protected <T extends Response> boolean handleIntermediate(Request request, T response)
      Handles intermediate responses during request processing.
      Type Parameters:
      T - the response type
      Parameters:
      request - the request being processed
      response - the intermediate response
      Returns:
      true if more responses are expected, false otherwise
    • getResponseTimeout

      protected abstract int getResponseTimeout(Request request)
      Gets the response timeout for a specific request.
      Parameters:
      request - the request to get timeout for
      Returns:
      the timeout in milliseconds
    • doConnect

      protected abstract void doConnect() throws Exception
      Establish the transport connection
      Throws:
      Exception - if the connection fails
    • doDisconnect

      protected abstract boolean doDisconnect(boolean hard, boolean inUse) throws IOException
      Disconnect the transport connection
      Parameters:
      hard - if true, force immediate disconnection without waiting for pending requests
      inUse - whether the transport is currently in use
      Returns:
      true if the disconnection was successful
      Throws:
      IOException - if an I/O error occurs
    • connect

      public boolean connect(long timeout) throws TransportException
      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

      public boolean disconnect(boolean hard) throws IOException
      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

      public boolean disconnect(boolean hard, boolean inUse) throws IOException
      Disconnect the transport
      Parameters:
      hard - if true, disconnect immediately without waiting for outstanding requests
      inUse - 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()
      Specified by:
      run in interface Runnable
    • toString

      public String toString()
      Overrides:
      toString in class Object