/
SocketUtility.java
41 lines (35 loc) · 1.51 KB
/
SocketUtility.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package org.mariadb.jdbc.internal.io.socket;
import com.sun.jna.Platform;
import org.mariadb.jdbc.internal.util.Utils;
import java.io.IOException;
public class SocketUtility {
@SuppressWarnings("unchecked")
public static SocketHandlerFunction getSocketHandler() {
try {
//forcing use of JNA to ensure AOT compilation
Platform.getOSType();
return (urlParser, host) -> {
if (urlParser.getOptions().pipe != null) {
return new NamedPipeSocket(host, urlParser.getOptions().pipe);
} else if (urlParser.getOptions().localSocket != null) {
try {
return new UnixDomainSocket(urlParser.getOptions().localSocket);
} catch (RuntimeException re) {
throw new IOException(re.getMessage(), re.getCause());
}
} else if (urlParser.getOptions().sharedMemory != null) {
try {
return new SharedMemorySocket(urlParser.getOptions().sharedMemory);
} catch (RuntimeException re) {
throw new IOException(re.getMessage(), re.getCause());
}
} else {
return Utils.standardSocket(urlParser, host);
}
};
} catch (Throwable cle) {
//jna jar's are not in classpath
}
return (urlParser, host) -> Utils.standardSocket(urlParser, host);
}
}