Skip to content

Commit

Permalink
Partially revert 65bc666
Browse files Browse the repository at this point in the history
* Removes accidental changes from earlier commit
  • Loading branch information
bastih committed Sep 21, 2013
1 parent fc52b44 commit 38935c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
27 changes: 6 additions & 21 deletions src/lib/net/AsyncConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ebb_connection *new_connection(ebb_server *server, struct sockaddr_in *addr) {
ebb_connection_init(connection);
connection->data = connection_data;
connection->new_request = new_request;
//connection->on_close = on_close;
connection->on_close = on_close;
connection->on_timeout = on_timeout;

connection_data->ev_loop = server->loop;
Expand Down Expand Up @@ -61,14 +61,6 @@ void request_complete(ebb_request *request) {
connection_data->request = request;
gettimeofday(&connection_data->starttime, nullptr);


//Handle persistent connections
if (ebb_request_should_keep_alive(request)) {
connection_data->responses_to_write++;
} else {
connection_data->responses_to_write = 1;
}

// Try to route to appropriate handler based on path
const AbstractRequestHandlerFactory *handler_factory;
try {
Expand Down Expand Up @@ -143,12 +135,10 @@ void write_cb(struct ev_loop *loop, struct ev_async *w, int revents) {
conn->code = conn->code == 0 ? 200 : conn->code;
conn->contentType = conn->contentType.size() == 0 ? "application/json" : conn->contentType;
conn->write_buffer_len += snprintf((char *)conn->write_buffer, max_header_length,
"HTTP/1.1 %lu OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\nConnection: %s\r\n\r\n",
"HTTP/1.1 %lu OK\r\nContent-Type: %s\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
conn->code,
conn->contentType.c_str(),
conn->response_length,
"Keep-Alive");
//conn->responses_to_write <= 1 ? "Close" : "Keep-Alive");
conn->response_length);

// Append the response
memcpy(conn->write_buffer + conn->write_buffer_len, conn->response, conn->response_length);
Expand All @@ -159,21 +149,16 @@ void write_cb(struct ev_loop *loop, struct ev_async *w, int revents) {
} else {
printf("%s [%s] %s %s (%f s) not sent\n", inet_ntoa(conn->addr.sin_addr), timestr, method, conn->path, duration);
}

ev_async_stop(conn->ev_loop, &conn->ev_write);
// When connection is nullptr, `continue_responding` won't fire since we never sent data to the client,
// thus, we'll need to clean up manually here, while connection has already been cleaned up in on `on_response`
if (conn->connection == nullptr) delete conn;
}

void continue_responding(ebb_connection *connection) {
AsyncConnection* cd = static_cast<AsyncConnection*>(connection->data);
// Close the connection if required
// if (--cd->responses_to_write <= 0) {
// delete(AsyncConnection *) connection->data;
// connection->data = nullptr;
// ebb_connection_schedule_close(connection);
// }
delete(AsyncConnection *) connection->data;
connection->data = nullptr;
ebb_connection_schedule_close(connection);
}

void on_close(ebb_connection *connection) {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/net/AsyncConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class AsyncConnection : public AbstractConnection {

bool closed;

int responses_to_write = 0;

// HTPP Code used to send to the client
size_t code;

Expand Down
5 changes: 1 addition & 4 deletions static/webq/js/hyrise.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ function runQuery() {
}).on("page", printQueryResult);
printQueryResult(null, 0);
},
error: function(e) {
$("#btn_submit").button("reset");
console.log(e);
}
error: function(e) { console.log(e);}
})

// Prevent default
Expand Down

0 comments on commit 38935c0

Please sign in to comment.