StandardSocketFactory
Date: 2016-03-08

com.mysql.jdbc

## Class StandardSocketFactory

- java.lang.Object
- - com.mysql.jdbc.StandardSocketFactory

- All Implemented Interfaces:
    SocketFactory, SocketMetadata
  Direct Known Subclasses:
    SocksProxySocketFactory

      public class StandardSocketFactory
      extends java.lang.Object
      implements SocketFactory, SocketMetadata

  Socket factory for vanilla TCP/IP sockets (the standard)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `host` The hostname to connect to
    `static java.lang.String` | `IS_LOCAL_HOSTNAME_REPLACEMENT_PROPERTY_NAME`
    `protected long` | `loginTimeoutCheckTimestamp` Time when last Login Timeout check occurred
    `protected int` | `loginTimeoutCountdown` The remaining login time in milliseconds.
    `protected int` | `port` The port number to connect to
    `protected java.net.Socket` | `rawSocket` The underlying TCP/IP socket to use
    `protected int` | `socketTimeoutBackup` Backup original Socket timeout to be restored after handshake
    `static java.lang.String` | `TCP_KEEP_ALIVE_DEFAULT_VALUE`
    `static java.lang.String` | `TCP_KEEP_ALIVE_PROPERTY_NAME`
    `static java.lang.String` | `TCP_NO_DELAY_DEFAULT_VALUE`
    `static java.lang.String` | `TCP_NO_DELAY_PROPERTY_NAME`
    `static java.lang.String` | `TCP_RCV_BUF_DEFAULT_VALUE`
    `static java.lang.String` | `TCP_RCV_BUF_PROPERTY_NAME`
    `static java.lang.String` | `TCP_SND_BUF_DEFAULT_VALUE`
    `static java.lang.String` | `TCP_SND_BUF_PROPERTY_NAME`
    `static java.lang.String` | `TCP_TRAFFIC_CLASS_DEFAULT_VALUE`
    `static java.lang.String` | `TCP_TRAFFIC_CLASS_PROPERTY_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StandardSocketFactory()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.net.Socket` | `afterHandshake()` Called by the driver after issuing the MySQL protocol handshake and reading the results of the handshake.
    `java.net.Socket` | `beforeHandshake()` Called by the driver before issuing the MySQL protocol handshake.
    `java.net.Socket` | `connect(java.lang.String hostname, int portNumber, java.util.Properties props)` Creates a new socket using the given properties.
    `protected java.net.Socket` | `createSocket(java.util.Properties props)` Create the raw socket.
    `protected int` | `getRealTimeout(int expectedTimeout)` Validates the connection/socket timeout that must really be used.
    `boolean` | `isLocallyConnected(ConnectionImpl conn)`
    `protected void` | `resetLoginTimeCountdown()` Decrements elapsed time since last reset from login timeout count down.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TCP_NO_DELAY_PROPERTY_NAME

          public static final java.lang.String TCP_NO_DELAY_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### TCP_KEEP_ALIVE_DEFAULT_VALUE

          public static final java.lang.String TCP_KEEP_ALIVE_DEFAULT_VALUE

      See Also:
        Constant Field Values

    - #### TCP_KEEP_ALIVE_PROPERTY_NAME

          public static final java.lang.String TCP_KEEP_ALIVE_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### TCP_RCV_BUF_PROPERTY_NAME

          public static final java.lang.String TCP_RCV_BUF_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### TCP_SND_BUF_PROPERTY_NAME

          public static final java.lang.String TCP_SND_BUF_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### TCP_TRAFFIC_CLASS_PROPERTY_NAME

          public static final java.lang.String TCP_TRAFFIC_CLASS_PROPERTY_NAME

      See Also:
        Constant Field Values

    - #### TCP_RCV_BUF_DEFAULT_VALUE

          public static final java.lang.String TCP_RCV_BUF_DEFAULT_VALUE

      See Also:
        Constant Field Values

    - #### TCP_SND_BUF_DEFAULT_VALUE

          public static final java.lang.String TCP_SND_BUF_DEFAULT_VALUE

      See Also:
        Constant Field Values

    - #### TCP_TRAFFIC_CLASS_DEFAULT_VALUE

          public static final java.lang.String TCP_TRAFFIC_CLASS_DEFAULT_VALUE

      See Also:
        Constant Field Values

    - #### TCP_NO_DELAY_DEFAULT_VALUE

          public static final java.lang.String TCP_NO_DELAY_DEFAULT_VALUE

      See Also:
        Constant Field Values

    - #### host

          protected java.lang.String host

      The hostname to connect to

    - #### port

          protected int port

      The port number to connect to

    - #### rawSocket

          protected java.net.Socket rawSocket

      The underlying TCP/IP socket to use

    - #### loginTimeoutCountdown

          protected int loginTimeoutCountdown

      The remaining login time in milliseconds. Initial value set from defined DriverManager.setLoginTimeout()

    - #### loginTimeoutCheckTimestamp

          protected long loginTimeoutCheckTimestamp

      Time when last Login Timeout check occurred

    - #### socketTimeoutBackup

          protected int socketTimeoutBackup

      Backup original Socket timeout to be restored after handshake

    - #### IS_LOCAL_HOSTNAME_REPLACEMENT_PROPERTY_NAME

          public static final java.lang.String IS_LOCAL_HOSTNAME_REPLACEMENT_PROPERTY_NAME

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StandardSocketFactory

          public StandardSocketFactory()

  - ### Method Detail

    - #### afterHandshake

          public java.net.Socket afterHandshake()
                                         throws java.net.SocketException,
                                                java.io.IOException

      Called by the driver after issuing the MySQL protocol handshake and reading the results of the handshake.
      Specified by:
        `afterHandshake` in interface `SocketFactory`
      Returns:
        The socket to use after the handshake
      Throws:
        `java.net.SocketException` - if a socket error occurs
        `java.io.IOException` - if an I/O error occurs

    - #### beforeHandshake

          public java.net.Socket beforeHandshake()
                                          throws java.net.SocketException,
                                                 java.io.IOException

      Called by the driver before issuing the MySQL protocol handshake. Should return the socket instance that should be used during the handshake.
      Specified by:
        `beforeHandshake` in interface `SocketFactory`
      Returns:
        the socket to use before the handshake
      Throws:
        `java.net.SocketException` - if a socket error occurs
        `java.io.IOException` - if an I/O error occurs

    - #### createSocket

          protected java.net.Socket createSocket(java.util.Properties props)

      Create the raw socket.
      Parameters:
        `props` - properties available to affect behavior during socket creation.

    - #### connect

          public java.net.Socket connect(java.lang.String hostname,
                                int portNumber,
                                java.util.Properties props)
                                  throws java.net.SocketException,
                                         java.io.IOException

      Description copied from interface: `SocketFactory`
      Creates a new socket using the given properties. Properties are parsed by the driver from the URL. All properties other than sensitive ones (user and password) are passed to this method. The driver will instantiate the socket factory with the class name given in the property "socketFactory", where the standard is `com.mysql.jdbc.StandardSocketFactory` Implementing classes are responsible for handling synchronization of this method (if needed).
      Specified by:
        `connect` in interface `SocketFactory`
      Parameters:
        `hostname` - the hostname passed in the JDBC URL. It will be a single hostname, as the driver parses multi-hosts (for failover) and calls this method for each host connection attempt.
        `portNumber` - the port number to connect to (if required).
        `props` - properties passed to the driver via the URL and/or properties instance.
      Returns:
        a socket connected to the given host
      Throws:
        `java.net.SocketException` - if a socket error occurs
        `java.io.IOException` - if an I/O error occurs
      See Also:
        `com.mysql.jdbc.SocketFactory#createSocket(Properties)`

    - #### isLocallyConnected

          public boolean isLocallyConnected(ConnectionImpl conn)
                                     throws java.sql.SQLException

      Specified by:
        `isLocallyConnected` in interface `SocketMetadata`
      Throws:
        `java.sql.SQLException`

    - #### resetLoginTimeCountdown

          protected void resetLoginTimeCountdown()
                                          throws java.net.SocketException

      Decrements elapsed time since last reset from login timeout count down.
      Throws:
        `java.net.SocketException` - If the login timeout is reached or exceeded.

    - #### getRealTimeout

          protected int getRealTimeout(int expectedTimeout)

      Validates the connection/socket timeout that must really be used.
      Parameters:
        `expectedTimeout` - The timeout to validate.
      Returns:
        The timeout to be used.