@@ -49,6 +49,8 @@ public boolean isOpen() {
4949 public synchronized int write (ByteBuffer src ) throws IOException {
5050 connectIfNeeded ();
5151
52+ System .out .println ("========== Write called - delegate state: open=" + delegate .isOpen () + ", connected=" + delegate .isConnected ());
53+
5254 int size = src .remaining ();
5355 int written = 0 ;
5456 if (size == 0 ) {
@@ -60,11 +62,17 @@ public synchronized int write(ByteBuffer src) throws IOException {
6062
6163 try {
6264 long deadline = System .nanoTime () + timeout * 1_000_000L ;
65+ System .out .println ("========== About to write delimiter buffer, size: " + delimiterBuffer .remaining ());
6366 written = writeAll (delimiterBuffer , true , deadline );
67+ System .out .println ("========== Delimiter buffer written, bytes: " + written );
6468 if (written > 0 ) {
69+ System .out .println ("========== About to write src buffer, size: " + src .remaining ());
6570 written += writeAll (src , false , deadline );
71+ System .out .println ("========== Src buffer written, total bytes: " + written );
6672 }
6773 } catch (IOException e ) {
74+ System .out .println ("========== Write failed with IOException: " + e .getClass ().getName () + ": " + e .getMessage ());
75+ e .printStackTrace ();
6876 // If we get an exception, it's unrecoverable, we close the channel and try to reconnect
6977 disconnect ();
7078 throw e ;
@@ -111,7 +119,12 @@ public int writeAll(ByteBuffer bb, boolean canReturnOnTimeout, long deadline)
111119 }
112120
113121 private void connectIfNeeded () throws IOException {
122+ System .out .println ("========== connectIfNeeded called - delegate is " + (delegate == null ? "null" : "not null" ));
123+ if (delegate != null ) {
124+ System .out .println ("========== existing delegate state - open: " + delegate .isOpen () + ", connected: " + delegate .isConnected ());
125+ }
114126 if (delegate == null ) {
127+ System .out .println ("========== calling connect()" );
115128 connect ();
116129 }
117130 }
@@ -172,6 +185,7 @@ private void connect() throws IOException {
172185 throw new IOException ("Connection failed" );
173186 }
174187 System .out .println ("========== Connection successful" );
188+ System .out .println ("========== Channel state - open: " + channel .isOpen () + ", connected: " + channel .isConnected ());
175189 // channel.socket().setSoTimeout(Math.max(timeout, 0));
176190 // if (bufferSize > 0) {
177191 // channel.socket().setSendBufferSize(bufferSize);
0 commit comments