34 std::unique_ptr<Record> record;
58 #if FASTCGIPP_LOG_LEVEL > 3 65 #if FASTCGIPP_LOG_LEVEL > 3 66 ++m_connectionKillCount;
80 while(!m_terminate && !(m_stop && m_sockets.size()==0))
82 socket = m_sockets.poll(flushed);
91 m_sockets.accept(
false);
104 m_sockets.accept(
true);
105 if(!m_thread.joinable())
108 m_thread.swap(thread);
114 if(m_thread.joinable())
122 m_sendMessage(sendMessage)
124 ,m_connectionKillCount(0),
125 m_connectionRDHupCount(0),
131 DIAG_LOG(
"Transceiver::Transciever(): Initialized")
138 Block& buffer=m_receiveBuffers[socket];
145 const ssize_t read = socket.
read(
150 cleanupSocket(socket);
160 +reinterpret_cast<Protocol::Header*>(
161 buffer.
begin())->contentLength
162 +reinterpret_cast<Protocol::Header*>(
163 buffer.
begin())->paddingLength);
168 const ssize_t read = socket.
read(
174 cleanupSocket(socket);
182 message.
data = std::move(buffer);
187 #if FASTCGIPP_LOG_LEVEL > 3 195 m_receiveBuffers.erase(socket);
200 #if FASTCGIPP_LOG_LEVEL > 3 201 ++m_connectionRDHupCount;
210 std::unique_ptr<Record> record(
new Record(
215 std::lock_guard<std::mutex> lock(m_sendBufferMutex);
216 m_sendBuffer.push_back(std::move(record));
219 #if FASTCGIPP_LOG_LEVEL > 3 227 DIAG_LOG(
"Transceiver::~Transceiver(): Locally closed sockets ==== " \
228 << m_connectionKillCount)
229 DIAG_LOG(
"Transceiver::~Transceiver(): Remotely closed sockets === " \
230 << m_connectionRDHupCount)
231 DIAG_LOG(
"Transceiver::~Transceiver(): Remaining receive buffers = " \
232 << m_receiveBuffers.size())
233 DIAG_LOG(
"Transceiver::~Transceiver(): Records queued === " \
235 DIAG_LOG(
"Transceiver::~Transceiver(): Records sent ===== " \
237 DIAG_LOG(
"Transceiver::~Transceiver(): Records received = " \
238 << m_recordsReceived)
void send(const Socket &socket, Block &&data, bool kill)
Queue up a block of data for transmission.
void close() const
Call this to close the socket.
std::deque< std::unique_ptr< Record > > m_sendBuffer
Buffer for transmitting data
void handler()
General transceiver handler.
void header(Level level)
Send a log header to logstream.
void join()
Block until a stop() or terminate() is called and completed.
void cleanupSocket(const Socket &socket)
Cleanup a dead socket.
Data structure used to pass messages to requests.
Transceiver(const std::function< void(Protocol::RequestId, Message &&)> sendMessage)
Constructor.
size_t size() const
See the relevant data size.
bool valid() const
Returns true if this socket is still open and capable of read/write.
#define FASTCGIPP_LOG_LEVEL
const uint16_t badFcgiId
Constant that defines a bad/special FcgiId.
void terminate()
Call from any thread to terminate the handler() thread.
Simple FastCGI record to queue up for transmission.
void start()
Call from any thread to start the handler() thread.
ssize_t read(char *buffer, size_t size) const
Try and read a chunk of data out of the socket.
std::map< Socket, Block > m_receiveBuffers
Container associating sockets with their receive buffers.
Class for representing an OS level I/O socket.
void receive(Socket &socket)
Receive data on the specified socket.
A unique identifier for each FastCGI request.
Block data
The raw data being passed along with the message.
ssize_t write(const char *buffer, size_t size) const
Try and write a chunk of data into the socket.
void stop()
Call from any thread to stop the handler() thread.
bool transmit()
Transmit all buffered data possible.
Declares the Fastcgipp::Transceiver class.
size_t reserve() const
See the reserve size.
char * end()
Pointer to 1+ the last element.
Declares the Fastcgipp debugging/logging facilities.
std::mutex m_sendBufferMutex
Thread safe the send buffer.
Data structure to hold a block of raw data.
char * begin()
Pointer to the first element.