mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-23 00:00:06 +01:00
77 lines
No EOL
4.9 KiB
TeX
77 lines
No EOL
4.9 KiB
TeX
\hypertarget{group__sock-adopt}{}\section{Socket adoption helpers}
|
|
\label{group__sock-adopt}\index{Socket adoption helpers@{Socket adoption helpers}}
|
|
\subsection*{Functions}
|
|
\begin{DoxyCompactItemize}
|
|
\item
|
|
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws $\ast$ \hyperlink{group__sock-adopt_gabe71b7462afb21c767bdc67334f305af}{lws\+\_\+adopt\+\_\+socket} (struct lws\+\_\+context $\ast$context, lws\+\_\+sockfd\+\_\+type accept\+\_\+fd)
|
|
\item
|
|
L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws $\ast$ \hyperlink{group__sock-adopt_gab2d045df0f81afe00891aaed312d552b}{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf} (struct lws\+\_\+context $\ast$context, lws\+\_\+sockfd\+\_\+type accept\+\_\+fd, const char $\ast$readbuf, size\+\_\+t len)
|
|
\end{DoxyCompactItemize}
|
|
|
|
|
|
\subsection{Detailed Description}
|
|
\subsubsection*{Socket adoption helpers}
|
|
|
|
When integrating with an external app with its own event loop, these can be used to accept connections from someone else\textquotesingle{}s listening socket.
|
|
|
|
When using lws own event loop, these are not needed.
|
|
|
|
\subsection{Function Documentation}
|
|
\index{Socket adoption helpers@{Socket adoption helpers}!lws\+\_\+adopt\+\_\+socket@{lws\+\_\+adopt\+\_\+socket}}
|
|
\index{lws\+\_\+adopt\+\_\+socket@{lws\+\_\+adopt\+\_\+socket}!Socket adoption helpers@{Socket adoption helpers}}
|
|
\subsubsection[{\texorpdfstring{lws\+\_\+adopt\+\_\+socket(struct lws\+\_\+context $\ast$context, lws\+\_\+sockfd\+\_\+type accept\+\_\+fd)}{lws\_adopt\_socket(struct lws\_context *context, lws\_sockfd\_type accept\_fd)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws$\ast$ lws\+\_\+adopt\+\_\+socket (
|
|
\begin{DoxyParamCaption}
|
|
\item[{struct lws\+\_\+context $\ast$}]{context, }
|
|
\item[{lws\+\_\+sockfd\+\_\+type}]{accept\+\_\+fd}
|
|
\end{DoxyParamCaption}
|
|
)}\hypertarget{group__sock-adopt_gabe71b7462afb21c767bdc67334f305af}{}\label{group__sock-adopt_gabe71b7462afb21c767bdc67334f305af}
|
|
|
|
|
|
{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}
|
|
|
|
\hyperlink{group__sock-adopt_gabe71b7462afb21c767bdc67334f305af}{lws\+\_\+adopt\+\_\+socket()} -\/ adopt foreign socket as if listen socket accepted it
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em context} & lws context \\
|
|
\hline
|
|
{\em accept\+\_\+fd} & fd of already-\/accepted socket to adopt\\
|
|
\hline
|
|
\end{DoxyParams}
|
|
Either returns new wsi bound to accept\+\_\+fd, or closes accept\+\_\+fd and returns N\+U\+LL, having cleaned up any new wsi pieces.
|
|
|
|
L\+WS adopts the socket in http serving mode, it\textquotesingle{}s ready to accept an upgrade to ws or just serve http. \index{Socket adoption helpers@{Socket adoption helpers}!lws\+\_\+adopt\+\_\+socket\+\_\+readbuf@{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf}}
|
|
\index{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf@{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf}!Socket adoption helpers@{Socket adoption helpers}}
|
|
\subsubsection[{\texorpdfstring{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf(struct lws\+\_\+context $\ast$context, lws\+\_\+sockfd\+\_\+type accept\+\_\+fd, const char $\ast$readbuf, size\+\_\+t len)}{lws\_adopt\_socket\_readbuf(struct lws\_context *context, lws\_sockfd\_type accept\_fd, const char *readbuf, size\_t len)}}]{\setlength{\rightskip}{0pt plus 5cm}L\+W\+S\+\_\+\+V\+I\+S\+I\+B\+LE L\+W\+S\+\_\+\+E\+X\+T\+E\+RN struct lws$\ast$ lws\+\_\+adopt\+\_\+socket\+\_\+readbuf (
|
|
\begin{DoxyParamCaption}
|
|
\item[{struct lws\+\_\+context $\ast$}]{context, }
|
|
\item[{lws\+\_\+sockfd\+\_\+type}]{accept\+\_\+fd, }
|
|
\item[{const char $\ast$}]{readbuf, }
|
|
\item[{size\+\_\+t}]{len}
|
|
\end{DoxyParamCaption}
|
|
)}\hypertarget{group__sock-adopt_gab2d045df0f81afe00891aaed312d552b}{}\label{group__sock-adopt_gab2d045df0f81afe00891aaed312d552b}
|
|
|
|
|
|
{\ttfamily \#include $<$\hyperlink{libwebsockets_8h}{lib/libwebsockets.\+h}$>$}
|
|
|
|
\hyperlink{group__sock-adopt_gab2d045df0f81afe00891aaed312d552b}{lws\+\_\+adopt\+\_\+socket\+\_\+readbuf()} -\/ adopt foreign socket and first rx as if listen socket accepted it
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em context} & lws context \\
|
|
\hline
|
|
{\em accept\+\_\+fd} & fd of already-\/accepted socket to adopt \\
|
|
\hline
|
|
{\em readbuf} & N\+U\+LL or pointer to data that must be drained before reading from accept\+\_\+fd \\
|
|
\hline
|
|
{\em len} & The length of the data held at \\
|
|
\hline
|
|
{\em readbuf} & Either returns new wsi bound to accept\+\_\+fd, or closes accept\+\_\+fd and returns N\+U\+LL, having cleaned up any new wsi pieces.\\
|
|
\hline
|
|
\end{DoxyParams}
|
|
L\+WS adopts the socket in http serving mode, it\textquotesingle{}s ready to accept an upgrade to ws or just serve http.
|
|
|
|
If your external code did not already read from the socket, you can use \hyperlink{group__sock-adopt_gabe71b7462afb21c767bdc67334f305af}{lws\+\_\+adopt\+\_\+socket()} instead.
|
|
|
|
This api is guaranteed to use the data at
|
|
\begin{DoxyParams}{Parameters}
|
|
{\em readbuf} & first, before reading from the socket.\\
|
|
\hline
|
|
\end{DoxyParams}
|
|
readbuf is limited to the size of the ah rx buf, currently 2048 bytes. |