Reformat mascaled.c
This commit is contained in:
@ -38,7 +38,8 @@
|
|||||||
#include <modinfo.h>
|
#include <modinfo.h>
|
||||||
#include <maxscaled.h>
|
#include <maxscaled.h>
|
||||||
|
|
||||||
MODULE_INFO info = {
|
MODULE_INFO info =
|
||||||
|
{
|
||||||
MODULE_API_PROTOCOL,
|
MODULE_API_PROTOCOL,
|
||||||
MODULE_GA,
|
MODULE_GA,
|
||||||
GWPROTOCOL_VERSION,
|
GWPROTOCOL_VERSION,
|
||||||
@ -72,7 +73,8 @@ static int maxscaled_listen(DCB *dcb, char *config);
|
|||||||
/**
|
/**
|
||||||
* The "module object" for the maxscaled protocol module.
|
* The "module object" for the maxscaled protocol module.
|
||||||
*/
|
*/
|
||||||
static GWPROTOCOL MyObject = {
|
static GWPROTOCOL MyObject =
|
||||||
|
{
|
||||||
maxscaled_read_event, /**< Read - EPOLLIN handler */
|
maxscaled_read_event, /**< Read - EPOLLIN handler */
|
||||||
maxscaled_write, /**< Write - data from gateway */
|
maxscaled_write, /**< Write - data from gateway */
|
||||||
maxscaled_write_event, /**< WriteReady - EPOLLOUT handler */
|
maxscaled_write_event, /**< WriteReady - EPOLLOUT handler */
|
||||||
@ -84,15 +86,14 @@ static GWPROTOCOL MyObject = {
|
|||||||
maxscaled_listen, /**< Create a listener */
|
maxscaled_listen, /**< Create a listener */
|
||||||
NULL, /**< Authentication */
|
NULL, /**< Authentication */
|
||||||
NULL /**< Session */
|
NULL /**< Session */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the mandatory version entry point
|
* Implementation of the mandatory version entry point
|
||||||
*
|
*
|
||||||
* @return version string of the module
|
* @return version string of the module
|
||||||
*/
|
*/
|
||||||
char *
|
char* version()
|
||||||
version()
|
|
||||||
{
|
{
|
||||||
return version_str;
|
return version_str;
|
||||||
}
|
}
|
||||||
@ -101,8 +102,7 @@ version()
|
|||||||
* The module initialisation routine, called when the module
|
* The module initialisation routine, called when the module
|
||||||
* is first loaded.
|
* is first loaded.
|
||||||
*/
|
*/
|
||||||
void
|
void ModuleInit()
|
||||||
ModuleInit()
|
|
||||||
{
|
{
|
||||||
MXS_INFO("Initialise MaxScaled Protocol module.");;
|
MXS_INFO("Initialise MaxScaled Protocol module.");;
|
||||||
}
|
}
|
||||||
@ -115,8 +115,7 @@ ModuleInit()
|
|||||||
*
|
*
|
||||||
* @return The module object
|
* @return The module object
|
||||||
*/
|
*/
|
||||||
GWPROTOCOL *
|
GWPROTOCOL* GetModuleObject()
|
||||||
GetModuleObject()
|
|
||||||
{
|
{
|
||||||
return &MyObject;
|
return &MyObject;
|
||||||
}
|
}
|
||||||
@ -127,18 +126,16 @@ GetModuleObject()
|
|||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_read_event(DCB* dcb)
|
||||||
maxscaled_read_event(DCB* dcb)
|
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
GWBUF *head = NULL;
|
GWBUF *head = NULL;
|
||||||
SESSION *session = dcb->session;
|
SESSION *session = dcb->session;
|
||||||
MAXSCALED *maxscaled = (MAXSCALED *)dcb->protocol;
|
MAXSCALED *maxscaled = (MAXSCALED *)dcb->protocol;
|
||||||
char *password;
|
char *password;
|
||||||
|
|
||||||
if ((n = dcb_read(dcb, &head, 0)) != -1)
|
if ((n = dcb_read(dcb, &head, 0)) != -1)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (head)
|
if (head)
|
||||||
{
|
{
|
||||||
if (GWBUF_LENGTH(head))
|
if (GWBUF_LENGTH(head))
|
||||||
@ -163,7 +160,10 @@ char *password;
|
|||||||
dcb_printf(dcb, "FAILED");
|
dcb_printf(dcb, "FAILED");
|
||||||
maxscaled->state = MAXSCALED_STATE_LOGIN;
|
maxscaled->state = MAXSCALED_STATE_LOGIN;
|
||||||
}
|
}
|
||||||
while ((head = gwbuf_consume(head, GWBUF_LENGTH(head))) != NULL);
|
while ((head = gwbuf_consume(head, GWBUF_LENGTH(head))) != NULL)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
free(password);
|
free(password);
|
||||||
break;
|
break;
|
||||||
case MAXSCALED_STATE_DATA:
|
case MAXSCALED_STATE_DATA:
|
||||||
@ -175,7 +175,10 @@ char *password;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Force the free of the buffer header
|
// Force the free of the buffer header
|
||||||
while ((head = gwbuf_consume(head, GWBUF_LENGTH(head))) != NULL);
|
while ((head = gwbuf_consume(head, GWBUF_LENGTH(head))) != NULL)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,8 +191,7 @@ char *password;
|
|||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_write_event(DCB *dcb)
|
||||||
maxscaled_write_event(DCB *dcb)
|
|
||||||
{
|
{
|
||||||
return dcb_drain_writeq(dcb);
|
return dcb_drain_writeq(dcb);
|
||||||
}
|
}
|
||||||
@ -203,8 +205,7 @@ maxscaled_write_event(DCB *dcb)
|
|||||||
* @param dcb Descriptor Control Block for the socket
|
* @param dcb Descriptor Control Block for the socket
|
||||||
* @param queue Linked list of buffes to write
|
* @param queue Linked list of buffes to write
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_write(DCB *dcb, GWBUF *queue)
|
||||||
maxscaled_write(DCB *dcb, GWBUF *queue)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
rc = dcb_write(dcb, queue);
|
rc = dcb_write(dcb, queue);
|
||||||
@ -216,8 +217,7 @@ maxscaled_write(DCB *dcb, GWBUF *queue)
|
|||||||
*
|
*
|
||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_error(DCB *dcb)
|
||||||
maxscaled_error(DCB *dcb)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -227,8 +227,7 @@ maxscaled_error(DCB *dcb)
|
|||||||
*
|
*
|
||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_hangup(DCB *dcb)
|
||||||
maxscaled_hangup(DCB *dcb)
|
|
||||||
{
|
{
|
||||||
dcb_close(dcb);
|
dcb_close(dcb);
|
||||||
return 0;
|
return 0;
|
||||||
@ -241,10 +240,9 @@ maxscaled_hangup(DCB *dcb)
|
|||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
* @return The number of new connections created
|
* @return The number of new connections created
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_accept(DCB *dcb)
|
||||||
maxscaled_accept(DCB *dcb)
|
|
||||||
{
|
{
|
||||||
int n_connect = 0;
|
int n_connect = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
@ -257,7 +255,9 @@ int n_connect = 0;
|
|||||||
so = accept(dcb->fd, (struct sockaddr *)&addr, &addrlen);
|
so = accept(dcb->fd, (struct sockaddr *)&addr, &addrlen);
|
||||||
|
|
||||||
if (so == -1)
|
if (so == -1)
|
||||||
|
{
|
||||||
return n_connect;
|
return n_connect;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
atomic_add(&dcb->stats.n_accepts, 1);
|
atomic_add(&dcb->stats.n_accepts, 1);
|
||||||
@ -281,8 +281,7 @@ int n_connect = 0;
|
|||||||
spinlock_init(&maxscaled_pr->lock);
|
spinlock_init(&maxscaled_pr->lock);
|
||||||
client_dcb->protocol = (void *)maxscaled_pr;
|
client_dcb->protocol = (void *)maxscaled_pr;
|
||||||
|
|
||||||
client_dcb->session =
|
client_dcb->session = session_alloc(dcb->session->service, client_dcb);
|
||||||
session_alloc(dcb->session->service, client_dcb);
|
|
||||||
|
|
||||||
if (NULL == client_dcb->session || poll_add_dcb(client_dcb))
|
if (NULL == client_dcb->session || poll_add_dcb(client_dcb))
|
||||||
{
|
{
|
||||||
@ -304,13 +303,14 @@ int n_connect = 0;
|
|||||||
* @param dcb The descriptor control block
|
* @param dcb The descriptor control block
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int maxscaled_close(DCB *dcb)
|
||||||
maxscaled_close(DCB *dcb)
|
|
||||||
{
|
{
|
||||||
MAXSCALED *maxscaled = dcb->protocol;
|
MAXSCALED *maxscaled = dcb->protocol;
|
||||||
|
|
||||||
if (!maxscaled)
|
if (!maxscaled)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
spinlock_acquire(&maxscaled->lock);
|
spinlock_acquire(&maxscaled->lock);
|
||||||
if (maxscaled->username)
|
if (maxscaled->username)
|
||||||
@ -329,18 +329,18 @@ MAXSCALED *maxscaled = dcb->protocol;
|
|||||||
* @param listener The Listener DCB
|
* @param listener The Listener DCB
|
||||||
* @param config Configuration (ip:port)
|
* @param config Configuration (ip:port)
|
||||||
*/
|
*/
|
||||||
static int
|
static int maxscaled_listen(DCB *listener, char *config)
|
||||||
maxscaled_listen(DCB *listener, char *config)
|
|
||||||
{
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
int one = 1;
|
int one = 1;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
|
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
|
||||||
|
|
||||||
if (!parse_bindconfig(config, 6033, &addr))
|
if (!parse_bindconfig(config, 6033, &addr))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((listener->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
if ((listener->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||||
{
|
{
|
||||||
@ -362,9 +362,12 @@ int rc;
|
|||||||
|
|
||||||
rc = listen(listener->fd, SOMAXCONN);
|
rc = listen(listener->fd, SOMAXCONN);
|
||||||
|
|
||||||
if (rc == 0) {
|
if (rc == 0)
|
||||||
|
{
|
||||||
MXS_NOTICE("Listening maxscale connections at %s", config);
|
MXS_NOTICE("Listening maxscale connections at %s", config);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int eno = errno;
|
int eno = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
char errbuf[STRERROR_BUFLEN];
|
char errbuf[STRERROR_BUFLEN];
|
||||||
@ -374,7 +377,6 @@ int rc;
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (poll_add_dcb(listener) == -1)
|
if (poll_add_dcb(listener) == -1)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user