@@ -34,6 +34,7 @@ public class UnixStreamClientChannel implements ClientChannel {
3434 this .timeout = timeout ;
3535 this .connectionTimeout = connectionTimeout ;
3636 this .bufferSize = bufferSize ;
37+ System .out .println ("================Created UnixStreamClientChannel with address: " + address );
3738 }
3839
3940 @ Override
@@ -98,18 +99,16 @@ private void connect() throws IOException {
9899
99100 long deadline = System .nanoTime () + connectionTimeout * 1_000_000L ;
100101 // Use native JDK Unix domain socket support for compatible versions (Java 16+). Fall back to JNR support otherwise.
101- if (ClientChannelUtils .hasNativeUdsSupport ()) {
102+ if (VersionUtils .hasNativeUdsSupport ()) {
102103 connectJdkSocket (deadline );
103104 } else {
104105 connectJnrSocket (deadline );
105106 }
106107 }
107108
108109 private void connectJdkSocket (long deadline ) throws IOException {
109- String socketPath = address .toString ();
110-
110+ String socketPath = address .toString ();
111111 try {
112- // Use reflection to avoid compile-time dependency on Java 16+ classes
113112 Class <?> udsAddressClass = Class .forName ("java.net.UnixDomainSocketAddress" );
114113 Object udsAddress = udsAddressClass .getMethod ("of" , String .class ).invoke (null , socketPath );
115114
@@ -118,32 +117,34 @@ private void connectJdkSocket(long deadline) throws IOException {
118117 delegate .socket ().setSoTimeout (connectionTimeout );
119118 }
120119
121- try {
122- delegate .configureBlocking (false );
123- if (!delegate .connect ((SocketAddress ) udsAddress )) {
124- if (connectionTimeout > 0 && System .nanoTime () > deadline ) {
125- throw new IOException ("Connection timed out" );
126- }
127- if (!delegate .finishConnect ()) {
128- throw new IOException ("Connection failed" );
129- }
130- }
131- delegate .configureBlocking (true );
132- delegate .socket ().setSoTimeout (Math .max (timeout , 0 ));
133- if (bufferSize > 0 ) {
134- delegate .socket ().setSendBufferSize (bufferSize );
120+ delegate .configureBlocking (false );
121+ System .out .println ("================Attempting to connect delegate to: " + udsAddress );
122+ if (!delegate .connect ((SocketAddress ) udsAddress )) {
123+ System .out .println ("================Initial connect returned false, checking deadline" );
124+ if (connectionTimeout > 0 && System .nanoTime () > deadline ) {
125+ throw new IOException ("Connection timed out" );
135126 }
136- this .delegate = delegate ;
137- } catch (Exception e ) {
138- try {
139- delegate .close ();
140- } catch (IOException __ ) {
141- // ignore
127+ System .out .println ("================Finishing connection" );
128+ if (!delegate .finishConnect ()) {
129+ throw new IOException ("Connection failed" );
142130 }
143- throw new IOException ("Failed to connect to Unix Domain Socket: " + socketPath , e );
144131 }
145- } catch (ReflectiveOperationException e ) {
146- throw new IOException ("Failed to create UnixDomainSocketAddress: Java 16+ required" , e );
132+ System .out .println ("================Connection successful" );
133+ delegate .configureBlocking (true );
134+ delegate .socket ().setSoTimeout (Math .max (timeout , 0 ));
135+ if (bufferSize > 0 ) {
136+ delegate .socket ().setSendBufferSize (bufferSize );
137+ }
138+ this .delegate = delegate ;
139+ System .out .println ("================Set up complete." );
140+ } catch (Exception e ) {
141+ System .out .println ("================Failed to connect to UDS at: " + socketPath );
142+ try {
143+ delegate .close ();
144+ } catch (IOException __ ) {
145+ // ignore
146+ }
147+ throw new IOException ("Failed to connect to Unix Domain Socket: " + socketPath , e );
147148 }
148149 }
149150
@@ -155,6 +156,7 @@ private void connectJnrSocket(long deadline) throws IOException {
155156 delegate .setOption (UnixSocketOptions .SO_SNDTIMEO , connectionTimeout );
156157 }
157158 try {
159+ System .out .println ("================Attempting to connect delegate to: " + address );
158160 if (!delegate .connect ((UnixSocketAddress ) address )) {
159161 if (connectionTimeout > 0 && System .nanoTime () > deadline ) {
160162 throw new IOException ("Connection timed out" );
@@ -163,11 +165,13 @@ private void connectJnrSocket(long deadline) throws IOException {
163165 throw new IOException ("Connection failed" );
164166 }
165167 }
168+ System .out .println ("================Connection successful" );
166169 delegate .setOption (UnixSocketOptions .SO_SNDTIMEO , Math .max (timeout , 0 ));
167170 if (bufferSize > 0 ) {
168171 delegate .setOption (UnixSocketOptions .SO_SNDBUF , bufferSize );
169172 }
170173 this .delegate = delegate ;
174+ System .out .println ("================Set up complete." );
171175 } catch (Exception e ) {
172176 try {
173177 delegate .close ();
0 commit comments