Skip to content

Commit

Permalink
fix(port): updated code for port verification
Browse files Browse the repository at this point in the history
  • Loading branch information
alirana01 committed Sep 16, 2024
2 parents c16c63c + 5d4bfad commit 14058df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,32 @@ public static boolean isPortAvailable(int port)
{
try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
{
// If the socket opens, the port is in use
return false;
}
catch (IOException e)
{
// Port is unavailable, retrying if there are attempts left
if (attempts == retryCount)
// If the socket opens, the port is in use, so retry
attempts++;
if (attempts > retryCount)
{
// After exhausting all retries, return false
Logger.log("Port " + port + " is not available after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return false; // Failure, port is still not available
Logger.log("Port " + port + " is still in use after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return false; // After all retries, port is still not available
}

attempts++;

// Log retry attempt
Logger.log("Attempt " + attempts + " failed, retrying in " + retryDelayMillis + " ms..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

try
{
Thread.sleep(retryDelayMillis);
}
catch (InterruptedException interruptedException)
{
Thread.currentThread().interrupt(); // Restore interrupt status
Logger.log("Port availability check interrupted."); //$NON-NLS-1$
return false; // If interrupted, assume port unavailable and stop
}
Thread.sleep(retryDelayMillis);
}
catch (IOException e)
{
// If we get an IOException, the port is not in use, return true
return true;
}
catch (InterruptedException interruptedException)
{
// Handle interruption and stop further attempts
Thread.currentThread().interrupt(); // Restore interrupt status
Logger.log("Port availability check interrupted."); //$NON-NLS-1$
return false;
}
}
return true; //Fallback not reachable

return true; // Port is available if no exceptions occurred
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab

protected Button fUpdateThreadlistOnSuspend;

private Group gdbRemoteGroup;

private DefaultPreferences fDefaultPreferences;
private PersistentPreferences fPersistentPreferences;

Expand Down Expand Up @@ -570,6 +572,11 @@ public void widgetSelected(SelectionEvent e)
if (fDoStartGdbServer.getSelection())
{
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
gdbRemoteGroup.setEnabled(false);
}
else
{
gdbRemoteGroup.setEnabled(true);
}
scheduleUpdateJob();
}
Expand Down Expand Up @@ -836,16 +843,17 @@ public void widgetSelected(SelectionEvent e)
private void createRemoteControl(Composite parent)
{

Group group = new Group(parent, SWT.NONE);
gdbRemoteGroup = new Group(parent, SWT.NONE);
{
group.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); //$NON-NLS-1$
gdbRemoteGroup.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); //$NON-NLS-1$
GridLayout layout = new GridLayout();
group.setLayout(layout);
gdbRemoteGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
group.setLayoutData(gd);
gdbRemoteGroup.setLayoutData(gd);
gdbRemoteGroup.setEnabled(false);
}

Composite comp = new Composite(group, SWT.NONE);
Composite comp = new Composite(gdbRemoteGroup, SWT.NONE);
{
GridLayout layout = new GridLayout();
layout.numColumns = 2;
Expand Down

0 comments on commit 14058df

Please sign in to comment.