Changes to connect infrastructure
This commit is contained in:
parent
39c8695819
commit
78c371e92f
@ -148,7 +148,7 @@ GWPROTOCOL *funcs;
|
||||
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
|
||||
dcb->session = session;
|
||||
|
||||
if ((dcb->fd = dcb->func.connect(server, session)) == -1)
|
||||
if ((dcb->fd = dcb->func.connect(dcb, server, session)) == -1)
|
||||
{
|
||||
free(dcb);
|
||||
return NULL;
|
||||
|
@ -71,7 +71,7 @@ typedef struct gw_protocol {
|
||||
int (*error)(struct dcb *);
|
||||
int (*hangup)(struct dcb *);
|
||||
int (*accept)(struct dcb *);
|
||||
int (*connect)(struct server *, struct session *);
|
||||
int (*connect)(struct dcb *, struct server *, struct session *);
|
||||
int (*close)(struct dcb *);
|
||||
int (*listen)(struct dcb *, char *);
|
||||
} GWPROTOCOL;
|
||||
|
@ -76,25 +76,26 @@ mysql_common.o: mysql_common.c ../include/mysql_client_server_protocol.h \
|
||||
/usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \
|
||||
/usr/include/bits/setjmp.h ../../include/buffer.h \
|
||||
../../include/session.h
|
||||
mysql_backend.o: mysql_backend.c \
|
||||
../include/mysql_client_server_protocol.h /usr/include/stdio.h \
|
||||
/usr/include/features.h /usr/include/sys/cdefs.h \
|
||||
mysql_backend.o: mysql_backend.c ../../include/session.h \
|
||||
/usr/include/time.h /usr/include/features.h /usr/include/sys/cdefs.h \
|
||||
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
|
||||
/usr/include/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stddef.h \
|
||||
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
|
||||
/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \
|
||||
/usr/include/bits/time.h /usr/include/bits/types.h \
|
||||
/usr/include/bits/typesizes.h /usr/include/xlocale.h \
|
||||
../../include/server.h ../include/mysql_client_server_protocol.h \
|
||||
/usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h \
|
||||
/usr/include/wchar.h \
|
||||
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/include/stdarg.h \
|
||||
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
|
||||
/usr/include/stdlib.h /usr/include/bits/waitflags.h \
|
||||
/usr/include/bits/waitstatus.h /usr/include/endian.h \
|
||||
/usr/include/bits/endian.h /usr/include/bits/byteswap.h \
|
||||
/usr/include/sys/types.h /usr/include/time.h /usr/include/sys/select.h \
|
||||
/usr/include/sys/types.h /usr/include/sys/select.h \
|
||||
/usr/include/bits/select.h /usr/include/bits/sigset.h \
|
||||
/usr/include/bits/time.h /usr/include/sys/sysmacros.h \
|
||||
/usr/include/bits/pthreadtypes.h /usr/include/alloca.h \
|
||||
/usr/include/stdint.h /usr/include/bits/wchar.h /usr/include/string.h \
|
||||
/usr/include/xlocale.h /usr/include/openssl/sha.h \
|
||||
/usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
|
||||
/usr/include/alloca.h /usr/include/stdint.h /usr/include/bits/wchar.h \
|
||||
/usr/include/string.h /usr/include/openssl/sha.h \
|
||||
/usr/include/openssl/e_os2.h /usr/include/openssl/opensslconf.h \
|
||||
/usr/include/openssl/opensslconf-x86_64.h /usr/include/sys/ioctl.h \
|
||||
/usr/include/bits/ioctls.h /usr/include/asm/ioctls.h \
|
||||
@ -114,8 +115,7 @@ mysql_backend.o: mysql_backend.c \
|
||||
/usr/include/fcntl.h /usr/include/bits/fcntl.h /usr/include/bits/stat.h \
|
||||
../../include/dcb.h ../../include/spinlock.h ../../include/thread.h \
|
||||
/usr/include/pthread.h /usr/include/sched.h /usr/include/bits/sched.h \
|
||||
/usr/include/bits/setjmp.h ../../include/buffer.h \
|
||||
../../include/session.h
|
||||
/usr/include/bits/setjmp.h ../../include/buffer.h
|
||||
mysql_common.o: mysql_common.c ../include/mysql_client_server_protocol.h \
|
||||
/usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \
|
||||
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
|
||||
|
@ -15,7 +15,8 @@
|
||||
*
|
||||
* Copyright SkySQL Ab 2013
|
||||
*/
|
||||
|
||||
#include <session.h>
|
||||
#include <server.h>
|
||||
#include "mysql_client_server_protocol.h"
|
||||
|
||||
/*
|
||||
@ -34,6 +35,7 @@ int gw_read_backend_event(DCB* dcb);
|
||||
int gw_write_backend_event(DCB *dcb);
|
||||
int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue);
|
||||
int gw_error_backend_event(DCB *dcb);
|
||||
static int mysql_backend_connect(DCB *dcb, SERVER *server, SESSION *session);
|
||||
|
||||
static GWPROTOCOL MyObject = {
|
||||
gw_read_backend_event, /* Read - EPOLLIN handler */
|
||||
@ -263,3 +265,37 @@ int gw_error_backend_event(DCB *dcb) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a database server
|
||||
*
|
||||
* @param dcb The DCB for the new connection
|
||||
* @param server The server we are connecting to
|
||||
* @param session The client session
|
||||
* @return The file descriptor we conencted with
|
||||
*/
|
||||
static int
|
||||
mysql_backend_connect(DCB *dcb, SERVER *server, SESSION *session)
|
||||
{
|
||||
MySQLProtocol *ptr_proto = NULL;
|
||||
MySQLProtocol *client_protocol = NULL;
|
||||
MYSQL_session *s_data = NULL;
|
||||
|
||||
dcb->protocol = (MySQLProtocol *)gw_mysql_init(NULL);
|
||||
|
||||
ptr_proto = (MySQLProtocol *)dcb->protocol;
|
||||
|
||||
s_data = (MYSQL_session *)session->data;
|
||||
|
||||
// this is blocking until auth done
|
||||
if (gw_mysql_connect(server->name, server->port, s_data->db, s_data->user, s_data->client_sha1, dcb->protocol) == 0) {
|
||||
fprintf(stderr, "Connected to backend mysql server\n");
|
||||
dcb->fd = ptr_proto->fd;
|
||||
setnonblocking(dcb->fd);
|
||||
} else {
|
||||
fprintf(stderr, "<<<< NOT Connected to backend mysql server!!!\n");
|
||||
dcb->fd = -1;
|
||||
}
|
||||
|
||||
return dcb->fd;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user