Skip to content

Commit 0e221b8

Browse files
committed
integrated a multipart_parser into libeeb
1 parent f8d2ac5 commit 0e221b8

File tree

10 files changed

+930
-307
lines changed

10 files changed

+930
-307
lines changed

serve/async.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdlib.h>
2+
#include <assert.h>
23
#include <ev.h>
34
#include <dispatch/dispatch.h>
45

@@ -14,8 +15,9 @@ static int queue_length = 10;
1415
static main_async_t* async_queue;
1516
static ev_async main_async;
1617

17-
void dispatch_main_async_f(void* context, void (*cb)(void*))
18+
void main_async_f(void* context, void (*cb)(void*))
1819
{
20+
assert(cb);
1921
dispatch_semaphore_wait(async_queue_semaphore, DISPATCH_TIME_FOREVER);
2022
++queue_pending;
2123
if (queue_pending > queue_length)
@@ -30,14 +32,20 @@ void dispatch_main_async_f(void* context, void (*cb)(void*))
3032
ev_async_send(EV_DEFAULT_ &main_async);
3133
}
3234

33-
static void main_async_dispatch(EV_P_ ev_async* w, int revents)
35+
static void main_async_drain(EV_P_ ev_async* w, int revents)
3436
{
3537
dispatch_semaphore_wait(async_queue_semaphore, DISPATCH_TIME_FOREVER);
3638
while (queue_pending > 0)
3739
{
40+
main_async_t async;
3841
queue_position = (queue_position + queue_length - 1) % queue_length;
3942
--queue_pending;
40-
async_queue[queue_position].cb(async_queue[queue_position].context);
43+
async = async_queue[queue_position];
44+
dispatch_semaphore_signal(async_queue_semaphore);
45+
// call the async block outside the lock
46+
async.cb(async.context);
47+
// continue the lock so we can get correct queue_pending
48+
dispatch_semaphore_wait(async_queue_semaphore, DISPATCH_TIME_FOREVER);
4149
}
4250
dispatch_semaphore_signal(async_queue_semaphore);
4351
}
@@ -46,7 +54,7 @@ void main_async_init(void)
4654
{
4755
async_queue_semaphore = dispatch_semaphore_create(1);
4856
async_queue = (main_async_t*)malloc(sizeof(main_async_t) * queue_length);
49-
ev_async_init(&main_async, main_async_dispatch);
57+
ev_async_init(&main_async, main_async_drain);
5058
}
5159

5260
void main_async_start(EV_P)

serve/async.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _GUARD_async_h_
22
#define _GUARD_async_h_
33

4-
void dispatch_main_async_f(void* context, void (*cb)(void*));
4+
void main_async_f(void* context, void (*cb)(void*));
55
void main_async_init(void);
66
void main_async_start(EV_P);
77
void main_async_destroy(void);

serve/bbf.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#include "uri.h"
22

3-
#define MSG ("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\n\r\nhello world\n")
3+
void* uri_bbf_detect_objects_parse(void* parsed, const char* key, const char* value)
4+
{
5+
return 0;
6+
}
7+
8+
ebb_buf uri_bbf_detect_objects_intro(const void* query)
9+
{
10+
ebb_buf buf;
11+
const static char bbf_intro[] =
12+
"HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\nAccept: \r\nContent-Type: text/html\r\nContent-Length: 156\r\n\r\n"
13+
"<html><body><form enctype='multipart/form-data' method='post'><input type='file' name='a'><input type='file' name='b'><input type='submit'></form>\n";
14+
buf.data = (void*)bbf_intro;
15+
buf.len = sizeof(bbf_intro);
16+
return buf;
17+
}
418

5-
ebb_buf ebb_bbf_detect_objects(const void* query)
19+
ebb_buf uri_bbf_detect_objects(const void* query)
620
{
721
ebb_buf buf;
8-
buf.data = MSG;
9-
buf.len = sizeof(MSG);
22+
const static char bbf_intro[] =
23+
"HTTP/1.1 201 Created\r\nCache-Control: no-cache\r\nContent-Type: text/plain\r\nContent-Length: 3\r\n\r\n"
24+
"OK\n";
25+
buf.data = (void*)bbf_intro;
26+
buf.len = sizeof(bbf_intro);
1027
return buf;
1128
}

serve/ebb.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ on_readable(EV_P_ ev_io *watcher, int revents)
121121
recv_buffer_size = buf->len;
122122
}
123123

124-
125124
recved = recv(connection->fd, recv_buffer, recv_buffer_size, 0);
126125
if(recved < 0) goto error;
127126
if(recved == 0) return;

0 commit comments

Comments
 (0)