Addition of connect function to dcb functions and added dcb_connect routine
This commit is contained in:
41
core/dcb.c
41
core/dcb.c
@ -30,6 +30,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dcb.h>
|
#include <dcb.h>
|
||||||
#include <spinlock.h>
|
#include <spinlock.h>
|
||||||
|
#include <server.h>
|
||||||
|
#include <session.h>
|
||||||
|
|
||||||
static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */
|
static DCB *allDCBs = NULL; /* Diagnotics need a list of DCBs */
|
||||||
static SPINLOCK *dcbspin = NULL;
|
static SPINLOCK *dcbspin = NULL;
|
||||||
@ -104,6 +106,45 @@ free_dcb(DCB *dcb)
|
|||||||
free(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
|
* Diagnostic to print a DCB
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <buffer.h>
|
#include <buffer.h>
|
||||||
|
|
||||||
struct session;
|
struct session;
|
||||||
|
struct server;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The function pointer table used by descriptors to call relevant functions
|
* The function pointer table used by descriptors to call relevant functions
|
||||||
@ -48,6 +49,8 @@ typedef struct gw_protocol {
|
|||||||
* error EPOLLERR handler for the socket
|
* error EPOLLERR handler for the socket
|
||||||
* hangup EPOLLHUP handler for the socket
|
* hangup EPOLLHUP handler for the socket
|
||||||
* accept Accept handler for listener socket only
|
* accept Accept handler for listener socket only
|
||||||
|
* connect Create a connection to the specified server
|
||||||
|
* for the session pased in
|
||||||
* close Gateway close entry point for the socket
|
* close Gateway close entry point for the socket
|
||||||
*/
|
*/
|
||||||
int (*read)(struct dcb *, int);
|
int (*read)(struct dcb *, int);
|
||||||
@ -56,6 +59,7 @@ typedef struct gw_protocol {
|
|||||||
int (*error)(struct dcb *, int);
|
int (*error)(struct dcb *, int);
|
||||||
int (*hangup)(struct dcb *, int);
|
int (*hangup)(struct dcb *, int);
|
||||||
int (*accept)(struct dcb *, int);
|
int (*accept)(struct dcb *, int);
|
||||||
|
int (*connect)(struct server *, struct session *, int);
|
||||||
int (*close)(struct dcb *, int);
|
int (*close)(struct dcb *, int);
|
||||||
} GWPROTOCOL;
|
} GWPROTOCOL;
|
||||||
|
|
||||||
@ -98,6 +102,7 @@ typedef struct dcb {
|
|||||||
|
|
||||||
extern DCB *alloc_dcb(); /* Allocate a DCB */
|
extern DCB *alloc_dcb(); /* Allocate a DCB */
|
||||||
extern void free_dcb(DCB *); /* Free a DCB */
|
extern void free_dcb(DCB *); /* Free a DCB */
|
||||||
|
extern DCB *connect_dcb(struct server *, struct session *, const char *);
|
||||||
extern void printAllDCBs(); /* Debug to print all DCB in the system */
|
extern void printAllDCBs(); /* Debug to print all DCB in the system */
|
||||||
extern void printDCB(DCB *); /* Debug print routine */
|
extern void printDCB(DCB *); /* Debug print routine */
|
||||||
extern const char *gw_dcb_state2string(int); /* DCB state to string */
|
extern const char *gw_dcb_state2string(int); /* DCB state to string */
|
||||||
|
Reference in New Issue
Block a user