[gem5-dev] [M] Change in gem5/gem5[develop]: base: Remove the now unused UnixSocketAddr class and associated code.

2023-04-11 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/69169?usp=email )


Change subject: base: Remove the now unused UnixSocketAddr class and  
associated code.

..

base: Remove the now unused UnixSocketAddr class and associated code.

This job is now handled by the python param code, and the ListenSocket
classes.

Change-Id: I3a29b880b2484c5e25071bdef59fc73e1e8c2760
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69169
Tested-by: kokoro 
Maintainer: Gabe Black 
Reviewed-by: Simon Park 
---
M src/base/socket.cc
M src/base/socket.hh
M src/base/socket.test.cc
3 files changed, 0 insertions(+), 167 deletions(-)

Approvals:
  Simon Park: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/base/socket.cc b/src/base/socket.cc
index a30c6af..76dc73f 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -61,75 +61,12 @@

 namespace gem5
 {
-namespace
-{
-
-bool
-isSocketNameAbstract(const std::string &path)
-{
-if (path.empty()) {
-return false;
-}
-// No null byte should be present in the path
-return path.front() == '@';
-}
-
-std::string
-resolve(const std::string &path)
-{
-if (path.empty()) {
-return path;
-}
-if (isSocketNameAbstract(path)) {
-return '\0' + path.substr(1);
-}
-return simout.resolve(path);
-}
-
-}  // namespace

 bool ListenSocket::listeningDisabled = false;
 bool ListenSocket::anyListening = false;

 bool ListenSocket::bindToLoopback = false;

-UnixSocketAddr
-UnixSocketAddr::build(const std::string &path)
-{
-sockaddr_un addr = {.sun_family = AF_UNIX, .sun_path = {}};
-
-const bool is_abstract = isSocketNameAbstract(path);
-size_t max_len = sizeof(addr.sun_path);
-if (!is_abstract) {
-// File based socket names need to be null terminated
-max_len -= 1;
-}
-
-std::string resolved_path = resolve(path);
-std::string fmt_path = replace(resolved_path, '\0', '@');
-if (resolved_path.size() > max_len) {
-resolved_path = resolved_path.substr(0, max_len);
-const std::string untruncated_path = std::move(fmt_path);
-fmt_path = replace(resolved_path, '\0', '@');
-warn("SocketPath: unix socket path truncated from '%s' to '%s'",
- untruncated_path, fmt_path);
-}
-
-// We can't use strncpy here, since abstract sockets start with \0  
which

-// will make strncpy think that the string is empty.
-memcpy(addr.sun_path, resolved_path.c_str(), resolved_path.size());
-// We can't use sizeof(sockaddr_un) for abstract sockets, since all
-// sizeof(sun_path) bytes are used in representing the path.
-const size_t path_size =
-is_abstract ? resolved_path.size() : sizeof(addr.sun_path);
-const size_t addr_size = offsetof(sockaddr_un, sun_path) + path_size;
-
-return UnixSocketAddr{.addr = std::move(addr),
-  .addrSize = addr_size,
-  .isAbstract = is_abstract,
-  .formattedPath = std::move(fmt_path)};
-}
-
 void
 ListenSocket::cleanup()
 {
diff --git a/src/base/socket.hh b/src/base/socket.hh
index 5ae02aa..b8828e7 100644
--- a/src/base/socket.hh
+++ b/src/base/socket.hh
@@ -43,37 +43,6 @@
 namespace gem5
 {

-/**
- * @brief Wrapper around sockaddr_un, so that it can be used for both file
- * based unix sockets as well as abstract unix sockets.
- */
-struct UnixSocketAddr
-{
-/**
- * @brief Builds UnixSocketAddr from the given path.
- * @pre: `path` either represents a file based unix socket, or an  
abstract
- *   unix socket. If `path` represents an abstract socket, it  
should

- *   start with the character '@', and it should not have any null
- *   bytes in the name.
- * @param path: Pathname, where the socket should be instantiated.
- * @return UnixSocketAddr
- */
-static UnixSocketAddr build(const std::string &path);
-
-sockaddr_un addr;
-// Size of `sockaddr_un addr`. This is equal to sizeof(sockaddr_un) if
-// `addr` represents a normal file based unix socket. For abstract  
sockets
-// however, the size could be different. Because all sizeof(sun_path)  
is
-// used to represent the name of an abstract socket, addrSize for  
abstract
-// sockets only count the number of characters actually used by  
sun_path,

-// excluding any trailing null bytes.
-size_t addrSize;
-bool isAbstract;
-// Formatted string for file based sockets look the same as  
addr.sun_path.

-// For abstract sockets however, all null bytes are replaced with @
-std::string formattedPath;
-};
-
 class ListenSocket : public Named
 {
   protected:
diff --git a/src/base/socket.test.cc b/src/base/socket.test.cc
index 7bf9e18..5fd0f3f 100644
--- a/src/base/socket.test.cc
+++ b/src/base/socke

[gem5-dev] [M] Change in gem5/gem5[develop]: base: Remove the now unused UnixSocketAddr class and associated code.

2023-03-21 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/69169?usp=email )



Change subject: base: Remove the now unused UnixSocketAddr class and  
associated code.

..

base: Remove the now unused UnixSocketAddr class and associated code.

This job is now handled by the python param code, and the ListenSocket
classes.

Change-Id: I3a29b880b2484c5e25071bdef59fc73e1e8c2760
---
M src/base/socket.cc
M src/base/socket.hh
M src/base/socket.test.cc
3 files changed, 0 insertions(+), 167 deletions(-)



diff --git a/src/base/socket.cc b/src/base/socket.cc
index 0ef0062..86012bb 100644
--- a/src/base/socket.cc
+++ b/src/base/socket.cc
@@ -49,75 +49,12 @@

 namespace gem5
 {
-namespace
-{
-
-bool
-isSocketNameAbstract(const std::string &path)
-{
-if (path.empty()) {
-return false;
-}
-// No null byte should be present in the path
-return path.front() == '@';
-}
-
-std::string
-resolve(const std::string &path)
-{
-if (path.empty()) {
-return path;
-}
-if (isSocketNameAbstract(path)) {
-return '\0' + path.substr(1);
-}
-return simout.resolve(path);
-}
-
-}  // namespace

 bool ListenSocket::listeningDisabled = false;
 bool ListenSocket::anyListening = false;

 bool ListenSocket::bindToLoopback = false;

-UnixSocketAddr
-UnixSocketAddr::build(const std::string &path)
-{
-sockaddr_un addr = {.sun_family = AF_UNIX, .sun_path = {}};
-
-const bool is_abstract = isSocketNameAbstract(path);
-size_t max_len = sizeof(addr.sun_path);
-if (!is_abstract) {
-// File based socket names need to be null terminated
-max_len -= 1;
-}
-
-std::string resolved_path = resolve(path);
-std::string fmt_path = replace(resolved_path, '\0', '@');
-if (resolved_path.size() > max_len) {
-resolved_path = resolved_path.substr(0, max_len);
-const std::string untruncated_path = std::move(fmt_path);
-fmt_path = replace(resolved_path, '\0', '@');
-warn("SocketPath: unix socket path truncated from '%s' to '%s'",
- untruncated_path, fmt_path);
-}
-
-// We can't use strncpy here, since abstract sockets start with \0  
which

-// will make strncpy think that the string is empty.
-memcpy(addr.sun_path, resolved_path.c_str(), resolved_path.size());
-// We can't use sizeof(sockaddr_un) for abstract sockets, since all
-// sizeof(sun_path) bytes are used in representing the path.
-const size_t path_size =
-is_abstract ? resolved_path.size() : sizeof(addr.sun_path);
-const size_t addr_size = offsetof(sockaddr_un, sun_path) + path_size;
-
-return UnixSocketAddr{.addr = std::move(addr),
-  .addrSize = addr_size,
-  .isAbstract = is_abstract,
-  .formattedPath = std::move(fmt_path)};
-}
-
 void
 ListenSocket::cleanup()
 {
diff --git a/src/base/socket.hh b/src/base/socket.hh
index 5974348..123a6fe 100644
--- a/src/base/socket.hh
+++ b/src/base/socket.hh
@@ -43,37 +43,6 @@
 namespace gem5
 {

-/**
- * @brief Wrapper around sockaddr_un, so that it can be used for both file
- * based unix sockets as well as abstract unix sockets.
- */
-struct UnixSocketAddr
-{
-/**
- * @brief Builds UnixSocketAddr from the given path.
- * @pre: `path` either represents a file based unix socket, or an  
abstract
- *   unix socket. If `path` represents an abstract socket, it  
should

- *   start with the character '@', and it should not have any null
- *   bytes in the name.
- * @param path: Pathname, where the socket should be instantiated.
- * @return UnixSocketAddr
- */
-static UnixSocketAddr build(const std::string &path);
-
-sockaddr_un addr;
-// Size of `sockaddr_un addr`. This is equal to sizeof(sockaddr_un) if
-// `addr` represents a normal file based unix socket. For abstract  
sockets
-// however, the size could be different. Because all sizeof(sun_path)  
is
-// used to represent the name of an abstract socket, addrSize for  
abstract
-// sockets only count the number of characters actually used by  
sun_path,

-// excluding any trailing null bytes.
-size_t addrSize;
-bool isAbstract;
-// Formatted string for file based sockets look the same as  
addr.sun_path.

-// For abstract sockets however, all null bytes are replaced with @
-std::string formattedPath;
-};
-
 class ListenSocket : public Named
 {
   protected:
diff --git a/src/base/socket.test.cc b/src/base/socket.test.cc
index 7bf9e18..5fd0f3f 100644
--- a/src/base/socket.test.cc
+++ b/src/base/socket.test.cc
@@ -45,79 +45,6 @@
  * socket.cc have not been fully tested due to interaction with  
system-calls.

  */

-namespace {
-
-std::string
-repeat(const std::string& str, size_t n)
-{
-std::stringstream ss;
-for (int i = 0; i < n; ++i) {