Skip to content

Commit

Permalink
-formatted the codebase with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
kamchatka-volcano committed Jul 10, 2023
1 parent 06612ff commit ad1f0da
Show file tree
Hide file tree
Showing 52 changed files with 853 additions and 734 deletions.
4 changes: 2 additions & 2 deletions include/fcgi_responder/fcgi_limits.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

namespace fcgi{
constexpr auto maxRecordSize = 65798;
namespace fcgi {
constexpr auto maxRecordSize = 65798;
}
23 changes: 11 additions & 12 deletions include/fcgi_responder/requester.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include <map>
#include <optional>
#include <memory>
#include <optional>
#include <string>

namespace fcgi{
namespace fcgi {
class RequesterImpl;

class RequestHandle{
class RequestHandle {
public:
RequestHandle(const std::shared_ptr<std::function<void()>>& cancelRequestHandler);
void cancelRequest();
Expand All @@ -18,16 +17,15 @@ class RequestHandle{
std::weak_ptr<std::function<void()>> cancelRequestHandler_;
};

struct ResponseData
{
struct ResponseData {
std::string data;
std::string errorMsg;
};

///
/// \brief Abstract class which implements the client logic for making requests to FastCGI applications
///
class Requester{
class Requester {

public:
///
Expand All @@ -40,7 +38,8 @@ class Requester{
/// \return RequestHandle - object which can be used to cancel request
///
std::optional<RequestHandle> sendRequest(
std::map<std::string, std::string> params, std::string data,
std::map<std::string, std::string> params,
std::string data,
const std::function<void(std::optional<ResponseData>)>& responseHandler,
bool keepConnection = false);
///
Expand All @@ -50,14 +49,14 @@ class Requester{
/// by registering a handler function.
/// \param errorInfoHandler
///
void setErrorInfoHandler(const std::function<void (const std::string &)>& handler);
void setErrorInfoHandler(const std::function<void(const std::string&)>& handler);

///
/// \brief availableRequestsNumber
/// \return number of available requests
int availableRequestsNumber() const;

///
///
/// \brief maximumConnectionsNumber
/// \return Maximum connections number
///
Expand Down Expand Up @@ -96,4 +95,4 @@ class Requester{
std::unique_ptr<RequesterImpl> impl_;
};

}
} //namespace fcgi
9 changes: 5 additions & 4 deletions include/fcgi_responder/response.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once
#include <string>
#include <functional>
#include <string>

namespace fcgi{
namespace fcgi {

///
/// \brief Move-only object used to send response data from the application
///
class Response{
class Response {
using ResponseSender = std::function<void(std::string&& data, std::string&& errorData)>;

public:
///
/// \brief Constructor
Expand Down Expand Up @@ -57,4 +58,4 @@ class Response{
ResponseSender sender_;
};

}
} //namespace fcgi
10 changes: 5 additions & 5 deletions src/constants.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once
#include <limits>
#include <cstdint>
#include <limits>

namespace fcgi{
namespace hardcoded{
namespace fcgi {
namespace hardcoded {
const uint8_t protocolVersion = 1;
const uint8_t keepConnectionMask = 1;
const uint8_t headerSize = 8;
const uint32_t maxDataMessageSize = std::numeric_limits<uint16_t>::max();
const uint32_t maxRecordPaddingSize = std::numeric_limits<uint8_t>::max();
const uint32_t maxRecordSize = headerSize + maxDataMessageSize + maxRecordPaddingSize;
}
}
} //namespace hardcoded
} //namespace fcgi
12 changes: 5 additions & 7 deletions src/datareaderstream.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "datareaderstream.h"

namespace fcgi{
namespace fcgi {

MultiPartDataReaderBuffer::MultiPartDataReaderBuffer(std::vector<std::string_view> buffers)
: buffers_{std::move(buffers)}
{}
{
}

int MultiPartDataReaderBuffer::underflow()
{
Expand All @@ -18,10 +19,7 @@ int MultiPartDataReaderBuffer::underflow()
}
}
}
return gptr() == egptr()
? std::char_traits<char>::eof()
: std::char_traits<char>::to_int_type(*gptr());
return gptr() == egptr() ? std::char_traits<char>::eof() : std::char_traits<char>::to_int_type(*gptr());
}


}
} //namespace fcgi
7 changes: 4 additions & 3 deletions src/datareaderstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string_view>
#include <vector>

namespace fcgi{
namespace fcgi {

class MultiPartDataReaderBuffer : public std::streambuf {
public:
Expand All @@ -16,7 +16,8 @@ class MultiPartDataReaderBuffer : public std::streambuf {
std::size_t bufferIndex_ = 0;
};

class DataReaderStream : private MultiPartDataReaderBuffer, public std::istream {
class DataReaderStream : private MultiPartDataReaderBuffer,
public std::istream {
public:
template<typename... T>
explicit DataReaderStream(T&&... buffers)
Expand All @@ -27,4 +28,4 @@ class DataReaderStream : private MultiPartDataReaderBuffer, public std::istream
}
};

}
} //namespace fcgi
5 changes: 2 additions & 3 deletions src/datawriterstream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "datawriterstream.h"

namespace fcgi{
namespace fcgi {

DataWriterBuffer::DataWriterBuffer(std::size_t bufferMaxSize)
{
Expand All @@ -19,7 +19,6 @@ void DataWriterBuffer::reset(std::size_t size)
setp(buffer_.data(), buffer_.data() + buffer_.size());
}


DataWriterStream::DataWriterStream(std::size_t bufferMaxSize)
: DataWriterBuffer{bufferMaxSize}
, std::ostream{this}
Expand All @@ -36,4 +35,4 @@ void DataWriterStream::resetBuffer(std::size_t size)
DataWriterBuffer::reset(size);
}

}
} //namespace fcgi
13 changes: 6 additions & 7 deletions src/datawriterstream.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once
#include <streambuf>
#include <ostream>
#include <streambuf>

namespace fcgi{
namespace fcgi {

class DataWriterBuffer : public std::streambuf
{
class DataWriterBuffer : public std::streambuf {
public:
explicit DataWriterBuffer(std::size_t bufferMaxSize);
const std::string& data() const;
Expand All @@ -15,12 +14,12 @@ class DataWriterBuffer : public std::streambuf
std::string buffer_;
};

class DataWriterStream : private DataWriterBuffer, public std::ostream {
class DataWriterStream : private DataWriterBuffer,
public std::ostream {
public:
explicit DataWriterStream(std::size_t bufferMaxSize);
const std::string& buffer() const;
void resetBuffer(std::size_t size);

};

}
} //namespace fcgi
4 changes: 2 additions & 2 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "decoder.h"
#include <algorithm>

namespace fcgi{
namespace fcgi {

Decoder::Decoder(std::istream& input)
: input_{input}
Expand Down Expand Up @@ -47,4 +47,4 @@ void Decoder::skip(std::size_t numOfBytes)
input_.get(ch);
}

}
} //namespace fcgi
6 changes: 3 additions & 3 deletions src/decoder.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
#include <istream>

namespace fcgi{
namespace fcgi {

class Decoder{
class Decoder {
public:
explicit Decoder(std::istream& input);
Decoder& operator>>(uint8_t& val);
Expand All @@ -17,4 +17,4 @@ class Decoder{
std::istream& input_;
};

}
} //namespace fcgi
4 changes: 2 additions & 2 deletions src/encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "encoder.h"
#include <algorithm>

namespace fcgi{
namespace fcgi {

Encoder::Encoder(std::ostream& stream)
: output_{stream}
Expand Down Expand Up @@ -47,4 +47,4 @@ void Encoder::addPadding(std::size_t numOfBytes)
output_.put(ch);
}

}
} //namespace fcgi
6 changes: 3 additions & 3 deletions src/encoder.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once
#include <ostream>

namespace fcgi{
namespace fcgi {

class Encoder{
class Encoder {
public:
explicit Encoder(std::ostream& stream);
Encoder& operator<<(uint8_t val);
Expand All @@ -17,4 +17,4 @@ class Encoder{
std::ostream& output_;
};

}
} //namespace fcgi
29 changes: 17 additions & 12 deletions src/errors.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "errors.h"
#include <string>

namespace fcgi{
namespace fcgi {

ProtocolError::ProtocolError(const std::string& msg)
: std::runtime_error{msg}
Expand All @@ -19,21 +19,24 @@ uint8_t UnsupportedVersion::protocolVersion() const
return protocolVersion_;
}

namespace
{
namespace {

std::string invalidValueTypeToString(InvalidValueType type)
{
switch (type){
case InvalidValueType::RecordType: return "Record type";
case InvalidValueType::Role: return "Role";
case InvalidValueType::ProtocolStatus: return "Protocol status";
case InvalidValueType::ValueRequest: return "Value request";
switch (type) {
case InvalidValueType::RecordType:
return "Record type";
case InvalidValueType::Role:
return "Role";
case InvalidValueType::ProtocolStatus:
return "Protocol status";
case InvalidValueType::ValueRequest:
return "Value request";
}
return {};
}

}
} //namespace

InvalidValue::InvalidValue(InvalidValueType type, uint32_t value)
: ProtocolError{""}
Expand Down Expand Up @@ -77,7 +80,8 @@ const char* InvalidValue::what() const noexcept
RecordMessageReadError::RecordMessageReadError(const std::string& msg, std::size_t recordSize)
: ProtocolError{"Record message read error: " + msg}
, recordSize_{recordSize}
{}
{
}

std::size_t RecordMessageReadError::recordSize() const
{
Expand All @@ -87,11 +91,12 @@ std::size_t RecordMessageReadError::recordSize() const
InvalidRecordType::InvalidRecordType(uint8_t typeValue)
: ProtocolError{"Record type \"" + std::to_string(typeValue) + "\" is invalid."}
, typeValue_{typeValue}
{}
{
}

uint8_t InvalidRecordType::recordType() const
{
return typeValue_;
}

}
} //namespace fcgi
Loading

0 comments on commit ad1f0da

Please sign in to comment.