2 * Copyright (c) 2008 Ry Dahl. This software is released under the MIT
3 * License. See README file for details.
7 #define EV_STANDALONE 1
9 #include <sys/socket.h>
10 #include <netinet/in.h>
14 typedef struct ebb_server ebb_server
;
15 typedef struct ebb_client ebb_client
;
16 #define EBB_VERSION "0.1.0"
17 #define EBB_BUFFERSIZE (1024 * (80 + 33))
18 #define EBB_MAX_CLIENTS 1024
19 #define EBB_TIMEOUT 30.0
20 #define EBB_MAX_ENV 500
21 #define EBB_TCP_COMMON \
24 struct sockaddr_in sockaddr;
27 void ebb_client_close(ebb_client
*);
28 /* user MUST call this function on each client passed by the request_cb */
29 void ebb_client_release(ebb_client
*);
30 int ebb_client_read(ebb_client
*client
, char *buffer
, int length
);
31 void ebb_client_write_status(ebb_client
*, int status
, const char *human_status
);
32 void ebb_client_write_header(ebb_client
*, const char *field
, const char *value
);
33 void ebb_client_write_body(ebb_client
*, const char *data
, int length
);
46 unsigned int in_use
: 1;
53 size_t read
, nread_from_body
;
55 char *upload_filename
;
59 GString
*response_buffer
;
62 ev_timer timeout_watcher
;
63 unsigned int keep_alive
: 1;
64 unsigned int status_written
: 1;
65 unsigned int headers_written
: 1;
66 unsigned int body_written
: 1;
68 /* the ENV structure */
70 struct ebb_env_item env
[EBB_MAX_ENV
];
75 typedef void (*ebb_request_cb
)(ebb_client
*, void*);
77 ebb_server
* ebb_server_alloc(void);
78 void ebb_server_free(ebb_server
*);
79 void ebb_server_init( ebb_server
*server
80 , struct ev_loop
*loop
81 , ebb_request_cb request_cb
82 , void *request_cb_data
84 int ebb_server_listen_on_fd(ebb_server
*, const int sfd
);
85 int ebb_server_listen_on_port(ebb_server
*, const int port
);
86 int ebb_server_listen_on_socket(ebb_server
*, const char *socketpath
);
87 void ebb_server_unlisten(ebb_server
*);
93 ev_io request_watcher
;
94 ebb_client clients
[EBB_MAX_CLIENTS
];
96 void *request_cb_data
;
97 ebb_request_cb request_cb
;