This is an automated email from the ASF dual-hosted git repository.
jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 30dfef16 Fix UDS ut failed on MacOS
new 0e10bdb9 Merge pull request #1843 from wwbmmm/fix-uds-ut-on-mac
30dfef16 is described below
commit 30dfef1665601fd6efe3996417749aa45d997565
Author: wwbmmm <[email protected]>
AuthorDate: Mon Jul 18 17:55:48 2022 +0800
Fix UDS ut failed on MacOS
---
src/butil/details/extended_endpoint.hpp | 8 +++++++-
test/endpoint_unittest.cpp | 23 ++++++++++-------------
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/src/butil/details/extended_endpoint.hpp
b/src/butil/details/extended_endpoint.hpp
index e969d9d7..36a67719 100644
--- a/src/butil/details/extended_endpoint.hpp
+++ b/src/butil/details/extended_endpoint.hpp
@@ -163,6 +163,9 @@ public:
eep->_u.in6.sin6_flowinfo = 0u;
eep->_u.in6.sin6_scope_id = 0u;
eep->_socklen = sizeof(_u.in6);
+#if defined(OS_MACOSX)
+ eep->_u.in6.sin6_len = eep->_socklen;
+#endif
}
} else if (sp.starts_with("unix:")) { // ignore port
sp.remove_prefix(5); // remove `unix:'
@@ -174,6 +177,9 @@ public:
int size = sp.copy(eep->_u.un.sun_path, sp.size());
eep->_u.un.sun_path[size] = '\0';
eep->_socklen = offsetof(sockaddr_un, sun_path) + size + 1;
+#if defined(OS_MACOSX)
+ eep->_u.un.sun_len = eep->_socklen;
+#endif
}
}
if (eep) {
@@ -374,4 +380,4 @@ inline bool
GlobalEndPointSet::Equals::operator()(ExtendedEndPoint* const& p1, E
} // namespace details
} // namespace butil
-#endif // BUTIL_DETAILS_EXTENDED_ENDPOINT_H
\ No newline at end of file
+#endif // BUTIL_DETAILS_EXTENDED_ENDPOINT_H
diff --git a/test/endpoint_unittest.cpp b/test/endpoint_unittest.cpp
index 8b515ef3..4cb7f757 100644
--- a/test/endpoint_unittest.cpp
+++ b/test/endpoint_unittest.cpp
@@ -156,9 +156,6 @@ void* server_proc(void* arg) {
sockaddr_storage ss;
socklen_t len = sizeof(ss);
int fd = accept(listen_fd, (sockaddr*)&ss, &len);
- if (fd > 0) {
- close(fd);
- }
return (void*)(int64_t)fd;
}
@@ -190,7 +187,9 @@ static void test_listen_connect(const std::string&
server_addr, const std::strin
void* ret = nullptr;
pthread_join(pid, &ret);
- ASSERT_GT((int64_t)ret, 0);
+ int server_fd = (int)(int64_t)ret;
+ ASSERT_GT(server_fd, 0);
+ close(server_fd);
close(listen_fd);
}
@@ -238,12 +237,12 @@ TEST(EndPointTest, unix_socket) {
ASSERT_EQ(0, butil::str2endpoint("unix://a.sock", 123, &point));
ASSERT_EQ(std::string("unix://a.sock"),
butil::endpoint2str(point).c_str());
- ASSERT_EQ(-1,
butil::str2endpoint("unix:tooloooooooooooooooooooooooooooooooooooooooooooooooooo"
- "ooooooooooooooooooooooooooooooooooooooooooooooong.sock", &point));
- ASSERT_EQ(0, butil::str2endpoint("
unix:loooooooooooooooooooooooooooooooooooooooooooooooooooo"
- "ooooooooooooooooooooooooooooooooooooooooooooooong.sock", &point));
-
ASSERT_EQ(std::string("unix:loooooooooooooooooooooooooooooooooooooooooooooooooooo"
- "ooooooooooooooooooooooooooooooooooooooooooooooong.sock"),
butil::endpoint2str(point).c_str());
+ std::string long_path = "unix:";
+ long_path.append(sizeof(sockaddr_un::sun_path) - 1, 'a');
+ ASSERT_EQ(0, butil::str2endpoint(long_path.c_str(), &point));
+ ASSERT_EQ(long_path, butil::endpoint2str(point).c_str());
+ long_path.push_back('a');
+ ASSERT_EQ(-1, butil::str2endpoint(long_path.c_str(), &point));
char buf[128] = {0}; // braft use this size of buffer
size_t ret = snprintf(buf, sizeof(buf), "%s:%d",
butil::endpoint2str(point).c_str(), INT_MAX);
ASSERT_LT(ret, sizeof(buf) - 1);
@@ -383,9 +382,7 @@ TEST(EndPointTest, endpoint_sockaddr_conv_ipv6) {
in6_addr expect_in6_addr;
bzero(&expect_in6_addr, sizeof(expect_in6_addr));
- expect_in6_addr.__in6_u.__u6_addr8[15] = 1;
- // jge: mac monterey上应该这样,但准确判定条件不明
- //expect_in6_addr.__u6_addr.__u6_addr8[15] = 1;
+ expect_in6_addr.s6_addr[15] = 1;
sockaddr_storage ss;
const sockaddr_in6* sa6 = (sockaddr_in6*) &ss;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]