scorpioengine/src/server.h

88 lines
1.8 KiB
C++

#ifndef headerfile_libscorpiohttpserver_src_server_h
#define headerfile_libscorpiohttpserver_src_server_h
#include <list>
#include <sys/select.h>
#include "client.h"
#include "headers_parser.h"
class Server
{
public:
Server();
Server(const Server & s) = delete;
Server & operator=(const Server & s) = delete;
virtual ~Server();
void CloseMainSocket();
void CloseClientSockets();
void Close();
void Prepare();
void Wait();
private:
// we cannot use vector here because Client has aiocb struct
// and when adding clients to tab pointers can be invalidated for aio reading
std::list<Client> client_tab;
int main_socket;
fd_set read_set, write_set;
bool close_server;
HeadersParser headers_parser;
char * in_buffer; // rename to a better name
size_t in_buffer_max_len;
//size_t how_many_sending_file; // how many sockets currently is used for sending files
void PrepareSocketsForSelect(int & fd_max, timeval & t, int & how_many_external_resources);
void AddNewClient();
void AllocInputBuffer();
void ReadWriteToClients();
void ReadInputFromClient(Client & client);
void WriteOutputToClient(Client & client);
void ReadExternalResource(int how_many_external_resources);
void CheckHeaders(Client & client, size_t input_buffer_index);
void ParseHeaders(Client & client);
virtual bool SelectMethodName(Client & client, const std::wstring & method_name);
void ReadExternalResource(Client & client, std::string & output_buffer);
void WriteOutputToClient(Client & client, std::string & output_buffer, size_t & output_buffer_sent);
//void RemoveClientSocket(int client_socket);
virtual void CreateAnswer(Client & client);
void PrepareMainSocket();
int FileLen(std::string & file_name, size_t & file_len);
void CreateOutputHeaders(Client & client);
};
#endif