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;
119 const socket_t& socket,
153 const socket_t& socket,
179 ssize_t
read(
char* buffer,
size_t size)
const;
200 ssize_t
write(
const char* buffer,
size_t size)
const;
211 return m_data == x.
m_data;
243 m_original(x.m_original)
254 return m_data->m_valid;
320 uint32_t permissions = 0xffffffffUL,
321 const char* owner =
nullptr,
322 const char* group =
nullptr);
337 const char* interface,
338 const char* service);
350 Socket connect(
const char* name);
365 const char* service);
408 return m_sockets.size();
416 void accept(
bool status);
429 socket_t m_wakeSockets[2];
447 inline void createSocket(
const socket_t listener);
450 bool pollAdd(
const socket_t socket);
453 bool pollDel(
const socket_t socket);
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.
bool m_waking
Set to true while there is a pending wake.
void close() const
Call this to close the socket.
Socket(Socket &&x)
Move constructor.
bool operator==(const Socket &x) const
We need this to allow the socket objects to be in sorted containers.
~Socket()
Calls close() on the socket if we are destructing the original.
ssize_t read(char *buffer, size_t size) const
Try and read a chunk of data out of the socket.
bool m_original
This is only true for a non-copy constructed object.
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.
friend class SocketGroup
Our respective SocketGroup needs private access.
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.
std::mutex mutex
Thread safe the logging mechanism.
std::set< socket_t > m_listeners
These are the sockets we listen for connections on.
Class for representing an OS level I/O socket.
bool m_closing
Indicates whether or not the connection is closing.
Socket(const Socket &x)
Copy constructor.
ssize_t write(const char *buffer, size_t size) const
Try and write a chunk of data into the socket.
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.
size_t size() const
How many active sockets (not counting listeners) are in the group.
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.
bool operator<(const Socket &x) const
We need this to allow the socket objects to be in sorted containers.
Data(const socket_t &socket, bool valid, SocketGroup &group)
Sole constructor.
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.