return sendMessageImpl(packed);
}
catch (SocketException se) {
- myDebugger.disconnect();
- myDebugger.fireCommunicationError();
+ onSocketException();
}
catch (IOException e) {
LOG.debug(e);
protected abstract boolean sendMessageImpl(byte[] packed) throws IOException;
+ protected abstract void onSocketException();
+
public static void logFrame(ProtocolFrame frame, boolean out) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("%1$tH:%1$tM:%1$tS.%1$tL %2$s %3$s\n", new Date(), (out ? "<<<" : ">>>"), frame));
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* {@link DebuggerTransport} implementation that expects a debugging script to behave as a server. The main process of the debugging script
"Inappropriate state of Python debugger for connecting to Python debugger: " + myState + "; " + State.INIT + " is expected");
}
- doConnect();
- }
-
- private void doConnect() throws IOException {
synchronized (mySocketObject) {
if (mySocket != null) {
try {
beforeHandshake.countDown();
try {
myDebugger.handshake();
+ myDebuggerReader.connectionApproved();
return true;
}
catch (PyDebuggerException e) {
}
}
+ @Override
+ protected void onSocketException() {
+ myDebugger.disconnect();
+ if (myState == State.APPROVED) {
+ myDebugger.fireCommunicationError();
+ }
+ }
+
@Override
public void close() {
try {
DISCONNECTED
}
- public class DebuggerReader extends BaseDebuggerReader {
+ public static class DebuggerReader extends BaseDebuggerReader {
+ /**
+ * Indicates that the debugger connection has been approved within this {@link DebuggerReader}.
+ */
+ private final AtomicBoolean myConnectionApproved = new AtomicBoolean(false);
+
public DebuggerReader(@NotNull RemoteDebugger debugger, @NotNull InputStream stream) throws IOException {
super(stream, CharsetToolkit.UTF8_CHARSET, debugger); //TODO: correct encoding?
start(getClass().getName());
@Override
protected void onExit() {
- if (myState == State.APPROVED) {
+ if (myConnectionApproved.get()) {
getDebugger().fireExitEvent();
}
}
@Override
protected void onCommunicationError() {
- if (myState == State.APPROVED) {
+ if (myConnectionApproved.get()) {
getDebugger().fireCommunicationError();
}
}
+
+ public void connectionApproved() {
+ myConnectionApproved.set(true);
+ }
}
}
}
}
+ @Override
+ protected void onSocketException() {
+ myDebugger.disconnect();
+ myDebugger.fireCommunicationError();
+ }
+
public static class DebuggerReader extends BaseDebuggerReader {
public DebuggerReader(@NotNull RemoteDebugger debugger, @NotNull InputStream stream) throws IOException {
super(stream, CharsetToolkit.UTF8_CHARSET, debugger); //TODO: correct encoding?