New header file "fdqueue.h"

So that "http_server.h" does not have to include "serval.h" which
creates a circular dependency.

Remove the __SERVALDNA__HTTP_SERVER_IMPLEMENTATION hack from
"http_server.h"
This commit is contained in:
Andrew Bettison 2013-10-18 10:34:43 +10:30
parent 48921802f5
commit 291a631095
13 changed files with 114 additions and 82 deletions

View File

@ -1,9 +1,11 @@
#include "constants.h"
#include "mdp_client.h"
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include "constants.h"
#include "mdp_client.h"
#include "str.h"
struct item{

View File

@ -4,7 +4,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include <errno.h>
#include <time.h>
#include <sys/time.h>

View File

@ -17,8 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <poll.h>
#include "serval.h"
#include "fdqueue.h"
#include "conf.h"
#include "str.h"
#include "strbuf.h"

92
fdqueue.h Normal file
View File

@ -0,0 +1,92 @@
/*
Serval DNA file descriptor queue
Copyright (C) 2012-2013 Serval Project, Inc.
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 Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __SERVALDNA__FDQUEUE_H
#define __SERVALDNA__FDQUEUE_H
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include "os.h"
#include "log.h"
struct profile_total {
struct profile_total *_next;
int _initialised;
const char *name;
time_ms_t max_time;
time_ms_t total_time;
time_ms_t child_time;
int calls;
};
struct call_stats{
time_ms_t enter_time;
time_ms_t child_time;
struct profile_total *totals;
struct call_stats *prev;
};
struct sched_ent;
typedef void (*ALARM_FUNCP) (struct sched_ent *alarm);
struct sched_ent{
struct sched_ent *_next;
struct sched_ent *_prev;
ALARM_FUNCP function;
void *context;
struct pollfd poll;
// when we should first consider the alarm
time_ms_t alarm;
// the order we will prioritise the alarm
time_ms_t deadline;
struct profile_total *stats;
int _poll_index;
};
int is_scheduled(const struct sched_ent *alarm);
int _schedule(struct __sourceloc, struct sched_ent *alarm);
int _unschedule(struct __sourceloc, struct sched_ent *alarm);
int _watch(struct __sourceloc, struct sched_ent *alarm);
int _unwatch(struct __sourceloc, struct sched_ent *alarm);
#define schedule(alarm) _schedule(__WHENCE__, alarm)
#define unschedule(alarm) _unschedule(__WHENCE__, alarm)
#define watch(alarm) _watch(__WHENCE__, alarm)
#define unwatch(alarm) _unwatch(__WHENCE__, alarm)
int fd_poll();
/* function timing routines */
int fd_clearstats();
int fd_showstats();
int fd_checkalarms();
int fd_func_enter(struct __sourceloc, struct call_stats *this_call);
int fd_func_exit(struct __sourceloc, struct call_stats *this_call);
void dump_stack(int log_level);
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \
struct call_stats _this_call={.totals=&_aggregate_stats}; \
fd_func_enter(__HERE__, &_this_call);
#define OUT() fd_func_exit(__HERE__, &_this_call)
#define RETURN(X) do { OUT(); return (X); } while (0);
#define RETURNNULL do { OUT(); return (NULL); } while (0);
#endif // __SERVALDNA__FDQUEUE_H

View File

@ -18,6 +18,7 @@ HDRS= fifo.h \
crypto.h \
log.h \
net.h \
fdqueue.h \
http_server.h \
xprintf.h \
constants.h \

View File

@ -17,7 +17,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#define __SERVALDNA__HTTP_SERVER_IMPLEMENTATION
#include <assert.h>
#include <inttypes.h>
#include <time.h>

View File

@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <limits.h>
#include "constants.h"
#include "strbuf.h"
#include "fdqueue.h"
/* Generic HTTP request handling.
*
@ -111,8 +112,6 @@ void http_request_response(struct http_request *r, int result, const char *mime_
void http_request_simple_response(struct http_request *r, uint16_t result, const char *body);
void http_request_response_header(struct http_request *r, int result, const char *mime_type, uint64_t bytes);
#ifdef __SERVALDNA__HTTP_SERVER_IMPLEMENTATION
struct http_request {
struct sched_ent alarm; // MUST BE FIRST ELEMENT
enum http_request_phase { RECEIVE, TRANSMIT, DONE } phase;
@ -151,6 +150,4 @@ struct http_request {
char buffer[8 * 1024];
};
#endif // __SERVALDNA__HTTP_SERVER_IMPLEMENTATION
#endif // __SERVALDNA__HTTP_SERVER_H

View File

@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include <fcntl.h>
#include "serval.h"

View File

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "serval.h"
#include "fdqueue.h"
#include "conf.h"
struct profile_total *stats_head=NULL;

View File

@ -25,7 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
#include <assert.h>
#define __SERVALDNA__HTTP_SERVER_IMPLEMENTATION
#include "serval.h"
#include "overlay_address.h"
#include "conf.h"

View File

@ -1,7 +1,7 @@
/*
Serval Daemon
Serval DNA header file
Copyright (C) 2010-2012 Paul Gardner-Stephen
Copyright (C) 2012 Serval Project Inc.
Copyright (C) 2012-2013 Serval Project, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -90,9 +90,6 @@ struct in_addr {
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
@ -109,6 +106,7 @@ struct in_addr {
#include <ctype.h>
#include <sys/stat.h>
#include "fdqueue.h"
#include "cli.h"
#include "constants.h"
#include "mem.h"
@ -341,42 +339,6 @@ int keyring_dump(keyring_file *k, XPRINTF xpf, int include_secret);
extern int sock;
struct profile_total {
struct profile_total *_next;
int _initialised;
const char *name;
time_ms_t max_time;
time_ms_t total_time;
time_ms_t child_time;
int calls;
};
struct call_stats{
time_ms_t enter_time;
time_ms_t child_time;
struct profile_total *totals;
struct call_stats *prev;
};
struct sched_ent;
typedef void (*ALARM_FUNCP) (struct sched_ent *alarm);
struct sched_ent{
struct sched_ent *_next;
struct sched_ent *_prev;
ALARM_FUNCP function;
void *context;
struct pollfd poll;
// when we should first consider the alarm
time_ms_t alarm;
// the order we will prioritise the alarm
time_ms_t deadline;
struct profile_total *stats;
int _poll_index;
};
struct limit_state{
// length of time for a burst
time_ms_t burst_length;
@ -817,17 +779,6 @@ void sigIoHandler(int signal);
int overlay_mdp_setup_sockets();
int is_scheduled(const struct sched_ent *alarm);
int _schedule(struct __sourceloc, struct sched_ent *alarm);
int _unschedule(struct __sourceloc, struct sched_ent *alarm);
int _watch(struct __sourceloc, struct sched_ent *alarm);
int _unwatch(struct __sourceloc, struct sched_ent *alarm);
#define schedule(alarm) _schedule(__WHENCE__, alarm)
#define unschedule(alarm) _unschedule(__WHENCE__, alarm)
#define watch(alarm) _watch(__WHENCE__, alarm)
#define unwatch(alarm) _unwatch(__WHENCE__, alarm)
int fd_poll();
void overlay_interface_discover(struct sched_ent *alarm);
void overlay_packetradio_poll(struct sched_ent *alarm);
int overlay_packetradio_setup_port(overlay_interface *interface);
@ -857,22 +808,6 @@ time_ms_t limit_next_allowed(struct limit_state *state);
int limit_is_allowed(struct limit_state *state);
int limit_init(struct limit_state *state, int rate_micro_seconds);
/* function timing routines */
int fd_clearstats();
int fd_showstats();
int fd_checkalarms();
int fd_func_enter(struct __sourceloc, struct call_stats *this_call);
int fd_func_exit(struct __sourceloc, struct call_stats *this_call);
void dump_stack(int log_level);
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \
struct call_stats _this_call={.totals=&_aggregate_stats}; \
fd_func_enter(__HERE__, &_this_call);
#define OUT() fd_func_exit(__HERE__, &_this_call)
#define RETURN(X) do { OUT(); return (X); } while (0);
#define RETURNNULL do { OUT(); return (NULL); } while (0);
int olsr_init_socket(void);
int olsr_send(struct overlay_frame *frame);

View File

@ -17,8 +17,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "strbuf_helpers.h"
#include <poll.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
@ -26,6 +24,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdarg.h>
#include <inttypes.h>
#include <sys/wait.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@ -34,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
#include <sys/uio.h>
#include "http_server.h"
#include "strbuf_helpers.h"
static inline strbuf _toprint(strbuf sb, char c)
{

View File

@ -21,8 +21,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <poll.h>
#include <fcntl.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
#include "serval.h"
#include "conf.h"