2019-05-04 23:21:33 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
2019-05-04 23:42:03 -07:00
|
|
|
#include "firebuf/stream_buffer.h"
|
|
|
|
|
|
2019-05-04 23:21:33 -07:00
|
|
|
#include "request.h"
|
|
|
|
|
|
|
|
|
|
namespace firecgi {
|
|
|
|
|
|
|
|
|
|
class Connection {
|
|
|
|
|
public:
|
2019-05-09 19:19:26 -07:00
|
|
|
Connection(int sock, const sockaddr_in6& client_addr, const std::function<void(Request*)>& callback, const std::unordered_set<std::string_view>& headers, int max_request_len);
|
2019-05-04 23:21:33 -07:00
|
|
|
~Connection();
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] int Read();
|
|
|
|
|
[[nodiscard]] bool Write(const std::vector<iovec>& vecs);
|
|
|
|
|
|
2019-05-10 00:40:38 -07:00
|
|
|
[[nodiscard]] uint64_t Requests() const;
|
|
|
|
|
|
2019-05-04 23:21:33 -07:00
|
|
|
private:
|
|
|
|
|
const int sock_;
|
2019-05-07 22:56:00 -07:00
|
|
|
const std::function<void(Request*)>& callback_;
|
2019-05-04 23:21:33 -07:00
|
|
|
const std::unordered_set<std::string_view>& headers_;
|
2019-05-07 22:56:00 -07:00
|
|
|
firebuf::StreamBuffer buf_;
|
|
|
|
|
Request request_;
|
2019-05-04 23:21:33 -07:00
|
|
|
|
|
|
|
|
uint64_t requests_ = 0;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace firecgi
|