Browse Source

Begin basic main function parsing parameters, create a directory for sockets and create a listener thread

master
Con Kolivas 11 years ago
parent
commit
41bc9865c9
  1. 67
      src/ckpool.c
  2. 7
      src/ckpool.h
  3. 7
      src/libckpool.h

67
src/ckpool.c

@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 Con Kolivas
* Copyright 2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
@ -7,14 +7,77 @@
* any later version. See COPYING for more details.
*/
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "ckpool.h"
#include "libckpool.h"
#include "bitcoin.h"
int main(void)
static char *socket_dir = "/tmp/ckpool/";
static void create_pthread(pthread_t *thread, void *(*start_routine)(void *), void *arg)
{
int ret = pthread_create(thread, NULL, start_routine, arg);
if (unlikely(ret))
quit(1, "Failed to pthread_create");
}
static void join_pthread(pthread_t thread)
{
int ret = pthread_join(thread, NULL);
if (unlikely(ret))
quit(1, "Failed to pthread_join");
}
static void *listener(void *arg)
{
unixsock_t *us = (unixsock_t *)arg;
close_unix_socket(us->sockd, us->path);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t pth_listener;
unixsock_t uslistener;
ckpool_t ckp;
int c, ret;
memset(&ckp, 0, sizeof(ckp));
while ((c = getopt(argc, argv, "c:n:")) != -1) {
switch (c) {
case 'c':
ckp.config = optarg;
break;
case 'n':
ckp.name = optarg;
break;
case 's':
socket_dir = optarg;
break;
}
}
ret = mkdir(socket_dir, 0700);
if (ret && errno != EEXIST)
quit(1, "Failed to make directory %s", socket_dir);
uslistener.path = strdup(socket_dir);
realloc_strcat(&uslistener.path, "listener");
LOGDEBUG("Opening %s", uslistener.path);
uslistener.sockd = open_unix_server(uslistener.path);
if (unlikely(uslistener.sockd < 0))
quit(1, "Failed to open listener socket");
create_pthread(&pth_listener, listener, &uslistener);
join_pthread(pth_listener);
return 0;
}

7
src/ckpool.h

@ -122,4 +122,11 @@ static inline void flip_80(void *dest_p, const void *src_p)
for (i = 0; i < 20; i++)
dest[i] = bswap_32(src[i]);
}
struct ckpool_instance {
char *config;
char *name;
};
typedef struct ckpool_instance ckpool_t;
#endif /* CKPOOL_H */

7
src/libckpool.h

@ -115,6 +115,13 @@ struct connsock {
typedef struct connsock connsock_t;
struct unixsock {
int sockd;
char *path;
};
typedef struct unixsock unixsock_t;
void _mutex_lock(pthread_mutex_t *lock, const char *file, const char *func, const int line);
void _mutex_unlock_noyield(pthread_mutex_t *lock, const char *file, const char *func, const int line);
void _mutex_unlock(pthread_mutex_t *lock, const char *file, const char *func, const int line);

Loading…
Cancel
Save