ServerCore/latex/classcore_1_1Socket.tex

207 lines
14 KiB
TeX

\hypertarget{classcore_1_1Socket}{}\section{core\+:\+:Socket Class Reference}
\label{classcore_1_1Socket}\index{core\+::\+Socket@{core\+::\+Socket}}
{\ttfamily \#include $<$Socket.\+h$>$}
Inheritance diagram for core\+:\+:Socket\+:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classcore_1_1Socket__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for core\+:\+:Socket\+:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=217pt]{classcore_1_1Socket__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classcore_1_1Socket_a0009f3813f6d64285f3dad602e4e01cf}\label{classcore_1_1Socket_a0009f3813f6d64285f3dad602e4e01cf}}
{\bfseries Socket} (\hyperlink{classcore_1_1EPoll}{E\+Poll} \&e\+Poll)
\item
\mbox{\Hypertarget{classcore_1_1Socket_a36f8a8fda1d79995228b52c2fa01873b}\label{classcore_1_1Socket_a36f8a8fda1d79995228b52c2fa01873b}}
{\bfseries Socket} (\hyperlink{classcore_1_1EPoll}{E\+Poll} \&e\+Poll, std\+::string text)
\item
void \hyperlink{classcore_1_1Socket_af2d1b6de7a64a9d446b0305b6ec47b31}{shutdown} (std\+::string text=\char`\"{}unknown\char`\"{})
\item
void \hyperlink{classcore_1_1Socket_ac44f6ae3196a8a3e09a6a85fcf495762}{set\+Descriptor} (int descriptor)
\begin{DoxyCompactList}\small\item\em Set the descriptor for the socket. \end{DoxyCompactList}\item
\mbox{\Hypertarget{classcore_1_1Socket_a06ba54744530439d4131e6aba4623d08}\label{classcore_1_1Socket_a06ba54744530439d4131e6aba4623d08}}
int \hyperlink{classcore_1_1Socket_a06ba54744530439d4131e6aba4623d08}{get\+Descriptor} ()
\begin{DoxyCompactList}\small\item\em Get the descriptor for the socket. \end{DoxyCompactList}\item
bool \hyperlink{classcore_1_1Socket_a4c9a3396693ff919eb827729f9e72b03}{event\+Received} (struct epoll\+\_\+event event)
\begin{DoxyCompactList}\small\item\em Parse epoll event and call specified callbacks. \end{DoxyCompactList}\item
int \hyperlink{classcore_1_1Socket_a1413c826307ef0f29d7457770af675e3}{write} (std\+::string data)
\item
\mbox{\Hypertarget{classcore_1_1Socket_a4855594af113428eacdaa7448d661121}\label{classcore_1_1Socket_a4855594af113428eacdaa7448d661121}}
void {\bfseries write} (char $\ast$buffer, int length)
\item
\mbox{\Hypertarget{classcore_1_1Socket_ad67b0f95127bd987b98323120f40f6ed}\label{classcore_1_1Socket_ad67b0f95127bd987b98323120f40f6ed}}
void {\bfseries output} (std\+::stringstream \&out)
\item
virtual void \hyperlink{classcore_1_1Socket_a81e5ee3e17834166d97c6e8b7dfe0da0}{on\+Register} ()
\begin{DoxyCompactList}\small\item\em Called when the socket has finished registering with the epoll processing. \end{DoxyCompactList}\item
\mbox{\Hypertarget{classcore_1_1Socket_a23b9824653bbe4652a716acb828665b1}\label{classcore_1_1Socket_a23b9824653bbe4652a716acb828665b1}}
virtual void {\bfseries on\+Registered} ()
\item
virtual void \hyperlink{classcore_1_1Socket_aa1d380db54a5b2efbc859e3744bd898b}{on\+Unregister} ()
\begin{DoxyCompactList}\small\item\em Called when the socket has finished unregistering for the epoll processing. \end{DoxyCompactList}\item
\mbox{\Hypertarget{classcore_1_1Socket_a43247bfe43c2be5ab3863d9057d46b7c}\label{classcore_1_1Socket_a43247bfe43c2be5ab3863d9057d46b7c}}
bool {\bfseries needs\+To\+Write} ()
\end{DoxyCompactItemize}
\subsection*{Public Attributes}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classcore_1_1Socket_a26ce6667b1d883e7a77fcd46ead03f6b}\label{classcore_1_1Socket_a26ce6667b1d883e7a77fcd46ead03f6b}}
\begin{tabbing}
xx\=xx\=xx\=xx\=xx\=xx\=xx\=xx\=xx\=\kill
class \{\\
\} {\bfseries bufferSize}\\
\end{tabbing}\item
\mbox{\Hypertarget{classcore_1_1Socket_addc8b96547fb9cc921f9fb0e398d4882}\label{classcore_1_1Socket_addc8b96547fb9cc921f9fb0e398d4882}}
bool {\bfseries active} = false
\end{DoxyCompactItemize}
\subsection*{Protected Member Functions}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classcore_1_1Socket_a71c77a162698b9c074a7497beab7b5d8}\label{classcore_1_1Socket_a71c77a162698b9c074a7497beab7b5d8}}
void {\bfseries set\+Buffer\+Size} (int length)
\item
virtual void \hyperlink{classcore_1_1Socket_ac8d6a2c54696eb6fc2024cf6bcf6b4e5}{on\+Data\+Received} (std\+::string data)
\begin{DoxyCompactList}\small\item\em Called when data is received from the socket. \end{DoxyCompactList}\item
\mbox{\Hypertarget{classcore_1_1Socket_af6c06db2441633ae9979affe72930abc}\label{classcore_1_1Socket_af6c06db2441633ae9979affe72930abc}}
virtual void {\bfseries on\+Data\+Received} (char $\ast$buffer, int len)
\item
virtual void \hyperlink{classcore_1_1Socket_af455ec6f793473f529507af26aa54695}{receive\+Data} (char $\ast$buffer, int buffer\+Length)
\end{DoxyCompactItemize}
\subsection*{Protected Attributes}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classcore_1_1Socket_a3b0b139ac7da581f0d969f6ae9a0c97c}\label{classcore_1_1Socket_a3b0b139ac7da581f0d969f6ae9a0c97c}}
\hyperlink{classcore_1_1EPoll}{E\+Poll} \& {\bfseries e\+Poll}
\item
\mbox{\Hypertarget{classcore_1_1Socket_aa09db6c6298d20ea76c6e65f8bffd3dc}\label{classcore_1_1Socket_aa09db6c6298d20ea76c6e65f8bffd3dc}}
bool {\bfseries shut\+Down} = false
\end{DoxyCompactItemize}
\subsection{Detailed Description}
\hyperlink{classcore_1_1Socket}{Socket}
The core component to managing a socket.
Hooks into the \hyperlink{classcore_1_1EPoll}{E\+Poll} through the registration and unregistration process and provides a communication socket of the specified protocol type. This object provides for all receiving data threading through use of the \hyperlink{classcore_1_1EPoll}{E\+Poll} object and also provides buffering for output data requests to the socket.
A program using a socket object can request to open a socket (file or network or whatever) and communicate through the streambuffer interface of the socket object.
The socket side of the \hyperlink{classcore_1_1Socket}{Socket} accepts E\+P\+O\+L\+L\+IN event and will maintain the data in a buffer for the stream readers to read. A on\+Data\+Received event is then sent with the data received in the buffer that can be read through the stream.
When writing to the stream the data is written into a buffer and a E\+P\+O\+L\+L\+O\+UT is scheduled. Upon receiving the E\+P\+O\+L\+L\+O\+UT event then the buffer is written to the socket output.
\subsection{Member Function Documentation}
\mbox{\Hypertarget{classcore_1_1Socket_a4c9a3396693ff919eb827729f9e72b03}\label{classcore_1_1Socket_a4c9a3396693ff919eb827729f9e72b03}}
\index{core\+::\+Socket@{core\+::\+Socket}!event\+Received@{event\+Received}}
\index{event\+Received@{event\+Received}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{event\+Received()}{eventReceived()}}
{\footnotesize\ttfamily bool core\+::\+Socket\+::event\+Received (\begin{DoxyParamCaption}\item[{struct epoll\+\_\+event}]{event }\end{DoxyParamCaption})}
Parse epoll event and call specified callbacks.
The event received from epoll is sent through the event\+Received method which will parse the event and call the read and write callbacks on the socket.
This method is called by the B\+M\+A\+E\+Poll object and should not be called from any user extended classes unless an epoll event is being simulated. \mbox{\Hypertarget{classcore_1_1Socket_ac8d6a2c54696eb6fc2024cf6bcf6b4e5}\label{classcore_1_1Socket_ac8d6a2c54696eb6fc2024cf6bcf6b4e5}}
\index{core\+::\+Socket@{core\+::\+Socket}!on\+Data\+Received@{on\+Data\+Received}}
\index{on\+Data\+Received@{on\+Data\+Received}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{on\+Data\+Received()}{onDataReceived()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::on\+Data\+Received (\begin{DoxyParamCaption}\item[{std\+::string}]{data }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [protected]}, {\ttfamily [virtual]}}
Called when data is received from the socket.
The on\+Connected method is called when the socket is ready to communicate. Writing to the socket can begin on this call to initiate a contact with the remote device. The on\+Data\+Received method is called when the socket has received an event from epoll and there is data ready to be read from the socket. The default handler will pull the data and put it into the streambuf for the socket. E\+P\+O\+L\+L\+IN
\begin{DoxyParams}{Parameters}
{\em data} & the data that has been received from the socket. \\
\hline
\end{DoxyParams}
Reimplemented in \hyperlink{classcore_1_1TCPServer_a276ccbc8cb9b4380ebd78807b97f0159}{core\+::\+T\+C\+P\+Server}, \hyperlink{classcore_1_1TCPSession_aa87aca65cece02a107e7c288a925271f}{core\+::\+T\+C\+P\+Session}, and \hyperlink{classcore_1_1UDPServerSocket_a41933ca153c854a800e3d047ab18313e}{core\+::\+U\+D\+P\+Server\+Socket}.
\mbox{\Hypertarget{classcore_1_1Socket_a81e5ee3e17834166d97c6e8b7dfe0da0}\label{classcore_1_1Socket_a81e5ee3e17834166d97c6e8b7dfe0da0}}
\index{core\+::\+Socket@{core\+::\+Socket}!on\+Register@{on\+Register}}
\index{on\+Register@{on\+Register}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{on\+Register()}{onRegister()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::on\+Register (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}
Called when the socket has finished registering with the epoll processing.
The on\+Register method is called before the socket is registered with e\+Poll so objects extending the \hyperlink{classcore_1_1Socket}{Socket} definition can initialize the socket before receiving events. Evoked when the descriptor is set using set\+Descriptor for the socket.
Reimplemented in \hyperlink{classcore_1_1TCPSession_a77600a18d75f1efee00b3dc626b1e98b}{core\+::\+T\+C\+P\+Session}, and \hyperlink{classcore_1_1TLSSession_a76cec7cf4851eb27abe77a2339344c6d}{core\+::\+T\+L\+S\+Session}.
\mbox{\Hypertarget{classcore_1_1Socket_aa1d380db54a5b2efbc859e3744bd898b}\label{classcore_1_1Socket_aa1d380db54a5b2efbc859e3744bd898b}}
\index{core\+::\+Socket@{core\+::\+Socket}!on\+Unregister@{on\+Unregister}}
\index{on\+Unregister@{on\+Unregister}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{on\+Unregister()}{onUnregister()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::on\+Unregister (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}
Called when the socket has finished unregistering for the epoll processing.
The on\+Unregister method is called whenever the socket is unregistered with e\+Poll and socket communcation events will be stopped. The default method will close the socket and clean up the connection. If this is overridden by an extended object then the object should call this method to clean the socket up. \mbox{\Hypertarget{classcore_1_1Socket_af455ec6f793473f529507af26aa54695}\label{classcore_1_1Socket_af455ec6f793473f529507af26aa54695}}
\index{core\+::\+Socket@{core\+::\+Socket}!receive\+Data@{receive\+Data}}
\index{receive\+Data@{receive\+Data}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{receive\+Data()}{receiveData()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::receive\+Data (\begin{DoxyParamCaption}\item[{char $\ast$}]{buffer, }\item[{int}]{buffer\+Length }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [protected]}, {\ttfamily [virtual]}}
receive\+Data will read the data from the socket and place it in the socket buffer. T\+LS layer overrides this to be able to read from S\+SL.
Reimplemented in \hyperlink{classcore_1_1TLSSession_a1822cb21de545dc1a183ec0bac6cc4f0}{core\+::\+T\+L\+S\+Session}.
\mbox{\Hypertarget{classcore_1_1Socket_ac44f6ae3196a8a3e09a6a85fcf495762}\label{classcore_1_1Socket_ac44f6ae3196a8a3e09a6a85fcf495762}}
\index{core\+::\+Socket@{core\+::\+Socket}!set\+Descriptor@{set\+Descriptor}}
\index{set\+Descriptor@{set\+Descriptor}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{set\+Descriptor()}{setDescriptor()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::set\+Descriptor (\begin{DoxyParamCaption}\item[{int}]{descriptor }\end{DoxyParamCaption})}
Set the descriptor for the socket.
set\+Descriptor establishes the file descriptor for the socket and registers the socket on the \hyperlink{classcore_1_1EPoll}{E\+Poll} controller. set\+Descriptor will invoke the \hyperlink{classcore_1_1Socket_a81e5ee3e17834166d97c6e8b7dfe0da0}{on\+Register()} event. \mbox{\Hypertarget{classcore_1_1Socket_af2d1b6de7a64a9d446b0305b6ec47b31}\label{classcore_1_1Socket_af2d1b6de7a64a9d446b0305b6ec47b31}}
\index{core\+::\+Socket@{core\+::\+Socket}!shutdown@{shutdown}}
\index{shutdown@{shutdown}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{shutdown()}{shutdown()}}
{\footnotesize\ttfamily void core\+::\+Socket\+::shutdown (\begin{DoxyParamCaption}\item[{std\+::string}]{text = {\ttfamily \char`\"{}unknown\char`\"{}} }\end{DoxyParamCaption})}
Use the \hyperlink{classcore_1_1Socket_af2d1b6de7a64a9d446b0305b6ec47b31}{shutdown()} method to terminate the socket connection and remove resources. This method is provided to ensure that all destructors are called for all inherited objects without a virtual destructor. \mbox{\Hypertarget{classcore_1_1Socket_a1413c826307ef0f29d7457770af675e3}\label{classcore_1_1Socket_a1413c826307ef0f29d7457770af675e3}}
\index{core\+::\+Socket@{core\+::\+Socket}!write@{write}}
\index{write@{write}!core\+::\+Socket@{core\+::\+Socket}}
\subsubsection{\texorpdfstring{write()}{write()}}
{\footnotesize\ttfamily int core\+::\+Socket\+::write (\begin{DoxyParamCaption}\item[{std\+::string}]{data }\end{DoxyParamCaption})}
Write data to the socket.
The documentation for this class was generated from the following files\+:\begin{DoxyCompactItemize}
\item
Socket.\+h\item
Socket.\+cpp\end{DoxyCompactItemize}