Skip to content

Commit

Permalink
more descriptive names
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Dec 11, 2023
1 parent bf1f2e1 commit fd9e676
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions include/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/Export.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef struct {
char* host;
char* port;
char* alias;
} ServerSpec;
} server_string_split_t;


typedef int64_t exptime_t;
Expand Down
2 changes: 1 addition & 1 deletion include/c_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions libmc/_client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/c_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions tests/test_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ 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");
}

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");
}

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");
}

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");
Expand Down

0 comments on commit fd9e676

Please sign in to comment.