34 #ifndef FASTCGIPP_SOCKETS_HPP 35 #define FASTCGIPP_SOCKETS_HPP 58 #ifdef FASTCGIPP_LINUX 61 #elif defined FASTCGIPP_UNIX 62 typedef std::vector<pollfd>
poll_t;
179 ssize_t
read(
char* buffer,
size_t size)
const;
200 ssize_t
write(
const char* buffer,
size_t size)
const;
320 uint32_t permissions = 0xffffffffUL,
321 const char* owner =
nullptr,
322 const char* group =
nullptr);
337 const char* interface,
338 const char* service);
365 const char* service);
458 #if FASTCGIPP_LOG_LEVEL > 3 459 std::atomic_ullong m_incomingConnectionCount;
463 std::atomic_ullong m_outgoingConnectionCount;
466 std::atomic_ullong m_connectionKillCount;
469 std::atomic_ullong m_connectionRDHupCount;
472 std::atomic_ullong m_bytesSent;
475 std::atomic_ullong m_bytesReceived;
const int poll_t
Our polling type using the Linux kernel is simply an int.
std::map< socket_t, Socket > m_sockets
All the sockets.
Socket & operator=(const Socket &x)
Assignment.
Topmost namespace for the fastcgi++ library.
socket_t m_wakeSockets[2]
A pair of sockets for wakeup purposes.
bool m_waking
Set to true while there is a pending wake.
Socket(Socket &&x)
Move constructor.
bool operator==(const Socket &x) const
We need this to allow the socket objects to be in sorted containers.
void close() const
Call this to close the socket.
~Socket()
Calls close() on the socket if we are destructing the original.
bool m_original
This is only true for a non-copy constructed object.
bool listen()
Listen to the default Fastcgi socket.
bool valid() const
Returns true if this socket is still open and capable of read/write.
std::shared_ptr< Data > m_data
Shared pointer to hold the socket data.
void accept(bool status)
Should we accept new connections?
void createSocket(const socket_t listener)
Accept a new connection and create it's socket.
SocketGroup & m_group
SocketGroup object this socket is tied to.
int socket_t
Our socket identifier type in GNU/Linux is simply an int.
std::mutex m_wakingMutex
We need this mutex to thread safe the wake() function.
bool pollDel(const socket_t socket)
Remove a socket identifier to the poll list.
std::mutex mutex
Thread safe the logging mechanism.
std::set< socket_t > m_listeners
These are the sockets we listen for connections on.
void wake()
Wake up from a nap inside poll()
ssize_t read(char *buffer, size_t size) const
Try and read a chunk of data out of the socket.
Class for representing an OS level I/O socket.
Socket poll(bool block)
Poll socket set for new incoming connections and data.
bool m_closing
Indicates whether or not the connection is closing.
ssize_t write(const char *buffer, size_t size) const
Try and write a chunk of data into the socket.
Socket(const Socket &x)
Copy constructor.
size_t size() const
How many active sockets (not counting listeners) are in the group.
bool pollAdd(const socket_t socket)
Add a socket identifier to the poll list.
Class for representing an OS level socket that listens for connections.
Data structure to hold the shared socket data.
const socket_t m_socket
OS level socket identifier.
poll_t m_poll
Our poll object.
bool operator<(const Socket &x) const
We need this to allow the socket objects to be in sorted containers.
std::atomic_bool m_accept
Set to true if we should be accepting new connections.
std::deque< std::string > m_filenames
Filenames to cleanup when we're done.
Data(const socket_t &socket, bool valid, SocketGroup &group)
Sole constructor.
Socket connect(const char *name)
Connect to a named socket.
bool m_valid
Indicates whether or not the socket is dead/invalid.
Socket()
Creates an invalid socket with no original.
std::atomic_bool m_refreshListeners
Set to true if we should refresh the listeners in the poll.