Top Description Fields Constructors Methods
com.mysql.cj.protocol

public Class StandardSocketFactory

extends Object
implements SocketFactory
Class Inheritance
All Implemented Interfaces
com.mysql.cj.protocol.SocketFactory, com.mysql.cj.protocol.SocketMetadata
Known Direct Subclasses
com.mysql.jdbc.SocketFactoryWrapper, com.mysql.cj.protocol.SocksProxySocketFactory
Imports
java.io.Closeable, .IOException, java.net.InetAddress, .InetSocketAddress, .Socket, .SocketException, com.mysql.cj.Messages, com.mysql.cj.conf.PropertyKey, .PropertySet, com.mysql.cj.log.Log

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

Field Summary

Modifier and TypeField and Description
protected String
host

The hostname to connect to

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 Socket
rawSocket

The underlying TCP/IP socket to use

protected int
socketTimeoutBackup

Backup original Socket timeout to be restored after handshake

protected Socket
sslSocket

The wrapper for underlying TCP/IP socket

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterHandshake()

Overrides default com.mysql.cj.protocol.SocketFactory.afterHandshake.

Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.

public void
beforeHandshake()

Overrides default com.mysql.cj.protocol.SocketFactory.beforeHandshake.

Called by the driver before issuing the MySQL protocol handshake.

protected void
configureSocket(Socket
socket
sock
,
PropertySet
properties
pset
)

Configures socket properties based on properties from the connection (tcpNoDelay, snd/rcv buf, traffic class, etc).

public <T extends Closeable> T
connect(String
the hostname passed in the URL. It will be a single hostname, as the driver parses multi-hosts (for failover) and calls this method for each host connection attempt.
hostname
,
int
the port number to connect to (if required).
portNumber
,
PropertySet
properties passed to the driver via the URL and/or properties instance.
pset
,
int
login timeout in milliseconds
loginTimeout
)

Implements com.mysql.cj.protocol.SocketFactory.connect.

Creates a new socket or channel using the given properties.

protected Socket

Returns:

socket
createSocket
(PropertySet
properties available to affect behaviour during socket creation.
props
)

Create the raw socket.

protected int

Returns:

The timeout to be used.
getRealTimeout
(int
The timeout to validate.
expectedTimeout
)

Validates the connection/socket timeout that must really be used.

public <T extends Closeable> T
performTlsHandshake(SocketConnection
current SocketConnection
socketConnection
,
ServerSession
current ServerSession
serverSession
)

Implements com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

public <T extends Closeable> T
performTlsHandshake(SocketConnection
current SocketConnection
socketConnection
,
ServerSession
current ServerSession
serverSession
,
Log
logger
log
)

Overrides default com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

protected void
resetLoginTimeCountdown()

Decrements elapsed time since last reset from login timeout count down.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hostback to summary
protected String host

The hostname to connect to

loginTimeoutCheckTimestampback to summary
protected long loginTimeoutCheckTimestamp

Time when last Login Timeout check occurred

loginTimeoutCountdownback to summary
protected int loginTimeoutCountdown

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

portback to summary
protected int port

The port number to connect to

rawSocketback to summary
protected Socket rawSocket

The underlying TCP/IP socket to use

socketTimeoutBackupback to summary
protected int socketTimeoutBackup

Backup original Socket timeout to be restored after handshake

sslSocketback to summary
protected Socket sslSocket

The wrapper for underlying TCP/IP socket

Constructor Detail

StandardSocketFactoryback to summary
public StandardSocketFactory()

Method Detail

afterHandshakeback to summary
public void afterHandshake() throws IOException

Overrides default com.mysql.cj.protocol.SocketFactory.afterHandshake.

Doc from com.mysql.cj.protocol.SocketFactory.afterHandshake.

Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
beforeHandshakeback to summary
public void beforeHandshake() throws IOException

Overrides default com.mysql.cj.protocol.SocketFactory.beforeHandshake.

Doc from com.mysql.cj.protocol.SocketFactory.beforeHandshake.

Called by the driver before issuing the MySQL protocol handshake.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
configureSocketback to summary
protected void configureSocket(Socket sock, PropertySet pset) throws SocketException, IOException

Configures socket properties based on properties from the connection (tcpNoDelay, snd/rcv buf, traffic class, etc).

Parameters
sock:Socket

socket

pset:PropertySet

properties

Exceptions
SocketException:
if an error occurs
IOException:
if an error occurs
connectback to summary
public <T extends Closeable> T connect(String hostname, int portNumber, PropertySet pset, int loginTimeout) throws IOException

Implements com.mysql.cj.protocol.SocketFactory.connect.

Doc from com.mysql.cj.protocol.SocketFactory.connect.

Creates a new socket or channel 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.cj.protocol.StandardSocketFactory Implementing classes are responsible for handling synchronization of this method (if needed).

Parameters
<T>
result type
hostname:String

the hostname passed in the 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:int

the port number to connect to (if required).

pset:PropertySet

properties passed to the driver via the URL and/or properties instance.

loginTimeout:int

login timeout in milliseconds

Returns:T

a socket connected to the given host

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
IOException:
if an I/O error occurs
createSocketback to summary
protected Socket createSocket(PropertySet props)

Create the raw socket.

Parameters
props:PropertySet

properties available to affect behaviour during socket creation.

Returns:Socket

socket

getRealTimeoutback to summary
protected int getRealTimeout(int expectedTimeout)

Validates the connection/socket timeout that must really be used.

Parameters
expectedTimeout:int

The timeout to validate.

Returns:int

The timeout to be used.

performTlsHandshakeback to summary
public <T extends Closeable> T performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession) throws IOException

Implements com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

Doc from com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

Parameters
<T>
result type
socketConnection:SocketConnection

current SocketConnection

serverSession:ServerSession

current ServerSession

Returns:T

SSL socket

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
performTlsHandshakeback to summary
public <T extends Closeable> T performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession, Log log) throws IOException

Overrides default com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

Doc from com.mysql.cj.protocol.SocketFactory.performTlsHandshake.

If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.

Parameters
<T>
result type
socketConnection:SocketConnection

current SocketConnection

serverSession:ServerSession

current ServerSession

log:Log

logger

Returns:T

SSL socket

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
IOException:
if an I/O error occurs
resetLoginTimeCountdownback to summary
protected void resetLoginTimeCountdown() throws SocketException

Decrements elapsed time since last reset from login timeout count down.

Exceptions
SocketException:
If the login timeout is reached or exceeded.