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