Skip to content

Commit 14058df

Browse files
committed
fix(port): updated code for port verification
2 parents c16c63c + 5d4bfad commit 14058df

File tree

2 files changed

+33
-30
lines changed
  • bundles
    • com.espressif.idf.core/src/com/espressif/idf/core/util
    • com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui

2 files changed

+33
-30
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,32 @@ public static boolean isPortAvailable(int port)
3333
{
3434
try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
3535
{
36-
// If the socket opens, the port is in use
37-
return false;
38-
}
39-
catch (IOException e)
40-
{
41-
// Port is unavailable, retrying if there are attempts left
42-
if (attempts == retryCount)
36+
// If the socket opens, the port is in use, so retry
37+
attempts++;
38+
if (attempts > retryCount)
4339
{
44-
// After exhausting all retries, return false
45-
Logger.log("Port " + port + " is not available after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
46-
return false; // Failure, port is still not available
40+
Logger.log("Port " + port + " is still in use after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
41+
return false; // After all retries, port is still not available
4742
}
48-
49-
attempts++;
50-
51-
// Log retry attempt
5243
Logger.log("Attempt " + attempts + " failed, retrying in " + retryDelayMillis + " ms..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
5344

54-
try
55-
{
56-
Thread.sleep(retryDelayMillis);
57-
}
58-
catch (InterruptedException interruptedException)
59-
{
60-
Thread.currentThread().interrupt(); // Restore interrupt status
61-
Logger.log("Port availability check interrupted."); //$NON-NLS-1$
62-
return false; // If interrupted, assume port unavailable and stop
63-
}
45+
Thread.sleep(retryDelayMillis);
46+
}
47+
catch (IOException e)
48+
{
49+
// If we get an IOException, the port is not in use, return true
50+
return true;
51+
}
52+
catch (InterruptedException interruptedException)
53+
{
54+
// Handle interruption and stop further attempts
55+
Thread.currentThread().interrupt(); // Restore interrupt status
56+
Logger.log("Port availability check interrupted."); //$NON-NLS-1$
57+
return false;
6458
}
6559
}
66-
return true; //Fallback not reachable
60+
61+
return true; // Port is available if no exceptions occurred
6762
}
6863

6964
/**

bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab
131131

132132
protected Button fUpdateThreadlistOnSuspend;
133133

134+
private Group gdbRemoteGroup;
135+
134136
private DefaultPreferences fDefaultPreferences;
135137
private PersistentPreferences fPersistentPreferences;
136138

@@ -570,6 +572,11 @@ public void widgetSelected(SelectionEvent e)
570572
if (fDoStartGdbServer.getSelection())
571573
{
572574
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
575+
gdbRemoteGroup.setEnabled(false);
576+
}
577+
else
578+
{
579+
gdbRemoteGroup.setEnabled(true);
573580
}
574581
scheduleUpdateJob();
575582
}
@@ -836,16 +843,17 @@ public void widgetSelected(SelectionEvent e)
836843
private void createRemoteControl(Composite parent)
837844
{
838845

839-
Group group = new Group(parent, SWT.NONE);
846+
gdbRemoteGroup = new Group(parent, SWT.NONE);
840847
{
841-
group.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); //$NON-NLS-1$
848+
gdbRemoteGroup.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); //$NON-NLS-1$
842849
GridLayout layout = new GridLayout();
843-
group.setLayout(layout);
850+
gdbRemoteGroup.setLayout(layout);
844851
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
845-
group.setLayoutData(gd);
852+
gdbRemoteGroup.setLayoutData(gd);
853+
gdbRemoteGroup.setEnabled(false);
846854
}
847855

848-
Composite comp = new Composite(group, SWT.NONE);
856+
Composite comp = new Composite(gdbRemoteGroup, SWT.NONE);
849857
{
850858
GridLayout layout = new GridLayout();
851859
layout.numColumns = 2;

0 commit comments

Comments
 (0)