0
#define EV_STANDALONE 1
0
@@ -91,10 +89,7 @@ static void dispatch(ebb_client *client)
0
- /* decide if to use keep-alive or not */
0
+ /* XXX decide if to use keep-alive or not? */
0
server->request_cb(client, server->request_cb_data);
0
@@ -116,86 +111,6 @@ static void on_timeout(struct ev_loop *loop, ev_timer *watcher, int revents)
0
#define client_finished_parsing http_parser_is_finished(&client->parser)
0
#define total_request_size (client->parser.content_length + client->parser.nread)
0
-static void* read_body_into_file(void *_client)
0
- ebb_client *client = (ebb_client*)_client;
0
- char *filename = "/tmp/.ebb_upload.XXXXXX";
0
- assert(client->server->open);
0
- assert(client->parser.content_length > 0);
0
- assert(client_finished_parsing);
0
- /* set blocking socket */
0
- int flags = fcntl(client->fd, F_GETFL, 0);
0
- int ret = fcntl(client->fd, F_SETFL, flags & ~O_NONBLOCK);
0
- if(0 > mkstemp(filename)) {
0
- ebb_client_close(client);
0
- client->upload_filename = strdup(filename);
0
- tmpfile = fopen(filename, "w+");
0
- perror("opening tempfile for uplaod");
0
- ebb_client_close(client);
0
- client->upload_file = tmpfile;
0
- size_t body_head_length = client->read - client->parser.nread;
0
- size_t written = 0, r;
0
- while(written < body_head_length) {
0
- r = fwrite( client->request_buffer + sizeof(char)*(client->parser.nread + written)
0
- , body_head_length - written
0
- ebb_client_close(client);
0
- while(written < client->parser.content_length) {
0
- received = recv(client->fd
0
- , min(client->parser.content_length - written, bufsize)
0
- if(received < 0) goto error;
0
- client->read += received;
0
- rv = fwrite( buffer + w*sizeof(char)
0
- if(rv <= 0) goto error;
0
- // g_debug("%d bytes written to file %s", written, client->upload_filename);
0
- ebb_client_close(client);
0
static void on_client_readable(struct ev_loop *loop, ev_io *watcher, int revents)
0
ebb_client *client = (ebb_client*)(watcher->data);
0
@@ -216,7 +131,7 @@ static void on_client_readable(struct ev_loop *loop, ev_io *watcher, int revents
0
ev_timer_again(loop, &client->timeout_watcher);
0
- if(client->read == EBB_BUFFERSIZE) goto error;
0
+ // if(client->read == EBB_BUFFERSIZE) goto error;
0
if(FALSE == client_finished_parsing) {
0
http_parser_execute( &client->parser
0
@@ -228,21 +143,14 @@ static void on_client_readable(struct ev_loop *loop, ev_io *watcher, int revents
0
if(client_finished_parsing) {
0
- if(total_request_size == client->read) {
0
+ assert(client->read <= total_request_size);
0
+ if(total_request_size == client->read || total_request_size > EBB_BUFFERSIZE) {
0
+ client->body_head = client->request_buffer + client->parser.nread;
0
+ client->body_head_len = client->read - client->parser.nread;
0
ev_io_stop(loop, watcher);
0
- client->nread_from_body = 0;
0
- if(total_request_size > EBB_BUFFERSIZE ) {
0
- /* read body into file - in a thread */
0
- ev_io_stop(loop, watcher);
0
- int ret = pthread_create(&thread, NULL, read_body_into_file, client);
0
- pthread_detach(thread);
0
@@ -342,7 +250,7 @@ static void client_init(ebb_client *client)
0
- client->read = client->nread_from_body = 0;
0
if(client->request_buffer == NULL) {
0
/* Only allocate the request_buffer once */
0
client->request_buffer = (char*)malloc(EBB_BUFFERSIZE);
0
@@ -355,8 +263,6 @@ static void client_init(ebb_client *client)
0
g_string_free(client->response_buffer, TRUE);
0
client->response_buffer = g_string_new("");
0
- client->upload_filename = NULL;
0
/* SETUP READ AND TIMEOUT WATCHERS */
0
client->write_watcher.data = client;
0
ev_init (&client->write_watcher, on_client_writable);
0
@@ -631,12 +537,6 @@ void ebb_client_close(ebb_client *client)
0
ev_io_stop(client->server->loop, &client->write_watcher);
0
ev_timer_stop(client->server->loop, &client->timeout_watcher);
0
- if(client->upload_filename) {
0
- fclose(client->upload_file);
0
- unlink(client->upload_filename);
0
- client->upload_file = NULL;
0
- client->upload_filename = NULL;
0
g_string_free(client->response_buffer, TRUE);
0
@@ -701,36 +601,6 @@ void ebb_client_write_body(ebb_client *client, const char *data, int length)
0
-/* pass an allocated buffer and the length to read. this function will try to
0
- * fill the buffer with that length of data read from the body of the request.
0
- * the return value says how much was actually written.
0
-int ebb_client_read(ebb_client *client, char *buffer, int length)
0
- assert(client->in_use);
0
- if(!client->open) return -1;
0
- assert(client_finished_parsing);
0
- if(client->upload_file) {
0
- read = fread(buffer, 1, length, client->upload_file);
0
- /* TODO error checking! */
0
- char* request_body = client->request_buffer + client->parser.nread;
0
- read = ramp(min(length, client->parser.content_length - client->nread_from_body));
0
- , request_body + client->nread_from_body
0
- client->nread_from_body += read;
0
// int ebb_client_should_keep_alive(ebb_client*)
0
// /* TODO - return boolean */
Comments
No one has commented yet.