|
|
fbd856 |
commit 97f2dbbc341c09496c3823604cc73c5d70e42084
|
|
|
fbd856 |
Author: Jakub Janco <jjanco@redhat.com>
|
|
|
fbd856 |
Date: Tue Dec 18 17:43:18 2018 +0100
|
|
|
fbd856 |
|
|
|
fbd856 |
remove NamedPipeSocket
|
|
|
fbd856 |
|
|
|
fbd856 |
diff --git a/src/main/java/org/mariadb/jdbc/internal/io/socket/NamedPipeSocket.java b/src/main/java/org/mariadb/jdbc/internal/io/socket/NamedPipeSocket.java
|
|
|
fbd856 |
deleted file mode 100644
|
|
|
fbd856 |
index 562bceed..00000000
|
|
|
fbd856 |
--- a/src/main/java/org/mariadb/jdbc/internal/io/socket/NamedPipeSocket.java
|
|
|
fbd856 |
+++ /dev/null
|
|
|
fbd856 |
@@ -1,218 +0,0 @@
|
|
|
fbd856 |
-/*
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * MariaDB Client for Java
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * Copyright (c) 2012-2014 Monty Program Ab.
|
|
|
fbd856 |
- * Copyright (c) 2015-2017 MariaDB Ab.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * This library is free software; you can redistribute it and/or modify it under
|
|
|
fbd856 |
- * the terms of the GNU Lesser General Public License as published by the Free
|
|
|
fbd856 |
- * Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
fbd856 |
- * any later version.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * This library is distributed in the hope that it will be useful, but
|
|
|
fbd856 |
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
fbd856 |
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
fbd856 |
- * for more details.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * You should have received a copy of the GNU Lesser General Public License along
|
|
|
fbd856 |
- * with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * This particular MariaDB Client for Java file is work
|
|
|
fbd856 |
- * derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
|
|
fbd856 |
- * the following copyright and notice provisions:
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * Copyright (c) 2009-2011, Marcus Eriksson
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * Redistribution and use in source and binary forms, with or without modification,
|
|
|
fbd856 |
- * are permitted provided that the following conditions are met:
|
|
|
fbd856 |
- * Redistributions of source code must retain the above copyright notice, this list
|
|
|
fbd856 |
- * of conditions and the following disclaimer.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
fbd856 |
- * list of conditions and the following disclaimer in the documentation and/or
|
|
|
fbd856 |
- * other materials provided with the distribution.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * Neither the name of the driver nor the names of its contributors may not be
|
|
|
fbd856 |
- * used to endorse or promote products derived from this software without specific
|
|
|
fbd856 |
- * prior written permission.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
fbd856 |
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
fbd856 |
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
fbd856 |
- * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
fbd856 |
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
fbd856 |
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
fbd856 |
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
fbd856 |
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
fbd856 |
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
|
fbd856 |
- * OF SUCH DAMAGE.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- */
|
|
|
fbd856 |
-
|
|
|
fbd856 |
-package org.mariadb.jdbc.internal.io.socket;
|
|
|
fbd856 |
-
|
|
|
fbd856 |
-import com.sun.jna.platform.win32.Kernel32;
|
|
|
fbd856 |
-import java.io.FileNotFoundException;
|
|
|
fbd856 |
-import java.io.IOException;
|
|
|
fbd856 |
-import java.io.InputStream;
|
|
|
fbd856 |
-import java.io.OutputStream;
|
|
|
fbd856 |
-import java.io.RandomAccessFile;
|
|
|
fbd856 |
-import java.net.Socket;
|
|
|
fbd856 |
-import java.net.SocketAddress;
|
|
|
fbd856 |
-import java.util.concurrent.TimeUnit;
|
|
|
fbd856 |
-
|
|
|
fbd856 |
-@SuppressWarnings("UnnecessaryInitCause")
|
|
|
fbd856 |
-public class NamedPipeSocket extends Socket {
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- private final String host;
|
|
|
fbd856 |
- private final String name;
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- private RandomAccessFile file;
|
|
|
fbd856 |
- private InputStream is;
|
|
|
fbd856 |
- private OutputStream os;
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public NamedPipeSocket(String host, String name) {
|
|
|
fbd856 |
- this.host = host;
|
|
|
fbd856 |
- this.name = name;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void close() throws IOException {
|
|
|
fbd856 |
- if (file != null) {
|
|
|
fbd856 |
- file.close();
|
|
|
fbd856 |
- file = null;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void connect(SocketAddress endpoint) throws IOException {
|
|
|
fbd856 |
- connect(endpoint, 0);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- /**
|
|
|
fbd856 |
- * Name pipe connection.
|
|
|
fbd856 |
- *
|
|
|
fbd856 |
- * @param endpoint endPoint
|
|
|
fbd856 |
- * @param timeout timeout in milliseconds
|
|
|
fbd856 |
- * @throws IOException exception
|
|
|
fbd856 |
- */
|
|
|
fbd856 |
- public void connect(SocketAddress endpoint, int timeout) throws IOException {
|
|
|
fbd856 |
- String filename;
|
|
|
fbd856 |
- if (host == null || host.equals("localhost")) {
|
|
|
fbd856 |
- filename = "\\\\.\\pipe\\" + name;
|
|
|
fbd856 |
- } else {
|
|
|
fbd856 |
- filename = "\\\\" + host + "\\pipe\\" + name;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- //use a default timeout of 100ms if no timeout set.
|
|
|
fbd856 |
- int usedTimeout = timeout == 0 ? 100 : timeout;
|
|
|
fbd856 |
- long initialNano = System.nanoTime();
|
|
|
fbd856 |
- do {
|
|
|
fbd856 |
- try {
|
|
|
fbd856 |
- file = new RandomAccessFile(filename, "rw");
|
|
|
fbd856 |
- break;
|
|
|
fbd856 |
- } catch (FileNotFoundException fileNotFoundException) {
|
|
|
fbd856 |
- try {
|
|
|
fbd856 |
- //using JNA if available
|
|
|
fbd856 |
- Kernel32.INSTANCE.WaitNamedPipe(filename, timeout);
|
|
|
fbd856 |
- //then retry connection
|
|
|
fbd856 |
- file = new RandomAccessFile(filename, "rw");
|
|
|
fbd856 |
- } catch (Throwable cle) {
|
|
|
fbd856 |
- // in case JNA not on classpath, then wait 10ms before next try.
|
|
|
fbd856 |
- if (System.nanoTime() - initialNano > TimeUnit.MILLISECONDS.toNanos(usedTimeout)) {
|
|
|
fbd856 |
- if (timeout == 0) {
|
|
|
fbd856 |
- throw new FileNotFoundException(fileNotFoundException.getMessage()
|
|
|
fbd856 |
- + "\nplease consider set connectTimeout option, so connection can retry having access to named pipe. "
|
|
|
fbd856 |
- + "\n(Named pipe can throw ERROR_PIPE_BUSY error)");
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- throw fileNotFoundException;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- try {
|
|
|
fbd856 |
- TimeUnit.MILLISECONDS.sleep(5);
|
|
|
fbd856 |
- } catch (InterruptedException interrupted) {
|
|
|
fbd856 |
- IOException ioException = new IOException(
|
|
|
fbd856 |
- "Interruption during connection to named pipe");
|
|
|
fbd856 |
- ioException.initCause(interrupted);
|
|
|
fbd856 |
- throw ioException;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- } while (true);
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- is = new InputStream() {
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public int read(byte[] bytes, int off, int len) throws IOException {
|
|
|
fbd856 |
- return file.read(bytes, off, len);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public int read() throws IOException {
|
|
|
fbd856 |
- return file.read();
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public int read(byte[] bytes) throws IOException {
|
|
|
fbd856 |
- return file.read(bytes);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- };
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- os = new OutputStream() {
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void write(byte[] bytes, int off, int len) throws IOException {
|
|
|
fbd856 |
- file.write(bytes, off, len);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void write(int value) throws IOException {
|
|
|
fbd856 |
- file.write(value);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void write(byte[] bytes) throws IOException {
|
|
|
fbd856 |
- file.write(bytes);
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
- };
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public InputStream getInputStream() {
|
|
|
fbd856 |
- return is;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public OutputStream getOutputStream() {
|
|
|
fbd856 |
- return os;
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void setTcpNoDelay(boolean bool) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void setKeepAlive(boolean bool) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void setReceiveBufferSize(int size) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void setSendBufferSize(int size) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void setSoLinger(boolean bool, int value) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- @Override
|
|
|
fbd856 |
- public void setSoTimeout(int timeout) {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void shutdownInput() {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-
|
|
|
fbd856 |
- public void shutdownOutput() {
|
|
|
fbd856 |
- //do nothing
|
|
|
fbd856 |
- }
|
|
|
fbd856 |
-}
|
|
|
fbd856 |
diff --git a/src/main/java/org/mariadb/jdbc/internal/io/socket/SocketUtility.java b/src/main/java/org/mariadb/jdbc/internal/io/socket/SocketUtility.java
|
|
|
fbd856 |
index 8a024af9..1b8b498d 100644
|
|
|
fbd856 |
--- a/src/main/java/org/mariadb/jdbc/internal/io/socket/SocketUtility.java
|
|
|
fbd856 |
+++ b/src/main/java/org/mariadb/jdbc/internal/io/socket/SocketUtility.java
|
|
|
fbd856 |
@@ -19,9 +19,7 @@ public class SocketUtility {
|
|
|
fbd856 |
Platform.getOSType();
|
|
|
fbd856 |
|
|
|
fbd856 |
return (urlParser, host) -> {
|
|
|
fbd856 |
- if (urlParser.getOptions().pipe != null) {
|
|
|
fbd856 |
- return new NamedPipeSocket(host, urlParser.getOptions().pipe);
|
|
|
fbd856 |
- } else if (urlParser.getOptions().localSocket != null) {
|
|
|
fbd856 |
+ if (urlParser.getOptions().localSocket != null) {
|
|
|
fbd856 |
try {
|
|
|
fbd856 |
return new UnixDomainSocket(urlParser.getOptions().localSocket);
|
|
|
fbd856 |
} catch (RuntimeException re) {
|