Permalink
Browse files

Merge pull request #8 from lasselukkari/count-data

count incoming and outgoing data
  • Loading branch information...
lasselukkari committed Jun 3, 2017
2 parents c469fae + 7385052 commit 8d3907c3491fdfcee9d40abde069f7c2d6a7b5f3
Showing with 30 additions and 9 deletions.
  1. +26 −8 aWOT.cpp
  2. +4 −1 aWOT.h
View
@@ -30,6 +30,7 @@ Request::Request() :
m_pushbackDepth(0),
m_readingContent(false),
m_contentLeft(0),
m_bytesRead(0),
m_headerTail(NULL),
m_query(NULL),
m_queryComplete(false),
@@ -43,6 +44,7 @@ Request::Request() :
/* Initializes the request instance ready to process the incoming HTTP request. */
void Request::init(Client *client, char* buff, int bufflen) {
m_clientObject = client;
m_bytesRead = 0;
m_urlPath = buff;
m_urlPathLength = bufflen - 1;
}
@@ -400,6 +402,8 @@ int Request::read() {
int ch = m_clientObject->read();
if (ch != -1) {
m_bytesRead++;
if (m_readingContent) {
--m_contentLeft;
}
@@ -423,6 +427,10 @@ int Request::read() {
}
}
int Request::bytesRead() {
return m_bytesRead;
}
int Request::peek() {
int c = read();
push(c);
@@ -560,12 +568,14 @@ int Request::m_hexToInt(char *hex) {
/* Request class constructor. */
Response::Response() :
m_clientObject(NULL),
m_headersCount(0) {
m_headersCount(0),
m_bytesSent(0) {
}
/* Initializes the request instance ready for outputting the HTTP response. */
void Response::init(Client *client) {
m_clientObject = client;
m_bytesSent = 0;
}
void Response::writeP(const unsigned char *data, size_t length) {
@@ -574,15 +584,15 @@ void Response::writeP(const unsigned char *data, size_t length) {
while (length--) {
if (bufferEnd == 32) {
m_clientObject->write(buffer, 32);
write(buffer, 32);
bufferEnd = 0;
}
(buffer[bufferEnd++] = pgm_read_byte(data++));
}
if (bufferEnd > 0) {
m_clientObject->write(buffer, bufferEnd);
write(buffer, bufferEnd);
}
}
@@ -592,23 +602,31 @@ void Response::printP(const unsigned char *str) {
while ((buffer[bufferEnd++] = pgm_read_byte(str++))) {
if (bufferEnd == 32) {
m_clientObject->write(buffer, 32);
write(buffer, 32);
bufferEnd = 0;
}
}
// write out everything left but trailing NUL
if (bufferEnd > 1) {
m_clientObject->write(buffer, bufferEnd - 1);
write(buffer, bufferEnd - 1);
}
}
size_t Response::write(uint8_t ch) {
return m_clientObject->write(ch);
size_t bytesSent = m_clientObject->write(ch);
m_bytesSent += bytesSent;
return bytesSent;
}
size_t Response::write(uint8_t* ch, size_t size) {
return m_clientObject->write(ch, size);
size_t bytesSent = m_clientObject->write(ch, size);
m_bytesSent += bytesSent;
return bytesSent;
}
int Response::bytesSent() {
return m_bytesSent;
}
/* Sets a header name and value pair to the response. */
@@ -733,7 +751,7 @@ void Response::reset() {
}
void Response::m_printCRLF() {
m_clientObject->write((const uint8_t *) "\r\n", 2);
write((unsigned char*) "\r\n", 2);
}
void Response::m_printHeaders() {
View
5 aWOT.h
@@ -135,6 +135,7 @@ class Request: public Stream {
int available();
int read();
int bytesRead();
int peek();
void push(int ch);
void flush();
@@ -158,6 +159,7 @@ class Request: public Stream {
char m_paramBuffer[SERVER_PARAM_LENGTH];
int m_contentLeft;
int m_bytesRead;
HeaderNode* m_headerTail;
@@ -190,6 +192,7 @@ class Response: public Stream {
void writeP(const unsigned char *data, size_t length);
size_t write(uint8_t ch);
size_t write(uint8_t *ch, size_t size);
int bytesSent();
void set(const char* name, const char* value);
@@ -225,7 +228,7 @@ class Response: public Stream {
} m_headers[SERVER_HEADERS_COUNT];
unsigned int m_headersCount;
int m_bytesSent;
};
class Router {

0 comments on commit 8d3907c

Please sign in to comment.