-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionClass.cpp
More file actions
38 lines (32 loc) · 1.42 KB
/
Copy pathConnectionClass.cpp
File metadata and controls
38 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "ConnectionClass.hpp"
ConnectionClass::ConnectionClass(int socket, std::map<std::string, Server *> hosts) : _socket(socket),
_closeConnection(false), _responseStatus("200"), _writingBuff(""), _hosts(hosts),
_writer(new WritingTransmitterClass(_socket, _responseStatus, IS_PROCESSING_FIRST_LINE, _writingBuff, _closeConnection)),
_reader(new ReadingTransmitterClass(_socket, _responseStatus, IS_PROCESSING_FIRST_LINE, _writingBuff, _closeConnection, _hosts)),
_stateOfConnection(IS_PROCESSING_FIRST_LINE) {
}
void ConnectionClass::receive() {
_reader->_connectionState = _stateOfConnection;
if (_stateOfConnection == IS_PROCESSING_FIRST_LINE
|| _stateOfConnection == IS_PROCESSING_HEADERS
|| _stateOfConnection == IS_READING_BODY
|| _stateOfConnection == ERROR_WHILE_READING
|| _stateOfConnection == IS_FORMING_RESPONSE) {
_reader->env = this->env;
_reader->operate();
_stateOfConnection = _reader->getConnectionState();
}
}
void ConnectionClass::transmit() {
_writer->_connectionState = _stateOfConnection;
if (_stateOfConnection == IS_WRITING_RESPONSE) {
_writer->operate();
_stateOfConnection = _writer->getConnectionState();
}
}
ConnectionState ConnectionClass::getConnectionStatus() { return _stateOfConnection; }
void ConnectionClass::setEnv(char **env) { this->env = env; }
ConnectionClass::~ConnectionClass() {
delete _reader;
delete _writer;
}