From 6130cf61a1c5fbd908e88514590ad1f9101a2475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 24 Feb 2017 09:37:12 +0000 Subject: [PATCH] 2nd commit to support Darwin #930 --- include/proxy_defines.h | 2 +- lib/Makefile | 6 ++++++ lib/MySQL_Monitor.cpp | 6 ++++++ lib/MySQL_Protocol.cpp | 2 +- lib/MySQL_Thread.cpp | 2 +- lib/mysql_connection.cpp | 2 +- src/Makefile | 3 +++ 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/proxy_defines.h b/include/proxy_defines.h index 428d132f37..3e2af91d0d 100644 --- a/include/proxy_defines.h +++ b/include/proxy_defines.h @@ -2,7 +2,7 @@ // If defined then active pthread mutex in ProxySQL_Admin else use the wrlock #define PA_PTHREAD_MUTEX -#ifndef __FreeBSD__ +#if !defined(__FreeBSD__) && !defined(__APPLE__) // If enabled, it adds support for auxiliary threads #define IDLE_THREADS #endif diff --git a/lib/Makefile b/lib/Makefile index 065d5013a4..320f2a781d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -47,6 +47,12 @@ NOJEM=-DNOJEM else NOJEM= endif + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Darwin) +NOJEM=-DNOJEM +endif + MYCFLAGS=$(IDIRS) $(OPTZ) $(DEBUG) -Wall -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) MYCPPFLAGS=-std=c++11 $(MYCFLAGS) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 3b172b5598..92cc53f565 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -110,7 +110,13 @@ static void close_mysql(MYSQL *my) { memcpy(buff, &myhdr, sizeof(mysql_hdr)); buff[4]=0x01; int fd=my->net.fd; +#ifdef __APPLE__ + int arg_on=1; + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); + int wb=send(fd, buff, 5, 0); +#else int wb=send(fd, buff, 5, MSG_NOSIGNAL); +#endif fd+=wb; // dummy, to make compiler happy fd-=wb; // dummy, to make compiler happy } diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index 8939931125..b1263c8b1d 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -10,7 +10,7 @@ extern MySQL_Threads_Handler *GloMTH; #undef max_allowed_packet #endif -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__APPLE__) typedef uint8_t uint8; typedef uint8_t uchar; #endif diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 6ee220d171..33f6af0d80 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1928,7 +1928,7 @@ MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd) 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)); + setsockopt(sess->client_myds->fd, 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); diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index 3424ad69ff..94e4d3c802 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -1528,7 +1528,7 @@ void MySQL_Connection::close_mysql() { int fd=mysql->net.fd; #ifdef __APPLE__ int arg_on=1; - setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (char *) &arg_on, sizeof(int)); send(fd, buff, 5, 0); #else send(fd, buff, 5, MSG_NOSIGNAL); diff --git a/src/Makefile b/src/Makefile index cd340f6cff..94bf2fa572 100644 --- a/src/Makefile +++ b/src/Makefile @@ -61,6 +61,9 @@ ifeq ($(UNAME_S),FreeBSD) endif LIBPROXYSQLAR=$(LDIR)/libproxysql.a +ifeq ($(UNAME_S),Darwin) + LIBPROXYSQLAR=$(LDIR)/libproxysql.a ../deps/pcre/pcre/.libs/libpcre.a ../deps/pcre/pcre/.libs/libpcrecpp.a ../deps/libdaemon/libdaemon/libdaemon/.libs/libdaemon.a ../deps/libconfig/libconfig/lib/.libs/libconfig++.a ../deps/libconfig/libconfig/lib/.libs/libconfig.a ../deps/sqlite3/sqlite3/sqlite3.o +endif ODIR= obj