diff --git a/include/Common.h b/include/Common.h index 2414ed41..f7a22de8 100644 --- a/include/Common.h +++ b/include/Common.h @@ -227,7 +227,7 @@ typedef enum { const char* errCodeToString(err_code_t err); bool isLocalSocket(const char* host); -ServerSpec splitServerString(char* input); +server_string_split_t splitServerString(char* input); } // namespace mc } // namespace douban diff --git a/include/Connection.h b/include/Connection.h index d3c12dad..c54f0379 100644 --- a/include/Connection.h +++ b/include/Connection.h @@ -62,7 +62,7 @@ class Connection { protected: int connectPoll(int fd, const sockaddr* ai_ptr, const socklen_t ai_addrlen); - int local(); + int unixSocketConnect(); char m_name[MC_NI_MAXHOST + 1 + MC_NI_MAXSERV]; char m_host[MC_NI_MAXHOST]; @@ -71,7 +71,7 @@ class Connection { int m_socketFd; bool m_alive; bool m_hasAlias; - bool m_local; + bool m_unixSocket; time_t m_deadUntil; io::BufferWriter* m_buffer_writer; // for send io::BufferReader* m_buffer_reader; // for recv diff --git a/include/Export.h b/include/Export.h index 832c0bc9..97a026c0 100644 --- a/include/Export.h +++ b/include/Export.h @@ -42,7 +42,7 @@ typedef struct { char* host; char* port; char* alias; -} ServerSpec; +} server_string_split_t; typedef int64_t exptime_t; diff --git a/include/c_client.h b/include/c_client.h index 53201c8f..21b0c4e9 100644 --- a/include/c_client.h +++ b/include/c_client.h @@ -68,7 +68,7 @@ extern "C" { err_code_t client_quit(void* client); const char* err_code_to_string(err_code_t err); - ServerSpec splitServerString(char* input); + server_string_split_t splitServerString(char* input); #ifdef __cplusplus } #endif diff --git a/libmc/_client.pyx b/libmc/_client.pyx index 611bbcc5..44719d0a 100644 --- a/libmc/_client.pyx +++ b/libmc/_client.pyx @@ -45,7 +45,7 @@ cdef extern from "Common.h" namespace "douban::mc": VERSION_OP QUIT_OP - ServerSpec splitServerString(char* input) nogil + server_string_split_t splitServerString(char* input) nogil cdef extern from "Export.h": @@ -101,7 +101,7 @@ cdef extern from "Export.h": RET_INCOMPLETE_BUFFER_ERR RET_OK - ctypedef struct ServerSpec: + ctypedef struct server_string_split_t: char* host char* port char* alias diff --git a/src/Common.cpp b/src/Common.cpp index fdcf7073..2e75ffca 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -57,9 +57,9 @@ bool isLocalSocket(const char* host) { } // modifies input string and output pointers reference input -ServerSpec splitServerString(char* input) { +server_string_split_t splitServerString(char* input) { bool escaped = false; - ServerSpec res = { input, NULL, NULL }; + server_string_split_t res = { input, NULL, NULL }; for (;; input++) { switch (*input) { diff --git a/src/Connection.cpp b/src/Connection.cpp index c664abde..0b95c8b3 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -23,7 +23,7 @@ namespace mc { Connection::Connection() : m_counter(0), m_port(0), m_socketFd(-1), - m_alive(false), m_hasAlias(false), m_local(false), + m_alive(false), m_hasAlias(false), m_unixSocket(false), m_deadUntil(0), m_connectTimeout(MC_DEFAULT_CONNECT_TIMEOUT), m_retryTimeout(MC_DEFAULT_RETRY_TIMEOUT), m_maxRetries(MC_DEFAULT_MAX_RETRIES), m_retires(0) { @@ -47,10 +47,10 @@ Connection::~Connection() { int Connection::init(const char* host, uint32_t port, const char* alias) { snprintf(m_host, sizeof m_host, "%s", host); m_port = port; - m_local = isLocalSocket(m_host); + m_unixSocket = isLocalSocket(m_host); if (alias == NULL) { m_hasAlias = false; - if (m_local) { + if (m_unixSocket) { snprintf(m_name, sizeof m_name, "%s", m_host); } else { snprintf(m_name, sizeof m_name, "%s:%u", m_host, m_port); @@ -66,8 +66,8 @@ int Connection::init(const char* host, uint32_t port, const char* alias) { int Connection::connect() { assert(!m_alive); this->close(); - if (m_local) { - return local(); + if (m_unixSocket) { + return unixSocketConnect(); } struct addrinfo hints, *server_addrinfo = NULL, *ai_ptr = NULL; @@ -132,7 +132,7 @@ int Connection::connect() { return m_alive ? 0 : -1; } -int Connection::local() { +int Connection::unixSocketConnect() { int fd, flags, opt_keepalive = 1; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { diff --git a/src/c_client.cpp b/src/c_client.cpp index 424e11d1..88b9d128 100644 --- a/src/c_client.cpp +++ b/src/c_client.cpp @@ -160,6 +160,6 @@ const char* err_code_to_string(err_code_t err) { return douban::mc::errCodeToString(err); } -ServerSpec splitServerString(char* input) { +server_string_split_t splitServerString(char* input) { return douban::mc::splitServerString(input); } diff --git a/tests/test_unix.cpp b/tests/test_unix.cpp index 0c9979fc..71743e57 100644 --- a/tests/test_unix.cpp +++ b/tests/test_unix.cpp @@ -28,7 +28,7 @@ TEST(test_unix, establish_connection) { TEST(test_unix, host_parse_regression) { char test[] = "127.0.0.1:21211 testing"; - ServerSpec out = splitServerString(test); + server_string_split_t out = splitServerString(test); ASSERT_STREQ(out.host, "127.0.0.1"); ASSERT_STREQ(out.port, "21211"); ASSERT_STREQ(out.alias, "testing"); @@ -36,7 +36,7 @@ TEST(test_unix, host_parse_regression) { TEST(test_unix, socket_path_spaces) { char test[] = "/tmp/spacey\\ path testing"; - ServerSpec out = splitServerString(test); + server_string_split_t out = splitServerString(test); ASSERT_STREQ(out.host, "/tmp/spacey\\ path"); ASSERT_EQ(out.port, nullptr); ASSERT_STREQ(out.alias, "testing"); @@ -44,7 +44,7 @@ TEST(test_unix, socket_path_spaces) { TEST(test_unix, socket_path_escaping) { char test[] = "/tmp/spicy\\\\ path testing"; - ServerSpec out = splitServerString(test); + server_string_split_t out = splitServerString(test); ASSERT_STREQ(out.host, "/tmp/spicy\\\\"); ASSERT_EQ(out.port, nullptr); ASSERT_STREQ(out.alias, "path"); @@ -52,7 +52,7 @@ TEST(test_unix, socket_path_escaping) { TEST(test_unix, alias_space_escaping) { char test[] = "/tmp/path testing\\ alias"; - ServerSpec out = splitServerString(test); + server_string_split_t out = splitServerString(test); ASSERT_STREQ(out.host, "/tmp/path"); ASSERT_EQ(out.port, nullptr); ASSERT_STREQ(out.alias, "testing\\ alias");