Add event handler

This commit is contained in:
juju committed 2020-05-05 15:39:59 +02:00
1 parent b42378c261
commit f512de7313
20 files changed
+717 -14

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
#include "connection.hh"
namespace paxos
{
Connection::Connection(shared_socket socket)
{
this->socket_ = socket;
servername_ = std::string();
}
Connection::~Connection()
{
}
const shared_socket& Connection::get_socket()
{
return socket_;
}
const misc::shared_fd Connection::get_socket_fd()
{
return socket_->fd_get();
}
misc::Buffer& Connection::get_buffer_in()
{
return buffer_in_;
}
misc::Buffer& Connection::get_buffer_out()
{
return buffer_out_;
}
const std::string Connection::get_origin_ip() const
{
return socket_->getsockname();
}
const std::string& Connection::get_origin_port() const
{
return socket_->get_listener_port();
}
void Connection::set_servername(const std::string& servername)
{
servername_ = servername;
}
const std::string& Connection::get_servername() const
{
return servername_;
}
}
+76
View File
@@ -0,0 +1,76 @@
/**
* \file vhost/connection.hh
* \brief Connection declaration.
*/
#pragma once
#include <iostream>
#include <memory>
#include "misc/fd.hh"
#include "socket/socket.hh"
#include "misc/buffer.hh"
namespace paxos
{
/**
* \struct Connection
* \brief Value object representing a connection.
*
* We need to keep track of the state of each request while it has not
* been fully processed.
*/
struct Connection
{
friend class APM;
Connection(shared_socket socket);
Connection(const Connection& con) = default;
Connection& operator=(const Connection&) = default;
Connection(Connection&&) = default;
Connection& operator=(Connection&&) = default;
~Connection();
/* Add members to store the information relative to the
** connection.
*/
const shared_socket& get_socket();
const misc::shared_fd get_socket_fd();
/*
** \brief Getter of the input misc::Buffer
** \return misc::Buffer
*/
misc::Buffer& get_buffer_in();
/*
** \brief Getter of the output misc::Buffer
** \return misc::Buffer
*/
misc::Buffer& get_buffer_out();
/**
* \brief Returns the ip the client accessed while connecting
*/
const std::string get_origin_ip() const;
/**
* \brief Returns the port the client accessed while connecting
*/
const std::string& get_origin_port() const;
const std::string& get_servername() const;
void set_servername(const std::string& servername);
private:
shared_socket socket_;
std::string servername_;
misc::Buffer buffer_in_;
misc::Buffer buffer_out_;
};
using shared_connection = std::shared_ptr<Connection>;
} // namespace http
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.