Addition of connect function to dcb functions and added dcb_connect routine

This commit is contained in:
Mark Riddoch
2013-06-14 17:55:31 +02:00
parent ebbe4bf035
commit 34372fbc5d
3 changed files with 47 additions and 1 deletions

View File

@ -30,6 +30,8 @@
#include <string.h>
#include <dcb.h>
#include <spinlock.h>
#include <server.h>
#include <session.h>
static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */
static SPINLOCK *dcbspin = NULL;
@ -104,6 +106,45 @@ free_dcb(DCB *dcb)
free(dcb);
}
/*
* Connect to a server
*
* @param server The server to connect to
* @param session The session this connection is being made for
* @param protcol The protocol module to use
*/
DCB *
connect_dcb(SERVER *server, SESSION *session, const char *protocol)
{
DCB *dcb;
GWPROTOCOL *funcs;
int epollfd = -1; // Need to work out how to get this
if ((dcb = alloc_dcb()) == NULL)
{
return NULL;
}
if ((funcs = load_module(protocol, "Protocol")) == NULL)
{
free(dcb);
return NULL;
}
memcpy(&(dcb->func), funcs, sizeof(GWPROTOCOL));
dcb->session = session;
if ((dcb->fd = dcb->func.connect(server, session, epollfd)) == -1)
{
free(dcb);
return NULL;
}
/*
* We are now connected, the authentication etc will happen as
* part of the EPOLLOUT event that will be received once the connection
* is established.
*/
return dcb;
}
/*
* Diagnostic to print a DCB
*