Code Review
/
src
/
app-framework-binder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
explicit use of json-c
[src/app-framework-binder.git]
/
src
/
afb-hsrv.c
diff --git
a/src/afb-hsrv.c
b/src/afb-hsrv.c
index
a833825
..
d235648
100644
(file)
--- a/
src/afb-hsrv.c
+++ b/
src/afb-hsrv.c
@@
-17,21
+17,27
@@
#define _GNU_SOURCE
#define _GNU_SOURCE
+#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <poll.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <poll.h>
#include <fcntl.h>
+#include <errno.h>
#include <sys/stat.h>
#include <microhttpd.h>
#include <sys/stat.h>
#include <microhttpd.h>
+#include <systemd/sd-event.h>
#include "afb-method.h"
#include "afb-method.h"
+#include "afb-context.h"
#include "afb-hreq.h"
#include "afb-hsrv.h"
#include "afb-req-itf.h"
#include "verbose.h"
#include "afb-hreq.h"
#include "afb-hsrv.h"
#include "afb-req-itf.h"
#include "verbose.h"
-#include "utils-upoll.h"
+
+#include "afb-common.h"
+
#define JSON_CONTENT "application/json"
#define JSON_CONTENT "application/json"
@@
-58,7
+64,7
@@
struct afb_hsrv {
unsigned refcount;
struct hsrv_handler *handlers;
struct MHD_Daemon *httpd;
unsigned refcount;
struct hsrv_handler *handlers;
struct MHD_Daemon *httpd;
- s
truct upoll *upoll
;
+ s
d_event_source *evsrc
;
int in_run;
char *cache_to;
};
int in_run;
char *cache_to;
};
@@
-125,6
+131,7
@@
static int access_handler(
}
/* init the request */
}
/* init the request */
+ hreq->refcount = 1;
hreq->hsrv = hsrv;
hreq->cacheTimeout = hsrv->cache_to;
hreq->reqid = ++global_reqids;
hreq->hsrv = hsrv;
hreq->cacheTimeout = hsrv->cache_to;
hreq->reqid = ++global_reqids;
@@
-223,7
+230,7
@@
static void end_handler(void *cls, struct MHD_Connection *connection, void **rec
hreq = *recordreq;
if (hreq->upgrade)
MHD_suspend_connection (connection);
hreq = *recordreq;
if (hreq->upgrade)
MHD_suspend_connection (connection);
- afb_hreq_
free
(hreq);
+ afb_hreq_
unref
(hreq);
}
void run_micro_httpd(struct afb_hsrv *hsrv)
}
void run_micro_httpd(struct afb_hsrv *hsrv)
@@
-231,15
+238,21
@@
void run_micro_httpd(struct afb_hsrv *hsrv)
if (hsrv->in_run != 0)
hsrv->in_run = 2;
else {
if (hsrv->in_run != 0)
hsrv->in_run = 2;
else {
-
upoll_on_readable(hsrv->upoll, NULL
);
+
sd_event_source_set_io_events(hsrv->evsrc, 0
);
do {
hsrv->in_run = 1;
MHD_run(hsrv->httpd);
} while(hsrv->in_run == 2);
hsrv->in_run = 0;
do {
hsrv->in_run = 1;
MHD_run(hsrv->httpd);
} while(hsrv->in_run == 2);
hsrv->in_run = 0;
-
upoll_on_readable(hsrv->upoll, (void*)run_micro_httpd
);
+
sd_event_source_set_io_events(hsrv->evsrc, EPOLLIN
);
}
}
-};
+}
+
+static int io_event_callback(sd_event_source *src, int fd, uint32_t revents, void *hsrv)
+{
+ run_micro_httpd(hsrv);
+ return 0;
+}
static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
static int new_client_handler(void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
@@
-360,7
+373,8
@@
int afb_hsrv_set_cache_timeout(struct afb_hsrv *hsrv, int duration)
int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection_timeout)
{
int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection_timeout)
{
- struct upoll *upoll;
+ sd_event_source *evsrc;
+ int rc;
struct MHD_Daemon *httpd;
const union MHD_DaemonInfo *info;
struct MHD_Daemon *httpd;
const union MHD_DaemonInfo *info;
@@
-374,35
+388,36
@@
int afb_hsrv_start(struct afb_hsrv *hsrv, uint16_t port, unsigned int connection
MHD_OPTION_END); /* options-end */
if (httpd == NULL) {
MHD_OPTION_END); /* options-end */
if (httpd == NULL) {
-
fprintf(stderr, "Error:
httpStart invalid httpd port: %d", (int)port);
+
ERROR("
httpStart invalid httpd port: %d", (int)port);
return 0;
}
info = MHD_get_daemon_info(httpd, MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY);
if (info == NULL) {
MHD_stop_daemon(httpd);
return 0;
}
info = MHD_get_daemon_info(httpd, MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY);
if (info == NULL) {
MHD_stop_daemon(httpd);
-
fprintf(stderr, "Error:
httpStart no pollfd");
+
ERROR("
httpStart no pollfd");
return 0;
}
return 0;
}
-
upoll = upoll_open(info->listen_fd
, hsrv);
- if (
upoll == NULL
) {
+
rc = sd_event_add_io(afb_common_get_event_loop(), &evsrc, info->listen_fd, EPOLLIN, io_event_callback
, hsrv);
+ if (
rc < 0
) {
MHD_stop_daemon(httpd);
MHD_stop_daemon(httpd);
- fprintf(stderr, "Error: connection to upoll of httpd failed");
+ errno = -rc;
+ ERROR("connection to events for httpd failed");
return 0;
}
return 0;
}
- upoll_on_readable(upoll, (void*)run_micro_httpd);
hsrv->httpd = httpd;
hsrv->httpd = httpd;
- hsrv->
upoll = upoll
;
+ hsrv->
evsrc = evsrc
;
return 1;
}
void afb_hsrv_stop(struct afb_hsrv *hsrv)
{
return 1;
}
void afb_hsrv_stop(struct afb_hsrv *hsrv)
{
- if (hsrv->upoll)
- upoll_close(hsrv->upoll);
- hsrv->upoll = NULL;
+ if (hsrv->evsrc != NULL) {
+ sd_event_source_unref(hsrv->evsrc);
+ hsrv->evsrc = NULL;
+ }
if (hsrv->httpd != NULL)
MHD_stop_daemon(hsrv->httpd);
hsrv->httpd = NULL;
if (hsrv->httpd != NULL)
MHD_stop_daemon(hsrv->httpd);
hsrv->httpd = NULL;