Commit 61f42550 authored by octal's avatar octal

Client will now detect when the remote closes the connection

parent 0c3af626
......@@ -94,6 +94,7 @@ struct Connection : public std::enable_shared_from_this<Connection> {
Fd fd;
void handleResponsePacket(const char* buffer, size_t totalBytes);
void handleError(const char* error);
void handleTimeout();
std::string dump() const;
......
......@@ -42,7 +42,7 @@ splitUrl(const std::string& url) {
match_literal('.', cursor);
StreamCursor::Token hostToken(cursor);
match_until('/', cursor);
match_until({ '?', '/' }, cursor);
StringView host(hostToken.rawText(), hostToken.size());
StringView page(cursor.offset(), buf.endptr());
......@@ -114,8 +114,12 @@ namespace {
auto host = s.first;
auto path = s.second;
auto pathStr = path.toString();
OUT(os << request.method() << " ");
OUT(os << path.toString());
if (pathStr[0] != '/')
OUT(os << '/');
OUT(os << pathStr);
OUT(os << " HTTP/1.1" << crlf);
if (!writeCookies(request.cookies(), buf)) return false;
......@@ -322,17 +326,15 @@ Transport::handleIncoming(const std::shared_ptr<Connection>& connection) {
handleResponsePacket(connection, buffer, totalBytes);
}
} else {
if (errno == ECONNRESET) {
}
else {
throw std::runtime_error(strerror(errno));
}
connection->handleError(strerror(errno));
}
break;
}
else if (bytes == 0) {
if (totalBytes > 0) {
handleResponsePacket(connection, buffer, totalBytes);
} else {
connection->handleError("Remote closed connection");
}
connections.erase(connection->fd);
connection->close();
......@@ -462,6 +464,18 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) {
}
}
void
Connection::handleError(const char* error) {
auto req = std::move(inflightRequests.front());
if (req.timer) {
req.timer->disarm();
timerPool_.releaseTimer(req.timer);
}
req.reject(Net::Error(error));
req.onDone();
}
void
Connection::handleTimeout() {
auto req = std::move(inflightRequests.front());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment