0
@@ -39,23 +39,22 @@ int thin_print_headers(thin_connection_t *connection, char *str)
0
void thin_connection_writable_cb(EV_P_ struct ev_io *watcher, int revents)
0
thin_connection_t *connection = get_ev_data(connection, watcher, write);
0
/* TODO write in chunk */
0
- /* TODO get rid of that malloc or do something less stupid! */
0
- msg = (char *) malloc(connection->body.len + 1024);
0
+ resp = (char *) palloc(connection->buffer_pool,
0
+ connection->body.len / connection->buffer_pool->size + 1);
0
- n = sprintf(msg, "HTTP/1.1 %d OK\r\n", connection->status);
0
- n += thin_print_headers(connection, (char *) msg + n);
0
- n += sprintf((char *) msg + n, "\r\n%s", connection->body.ptr);
0
+ n = sprintf(resp, "HTTP/1.1 %d OK\r\n", connection->status);
0
+ n += thin_print_headers(connection, (char *) resp + n);
0
+ n += sprintf((char *) resp + n, "\r\n%s", connection->body.ptr);
0
- if (send(connection->fd, msg, n, 0) < 0)
0
- free(msg); /* see, doesn't make sense... */
0
+ sent = send(connection->fd, resp, n, 0);
0
+ /* TODO do something w/ sent, maybe buffer, not all sent? */
0
+ pfree(connection->buffer_pool, resp);
0
watcher->cb = thin_connection_closable_cb;
0
@@ -67,21 +66,22 @@ void thin_connection_readable_cb(EV_P_ struct ev_io *watcher, int revents)
0
/* alloc more mem when buffer full */
0
- if (connection->read_buffer.len == connection->read_buffer.nalloc) {
0
- /* TODO refactor this into a buffer.c file? */
0
+ if (connection->read_buffer.len >= connection->read_buffer.salloc) {
0
old = connection->read_buffer.ptr;
0
- new = (char *) malloc(connection->read_buffer.nalloc * 2);
0
+ new = (char *) palloc(connection->buffer_pool,
0
+ connection->read_buffer.nalloc * 2);
0
- rb_sys_fail("
malloc");
0
+ rb_sys_fail("
palloc");
0
connection->read_buffer.ptr = new;
0
connection->read_buffer.nalloc *= 2;
0
+ connection->read_buffer.salloc *= 2;
0
+ pfree(connection->buffer_pool, old);
0
len = recv(connection->fd,
0
connection->read_buffer.ptr + connection->read_buffer.len,
0
-
THIN_BUFFER_SIZE - connection->read_buffer.len,
0
+
connection->read_buffer.salloc - connection->read_buffer.len,
0
connection->read_buffer.len += len;
0
@@ -160,6 +160,7 @@ void thin_connection_start(thin_backend_t *backend, int fd, struct sockaddr_in r
0
if (connection->read_buffer.ptr == NULL)
0
connection->read_buffer.nalloc = 1;
0
+ connection->read_buffer.salloc = connection->buffer_pool->size;
0
connection->read_buffer.len = 0;
0
@@ -191,6 +192,8 @@ void thin_connection_close(thin_connection_t *connection)
0
if (connection->read_buffer.ptr != NULL)
0
pfree(connection->buffer_pool, connection->read_buffer.ptr);
0
+ connection->read_buffer.salloc = 0;
0
+ connection->read_buffer.nalloc = 0;
0
\ No newline at end of file
Comments
No one has commented yet.