base,cpu,dev,sim: Pull common logic into ListenSocket::listen().

Create a version of listen() which handles common logic internally,
including scanning for an available port number, and notifying what
port was chosen.

The port is managed internal to ListenSocket, so that the logic
interacting with it doesn't need to manually manage a port number, and
hence a port number does not need to exist for non AF_INET sockets.

Change-Id: Ie371eccc4d0da5e7b90714508e4cb72fb0091875
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69160
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Yu-hsin Wang <yuhsingw@google.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
Gabe Black
2023-03-18 08:12:56 -07:00
committed by Gabe Black
parent 461520d0ab
commit 67fb75d659
11 changed files with 64 additions and 60 deletions

View File

@@ -39,17 +39,13 @@ namespace gem5
namespace trace {
NativeTrace::NativeTrace(const Params &p)
: ExeTracer(p)
: ExeTracer(p), native_listener(p.name, 8000)
{
if (ListenSocket::allDisabled())
fatal("All listeners are disabled!");
int port = 8000;
while (!native_listener.listen(port)) {
DPRINTF(GDBMisc, "Can't bind port %d\n", port);
port++;
}
ccprintf(std::cerr, "Listening for native process on port %d\n", port);
native_listener.listen();
fd = native_listener.accept();
}