1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.newsclub.net.unix.darwin.system;
19
20 import java.io.FileDescriptor;
21 import java.io.IOException;
22 import java.net.Socket;
23 import java.net.SocketException;
24
25 import org.newsclub.net.unix.AFSYSTEMSocketAddress;
26 import org.newsclub.net.unix.AFSYSTEMSocketImplExtensions;
27 import org.newsclub.net.unix.AFSocket;
28 import org.newsclub.net.unix.AFSocketCapability;
29 import org.newsclub.net.unix.AFSocketFactory;
30
31
32
33
34
35
36 public final class AFSYSTEMSocket extends AFSocket<AFSYSTEMSocketAddress> implements
37 AFSYSTEMSocketExtensions {
38 private static AFSYSTEMSocketImplExtensions staticExtensions = null;
39
40 AFSYSTEMSocket(FileDescriptor fdObj, AFSocketFactory<AFSYSTEMSocketAddress> factory)
41 throws SocketException {
42 super(new AFSYSTEMSocketImpl(fdObj), factory);
43 }
44
45 @SuppressWarnings("unused")
46 private static synchronized AFSYSTEMSocketImplExtensions getStaticImplExtensions()
47 throws IOException {
48 if (staticExtensions == null) {
49 try (AFSYSTEMSocket socket = new AFSYSTEMSocket(null, null)) {
50 staticExtensions = (AFSYSTEMSocketImplExtensions) socket.getImplExtensions();
51 }
52 }
53 return staticExtensions;
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public static boolean isSupported() {
70 return AFSocket.isSupported() && AFSocket.supports(AFSocketCapability.CAPABILITY_DARWIN);
71 }
72
73 @Override
74 protected AFSYSTEMSocketChannel newChannel() {
75 return new AFSYSTEMSocketChannel(this);
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89 public static AFSYSTEMSocket newInstance() throws IOException {
90 return (AFSYSTEMSocket) AFSocket.newInstance(AFSYSTEMSocket::new, (AFSYSTEMSocketFactory) null);
91 }
92
93 static AFSYSTEMSocket newInstance(AFSYSTEMSocketFactory factory) throws SocketException {
94 return (AFSYSTEMSocket) AFSocket.newInstance(AFSYSTEMSocket::new, factory);
95 }
96
97
98
99
100
101
102
103
104
105
106 public static AFSYSTEMSocket newStrictInstance() throws IOException {
107 return (AFSYSTEMSocket) AFSocket.newInstance(AFSYSTEMSocket::new, (AFSYSTEMSocketFactory) null);
108 }
109
110
111
112
113
114
115
116
117 public static AFSYSTEMSocket connectTo(AFSYSTEMSocketAddress addr) throws IOException {
118 return (AFSYSTEMSocket) AFSocket.connectTo(AFSYSTEMSocket::new, addr);
119 }
120
121 @Override
122 public AFSYSTEMSocketChannel getChannel() {
123 return (AFSYSTEMSocketChannel) super.getChannel();
124 }
125
126
127
128
129
130
131
132
133 public static void main(String[] args) {
134 System.out.print(AFSYSTEMSocket.class.getName() + ".isSupported(): ");
135 System.out.flush();
136 System.out.println(AFSYSTEMSocket.isSupported());
137 }
138 }