From c89beb3113c76d5834071d6ebe293ecc938bfd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 24 Feb 2017 09:06:20 +0000 Subject: [PATCH] First commit to support Darwin #930 --- include/gen_utils.h | 6 ++++-- include/proxysql.h | 2 +- lib/Makefile | 2 +- lib/MySQL_Thread.cpp | 5 ++++- lib/ProxySQL_Admin.cpp | 6 ++++++ lib/mysql_connection.cpp | 6 ++++++ lib/mysql_data_stream.cpp | 7 +++++++ src/Makefile | 10 +++++++++- 8 files changed, 38 insertions(+), 6 deletions(-) diff --git a/include/gen_utils.h b/include/gen_utils.h index b8d4794659..86b99cdf8d 100644 --- a/include/gen_utils.h +++ b/include/gen_utils.h @@ -182,13 +182,15 @@ class PtrSizeArray { #ifndef mach_time_h #define mach_time_h +#ifndef CLOCK_MONOTONIC #define CLOCK_MONOTONIC SYSTEM_CLOCK +#endif // CLOCK_MONOTONIC -void clock_gettime(int clk_id, struct timespec *tp) { +static void clock_gettime(int clk_id, struct timespec *tp) { clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); - retval = clock_get_time(cclock, &mts); + //retval = clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); tp->tv_sec = mts.tv_sec; tp->tv_nsec = mts.tv_nsec; diff --git a/include/proxysql.h b/include/proxysql.h index 93ed715fb3..a49fa4d613 100644 --- a/include/proxysql.h +++ b/include/proxysql.h @@ -48,7 +48,7 @@ #include -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) && !defined(__APPLE__) #define HAVE_BOOL #include "my_global.h" //#include "my_pthread.h" diff --git a/lib/Makefile b/lib/Makefile index 46928073cb..065d5013a4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -26,7 +26,7 @@ SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3 IDIR=../include -IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) +IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(RE2_IDIR) -I$(SQLITE3_DIR) -I$(PCRE_PATH) -I/usr/local/include LDIRS=-L$(JEMALLOC_PATH)/lib -L$(RE2_PATH)/obj -L$(INJECTION_PATH) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index c89f549b17..6ee220d171 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1927,6 +1927,9 @@ MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd) sess->client_myds = new MySQL_Data_Stream(); sess->client_myds->fd=_fd; setsockopt(sess->client_myds->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &arg_on, sizeof(int)); +#ifdef __APPLE__ + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); +#endif sess->client_myds->init(MYDS_FRONTEND, sess, sess->client_myds->fd); proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p, DataStream=%p -- Created new client Data Stream\n", sess->thread, sess, sess->client_myds); #ifdef DEBUG @@ -3800,7 +3803,7 @@ void MySQL_Thread::Get_Memory_Stats() { } else { status_variables.mysql_frontend_buffers_bytes+=(mysql_sessions->len * QUEUE_T_DEFAULT_SIZE * 2); status_variables.mysql_session_internal_bytes+=(mysql_sessions->len * sizeof(MySQL_Connection)); -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) && !defined(__APPLE__) status_variables.mysql_session_internal_bytes+=((sizeof(int) + sizeof(int) + sizeof(std::_Rb_tree_node_base)) * mysql_sessions->len ); #else status_variables.mysql_session_internal_bytes+=((sizeof(int) + sizeof(int) + 32) * mysql_sessions->len ); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 625b072693..75197db9b5 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -35,6 +35,12 @@ #define READ_ONLY_ON "\x01\x00\x00\x01\x02\x23\x00\x00\x02\x03\x64\x65\x66\x00\x00\x00\x0d\x56\x61\x72\x69\x61\x62\x6c\x65\x5f\x6e\x61\x6d\x65\x00\x0c\x21\x00\x0f\x00\x00\x00\xfd\x01\x00\x1f\x00\x00\x1b\x00\x00\x03\x03\x64\x65\x66\x00\x00\x00\x05\x56\x61\x6c\x75\x65\x00\x0c\x21\x00\x0f\x00\x00\x00\xfd\x01\x00\x1f\x00\x00\x05\x00\x00\x04\xfe\x00\x00\x02\x00\x0d\x00\x00\x05\x09\x72\x65\x61\x64\x5f\x6f\x6e\x6c\x79\x02\x4f\x4e\x05\x00\x00\x06\xfe\x00\x00\x02\x00" +#ifdef __APPLE__ +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif // MSG_NOSIGNAL +#endif // __APPLE__ + #define SAFE_SQLITE3_STEP(_stmt) do {\ do {\ rc=sqlite3_step(_stmt);\ diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 46f0dfc7c0..3424ad69ff 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1526,7 +1526,13 @@ void MySQL_Connection::close_mysql() { memcpy(buff, &myhdr, sizeof(mysql_hdr)); buff[4]=0x01; int fd=mysql->net.fd; +#ifdef __APPLE__ + int arg_on=1; + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); + send(fd, buff, 5, 0); +#else send(fd, buff, 5, MSG_NOSIGNAL); +#endif } // int rc=0; mysql_close_no_command(mysql); diff --git a/lib/mysql_data_stream.cpp b/lib/mysql_data_stream.cpp index b030b14262..f0905e4cd8 100644 --- a/lib/mysql_data_stream.cpp +++ b/lib/mysql_data_stream.cpp @@ -317,7 +317,11 @@ int MySQL_Data_Stream::write_to_net() { if (encrypted) { bytes_io = SSL_write (ssl, queue_r_ptr(queueOUT), s); } else { +#ifdef __APPLE__ + bytes_io = send(fd, queue_r_ptr(queueOUT), s, 0); +#else bytes_io = send(fd, queue_r_ptr(queueOUT), s, MSG_NOSIGNAL); +#endif } VALGRIND_ENABLE_ERROR_REPORTING; if (bytes_io < 0) { @@ -791,6 +795,9 @@ int MySQL_Data_Stream::myds_connect(char *address, int connect_port, int *pendin rc=connect(s, (struct sockaddr *) &a, sizeof(a)); int arg_on=1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *) &arg_on, sizeof(int)); +#ifdef __APPLE__ + setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); +#endif } else { rc=connect(s, (struct sockaddr *) &u, len); } diff --git a/src/Makefile b/src/Makefile index 741bfa3595..cd340f6cff 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,6 +34,12 @@ LDIR=../lib IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR) -L$(PCRE_LDIR) +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Darwin) + IDIRS+= -I/usr/local/include + LDIRS+= -L/usr/local/lib +endif MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) LDFLAGS+= @@ -44,7 +50,9 @@ else MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) endif -UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) + MYLIBS=-lssl -lre2 -lmariadbclient -lpthread -lm -lz -liconv -lcrypto +endif ifeq ($(UNAME_S),Linux) MYLIBS+= -ldl endif