/** * Establishes the TCP/IP connection to serverName and portNumber of this Connection * * @throws SQLTimeoutException If the connection cannot be established within the connect timeout * (either explicitly set or implied by the OS timeout of the socket) * @throws SQLException If the connection cannot be established. */ public final void socketConnect() throws SQLException { try { socket = new Socket(); socket.setTcpNoDelay(true); final int connectTimeout = attachProperties.getConnectTimeout(); final int socketConnectTimeout; if (connectTimeout != -1) { // connectTimeout is in seconds, need milliseconds socketConnectTimeout = (int) TimeUnit.SECONDS.toMillis(connectTimeout); // Blocking timeout initially identical to connect timeout socket.setSoTimeout(socketConnectTimeout); } else { // socket connect timeout is not set, so indefinite (0) socketConnectTimeout = 0; // Blocking timeout to normal socket timeout, 0 if not set socket.setSoTimeout(Math.max(attachProperties.getSoTimeout(), 0)); } final int socketBufferSize = attachProperties.getSocketBufferSize(); if (socketBufferSize != IConnectionProperties.DEFAULT_SOCKET_BUFFER_SIZE) { socket.setReceiveBufferSize(socketBufferSize); socket.setSendBufferSize(socketBufferSize); } socket.connect(new InetSocketAddress(getServerName(), getPortNumber()), socketConnectTimeout); } catch (SocketTimeoutException ste) { throw new FbExceptionBuilder() .timeoutException(ISCConstants.isc_network_error) .messageParameter(getServerName()) .cause(ste) .toSQLException(); } catch (IOException ioex) { throw new FbExceptionBuilder() .exception(ISCConstants.isc_network_error) .messageParameter(getServerName()) .cause(ioex) .toSQLException(); } }