Browse Source

Create a basic handler of json messages on the listener unix socket as RPC API commands with a ckmsgq

master
Con Kolivas 10 years ago
parent
commit
f6d87f1569
  1. 2
      src/Makefile.am
  2. 16
      src/ckpool.c
  3. 3
      src/ckpool.h

2
src/Makefile.am

@ -10,7 +10,7 @@ libckpool_la_LIBADD = @PTHREAD_LIBS@ @MATH_LIBS@ @RT_LIBS@
bin_PROGRAMS = ckpool ckpmsg notifier bin_PROGRAMS = ckpool ckpmsg notifier
ckpool_SOURCES = ckpool.c ckpool.h generator.c generator.h bitcoin.c bitcoin.h \ ckpool_SOURCES = ckpool.c ckpool.h generator.c generator.h bitcoin.c bitcoin.h \
stratifier.c stratifier.h connector.c connector.h uthash.h \ stratifier.c stratifier.h connector.c connector.h uthash.h \
utlist.h utlist.h api.c api.h
ckpool_LDADD = libckpool.la @JANSSON_LIBS@ ckpool_LDADD = libckpool.la @JANSSON_LIBS@
ckpmsg_SOURCES = ckpmsg.c ckpmsg_SOURCES = ckpmsg.c

16
src/ckpool.c

@ -31,6 +31,7 @@
#include "generator.h" #include "generator.h"
#include "stratifier.h" #include "stratifier.h"
#include "connector.h" #include "connector.h"
#include "api.h"
ckpool_t *global_ckp; ckpool_t *global_ckp;
@ -294,6 +295,17 @@ out:
return ret; return ret;
} }
static void api_message(ckpool_t *ckp, char **buf, int *sockd)
{
apimsg_t *apimsg = ckalloc(sizeof(apimsg_t));
apimsg->buf = *buf;
*buf = NULL;
apimsg->sockd = *sockd;
*sockd = -1;
ckmsgq_add(ckp->ckpapi, apimsg);
}
/* Listen for incoming global requests. Always returns a response if possible */ /* Listen for incoming global requests. Always returns a response if possible */
static void *listener(void *arg) static void *listener(void *arg)
{ {
@ -316,6 +328,9 @@ retry:
if (!buf) { if (!buf) {
LOGWARNING("Failed to get message in listener"); LOGWARNING("Failed to get message in listener");
send_unix_msg(sockd, "failed"); send_unix_msg(sockd, "failed");
} else if (buf[0] == '{') {
/* Any JSON messages received are for the RPC API to handle */
api_message(ckp, &buf, &sockd);
} else if (cmdmatch(buf, "shutdown")) { } else if (cmdmatch(buf, "shutdown")) {
LOGWARNING("Listener received shutdown message, terminating ckpool"); LOGWARNING("Listener received shutdown message, terminating ckpool");
send_unix_msg(sockd, "exiting"); send_unix_msg(sockd, "exiting");
@ -1684,6 +1699,7 @@ int main(int argc, char **argv)
launch_logger(&ckp.main); launch_logger(&ckp.main);
ckp.logfd = fileno(ckp.logfp); ckp.logfd = fileno(ckp.logfp);
ckp.ckpapi = create_ckmsgq(&ckp, "api", &ckpool_api);
create_pthread(&ckp.pth_listener, listener, &ckp.main); create_pthread(&ckp.pth_listener, listener, &ckp.main);
/* Launch separate processes from here */ /* Launch separate processes from here */

3
src/ckpool.h

@ -135,6 +135,9 @@ struct ckpool_instance {
/* How many clients maximum to accept before rejecting further */ /* How many clients maximum to accept before rejecting further */
int maxclients; int maxclients;
/* API message queue */
ckmsgq_t *ckpapi;
/* Logger message queue NOTE: Unique per process */ /* Logger message queue NOTE: Unique per process */
ckmsgq_t *logger; ckmsgq_t *logger;
/* Process instance data of parent/child processes */ /* Process instance data of parent/child processes */

Loading…
Cancel
Save