mem: multi-clients support for SharedMemoryServer
Record the client session with a map instead of a single unique_ptr so our server can interact with multiple clients at once. This will also avoid a race condition case where the client thought it has closed previous connection and is trying to a new one while the server hasn't clean up the previous entry and raise a fatal error. Change-Id: Id08154fc4b54d2611629875b3f4e0d66c0e2ed92 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/61049 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Yu-hsin Wang <yuhsingw@google.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
@@ -136,12 +136,10 @@ SharedMemoryServer::ListenSocketEvent::process(int revents)
|
||||
int cli_fd = ListenSocket::acceptCloexec(pfd.fd, nullptr, nullptr);
|
||||
panic_if(cli_fd < 0, "%s: accept failed: %s", name().c_str(),
|
||||
strerror(errno));
|
||||
panic_if(shmServer->clientSocketEvent.get(),
|
||||
"%s: cannot serve two clients at once", name().c_str());
|
||||
inform("%s: accept new connection %d", name().c_str(), cli_fd);
|
||||
shmServer->clientSocketEvent.reset(
|
||||
shmServer->clientSocketEvents[cli_fd].reset(
|
||||
new ClientSocketEvent(cli_fd, shmServer));
|
||||
pollQueue.schedule(shmServer->clientSocketEvent.get());
|
||||
pollQueue.schedule(shmServer->clientSocketEvents[cli_fd].get());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -241,7 +239,7 @@ SharedMemoryServer::ClientSocketEvent::process(int revents)
|
||||
// somehow broken. We'll just close the connection and move on.
|
||||
inform("%s: closing connection", name().c_str());
|
||||
close(pfd.fd);
|
||||
shmServer->clientSocketEvent.reset();
|
||||
shmServer->clientSocketEvents.erase(pfd.fd);
|
||||
}
|
||||
|
||||
} // namespace memory
|
||||
|
||||
Reference in New Issue
Block a user