Skip to content

Commit

Permalink
First commit to support Darwin #930
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Feb 24, 2017
1 parent d5f4a8b commit c89beb3
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
6 changes: 4 additions & 2 deletions include/gen_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/proxysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

#include <sys/ioctl.h>

#ifndef __FreeBSD__
#if !defined(__FreeBSD__) && !defined(__APPLE__)
#define HAVE_BOOL
#include "my_global.h"
//#include "my_pthread.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);\
Expand Down
6 changes: 6 additions & 0 deletions lib/mysql_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions lib/mysql_data_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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+=
Expand All @@ -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
Expand Down

0 comments on commit c89beb3

Please sign in to comment.