Module jcifs

Class Transport

java.lang.Object
org.codelibs.jcifs.smb1.util.transport.Transport
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
SmbTransport

public abstract class Transport extends Object implements Runnable
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

    Fields
    Modifier and Type
    Field
    Description
    protected HashMap
    Map of pending requests to their corresponding responses.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for Transport.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    connect(long timeout)
    Establishes a connection to the remote endpoint.
    void
    disconnect(boolean hard)
    Disconnects from the remote endpoint.
    protected abstract void
    Establishes a connection to the remote endpoint.
    protected abstract void
    doDisconnect(boolean hard)
    Tears down the connection to the remote endpoint.
    protected abstract void
    doRecv(Response response)
    Receives a response from the remote endpoint.
    protected abstract void
    doSend(Request request)
    Sends a request to the remote endpoint.
    protected abstract void
    Skips an unexpected or unrecognized message.
    protected abstract void
    makeKey(Request request)
    Creates a key for the specified request for response matching.
    protected abstract Request
    Reads and returns the key of the next message without consuming it.
    static int
    readn(InputStream in, byte[] b, int off, int len)
    Reads exactly len bytes from the input stream into the buffer.
    void
    run()
     
    void
    sendrecv(Request request, Response response, long timeout)
    Sends a request and waits for the corresponding response.
     

    Methods inherited from class java.lang.Object

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

    • response_map

      protected HashMap response_map
      Map of pending requests to their corresponding responses.
  • Constructor Details

    • Transport

      public Transport()
      Default constructor for Transport.
  • Method Details

    • readn

      public static int readn(InputStream in, byte[] b, int off, int len) throws IOException
      Reads exactly len bytes from the input stream into the 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:
      the number of bytes actually read
      Throws:
      IOException - if an I/O error occurs
    • makeKey

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

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

      protected abstract void doSend(Request request) throws IOException
      Sends a request to the remote endpoint.
      Parameters:
      request - the request to send
      Throws:
      IOException - if an I/O error occurs
    • doRecv

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

      protected abstract void doSkip() throws IOException
      Skips an unexpected or unrecognized message.
      Throws:
      IOException - if an I/O error occurs
    • sendrecv

      public void sendrecv(Request request, Response response, long timeout) throws IOException
      Sends a request and waits for the corresponding response.
      Parameters:
      request - the request to send
      response - the response object to populate
      timeout - the maximum time to wait for the response in milliseconds
      Throws:
      IOException - if an I/O error occurs during communication
    • doConnect

      protected abstract void doConnect() throws Exception
      Establishes a connection to the remote endpoint.
      Throws:
      Exception - if the connection fails
    • doDisconnect

      protected abstract void doDisconnect(boolean hard) throws IOException
      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

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

      public void disconnect(boolean hard) throws IOException
      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()
      Specified by:
      run in interface Runnable
    • toString

      public String toString()
      Overrides:
      toString in class Object