|
fastcgi++
A C++ FastCGI/Web API
|
Class for representing an OS level I/O socket. More...
#include <fastcgi++/sockets.hpp>
Classes | |
| struct | Data |
| Data structure to hold the shared socket data. More... | |
Public Member Functions | |
| ssize_t | read (char *buffer, size_t size) const |
| Try and read a chunk of data out of the socket. More... | |
| ssize_t | write (const char *buffer, size_t size) const |
| Try and write a chunk of data into the socket. More... | |
| bool | operator< (const Socket &x) const |
| We need this to allow the socket objects to be in sorted containers. More... | |
| bool | operator== (const Socket &x) const |
| We need this to allow the socket objects to be in sorted containers. More... | |
| Socket (const Socket &x) | |
| Copy constructor. More... | |
| Socket & | operator= (const Socket &x) |
| Assignment. More... | |
| Socket (Socket &&x) | |
| Move constructor. More... | |
| ~Socket () | |
| Calls close() on the socket if we are destructing the original. More... | |
| bool | valid () const |
| Returns true if this socket is still open and capable of read/write. More... | |
| void | close () const |
| Call this to close the socket. More... | |
| Socket () | |
| Creates an invalid socket with no original. More... | |
Private Member Functions | |
| Socket (const socket_t &socket, SocketGroup &group, bool valid=true) | |
| Sole non-copy/move constructor. More... | |
Private Attributes | |
| std::shared_ptr< Data > | m_data |
| Shared pointer to hold the socket data. More... | |
| bool | m_original |
| This is only true for a non-copy constructed object. More... | |
Friends | |
| class | SocketGroup |
| Our respective SocketGroup needs private access. More... | |
Class for representing an OS level I/O socket.
It works together with the SocketGroup class to establish all the interfacing between the OS and the Transceiver class to communicate with the outside world. The objects of this class represent individual connections to the FastCGI server. They are consolidated and managed within the SocketGroup class.
No non-const member functions are thread safe. This means you can only use valid() and the comparison operators across multiple threads.
Definition at line 83 of file sockets.hpp.
|
private |
Sole non-copy/move constructor.
This constructor is only accessible to the SocketGroup class to create new "original" sockets as they are accepted. Only sockets created with this constructor will have m_original set to true.
| [in,out] | socket | The OS level socket identifier to associate with this. |
| [in,out] | group | The SocketGroup object that created and is consolidating this socket and it's peers. |
| [in] | valid | Set to false if this is a dead socket. Sometimes it may be needed to create a socket that is invalid off the start. |
Definition at line 53 of file sockets.cpp.
References close(), ERROR_LOG, and Fastcgipp::SocketGroup::pollAdd().
|
inline |
Copy constructor.
Any sockets built using the copy constructor will not be marked original.
Definition at line 219 of file sockets.hpp.
|
inline |
Move constructor.
This constructor serves the purposes of moving "original" sockets into containers. The source socket has it's originality stripped and moved to the destination.
Definition at line 241 of file sockets.hpp.
| Fastcgipp::Socket::~Socket | ( | ) |
Calls close() on the socket if we are destructing the original.
Definition at line 138 of file sockets.cpp.
| Fastcgipp::Socket::Socket | ( | ) |
Creates an invalid socket with no original.
Definition at line 646 of file sockets.cpp.
| void Fastcgipp::Socket::close | ( | ) | const |
Call this to close the socket.
If the socket is valid, this will do the following:
If the socket is already invalid, calling this does nothing.
Definition at line 122 of file sockets.cpp.
Referenced by Fastcgipp::Transceiver::cleanupSocket(), Socket(), and Fastcgipp::Transceiver::transmit().
|
inline |
We need this to allow the socket objects to be in sorted containers.
Definition at line 203 of file sockets.hpp.
References m_data.
Assignment.
Any sockets assigned with this will not be marked original.
Definition at line 228 of file sockets.hpp.
References m_data, and m_original.
|
inline |
We need this to allow the socket objects to be in sorted containers.
Definition at line 209 of file sockets.hpp.
References m_data.
| ssize_t Fastcgipp::Socket::read | ( | char * | buffer, |
| size_t | size | ||
| ) | const |
Try and read a chunk of data out of the socket.
This function will attempt to read the requested amount of data out of the socket into the buffer. The return value indicates both how many bytes were read and socket validity.
If an error occurs during the read operation the socket is closed/destroyed, marked invalid and -1 is returned. If the other end has hung up, you can continue reading until the internal buffer is empty. At that point -1 is returned and the socket is closed/destroyed and marked invalid.
| [out] | buffer | Pointer to memory location to which data should be read into. |
| [in] | size | Maximum amount of data to read into the buffer. Obviously this should be less than or equal to the actual amount of memory allocated in the buffer. |
Definition at line 68 of file sockets.cpp.
References WARNING_LOG.
Referenced by Fastcgipp::Transceiver::receive().
|
inline |
Returns true if this socket is still open and capable of read/write.
Definition at line 252 of file sockets.hpp.
References m_data.
Referenced by Fastcgipp::Transceiver::receive().
| ssize_t Fastcgipp::Socket::write | ( | const char * | buffer, |
| size_t | size | ||
| ) | const |
Try and write a chunk of data into the socket.
This function will attempt to write the requested amount of data into the socket from the buffer. The return value indicates either how many bytes were actually written or socket validity.
If an error occurs during the write operation the socket is closed/destroyed, marked invalid and -1 is returned. If the other end has hung up, -1 will be returned but this does not mean the socket has been closed/destroyed yet. There may yet be data waiting to be read(). The socket will not be automatically shut down until said data is read.
| [out] | buffer | Pointer to memory location to which data should be written from. |
| [in] | size | Maximum amount of data to write from the buffer. |
Definition at line 99 of file sockets.cpp.
References WARNING_LOG.
Referenced by Fastcgipp::Transceiver::transmit().
|
friend |
Our respective SocketGroup needs private access.
Definition at line 87 of file sockets.hpp.
|
private |
Shared pointer to hold the socket data.
Definition at line 133 of file sockets.hpp.
Referenced by operator<(), operator=(), operator==(), and valid().
|
private |
This is only true for a non-copy constructed object.
Definition at line 136 of file sockets.hpp.
Referenced by operator=().
1.8.14