group__sock-adopt.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.11"/>
  7. <title>libwebsockets: Socket adoption helpers</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="resize.js"></script>
  13. <script type="text/javascript" src="navtreedata.js"></script>
  14. <script type="text/javascript" src="navtree.js"></script>
  15. <script type="text/javascript">
  16. $(document).ready(initResizable);
  17. $(window).load(resizeHeight);
  18. </script>
  19. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  20. </head>
  21. <body>
  22. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  23. <div id="titlearea">
  24. <table cellspacing="0" cellpadding="0">
  25. <tbody>
  26. <tr style="height: 56px;">
  27. <td id="projectlogo"><img alt="Logo" src="libwebsockets.org-logo.png"/></td>
  28. <td id="projectalign" style="padding-left: 0.5em;">
  29. <div id="projectname">libwebsockets
  30. </div>
  31. <div id="projectbrief">Lightweight C library for HTML5 websockets</div>
  32. </td>
  33. </tr>
  34. </tbody>
  35. </table>
  36. </div>
  37. <!-- end header part -->
  38. <!-- Generated by Doxygen 1.8.11 -->
  39. <div id="navrow1" class="tabs">
  40. <ul class="tablist">
  41. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  42. <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  43. <li class="current"><a href="modules.html"><span>Modules</span></a></li>
  44. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  45. <li><a href="files.html"><span>Files</span></a></li>
  46. </ul>
  47. </div>
  48. </div><!-- top -->
  49. <div id="side-nav" class="ui-resizable side-nav-resizable">
  50. <div id="nav-tree">
  51. <div id="nav-tree-contents">
  52. <div id="nav-sync" class="sync"></div>
  53. </div>
  54. </div>
  55. <div id="splitbar" style="-moz-user-select:none;"
  56. class="ui-resizable-handle">
  57. </div>
  58. </div>
  59. <script type="text/javascript">
  60. $(document).ready(function(){initNavTree('group__sock-adopt.html','');});
  61. </script>
  62. <div id="doc-content">
  63. <div class="header">
  64. <div class="summary">
  65. <a href="#func-members">Functions</a> </div>
  66. <div class="headertitle">
  67. <div class="title">Socket adoption helpers</div> </div>
  68. </div><!--header-->
  69. <div class="contents">
  70. <table class="memberdecls">
  71. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
  72. Functions</h2></td></tr>
  73. <tr class="memitem:gabe71b7462afb21c767bdc67334f305af"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN struct lws *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket</a> (struct lws_context *context, lws_sockfd_type accept_fd)</td></tr>
  74. <tr class="separator:gabe71b7462afb21c767bdc67334f305af"><td class="memSeparator" colspan="2">&#160;</td></tr>
  75. <tr class="memitem:gab2d045df0f81afe00891aaed312d552b"><td class="memItemLeft" align="right" valign="top">LWS_VISIBLE LWS_EXTERN struct lws *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__sock-adopt.html#gab2d045df0f81afe00891aaed312d552b">lws_adopt_socket_readbuf</a> (struct lws_context *context, lws_sockfd_type accept_fd, const char *readbuf, size_t len)</td></tr>
  76. <tr class="separator:gab2d045df0f81afe00891aaed312d552b"><td class="memSeparator" colspan="2">&#160;</td></tr>
  77. </table>
  78. <a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
  79. <h2>Socket adoption helpers</h2>
  80. <p>When integrating with an external app with its own event loop, these can be used to accept connections from someone else's listening socket.</p>
  81. <p>When using lws own event loop, these are not needed. </p>
  82. <h2 class="groupheader">Function Documentation</h2>
  83. <a class="anchor" id="gabe71b7462afb21c767bdc67334f305af"></a>
  84. <div class="memitem">
  85. <div class="memproto">
  86. <table class="memname">
  87. <tr>
  88. <td class="memname">LWS_VISIBLE LWS_EXTERN struct lws* lws_adopt_socket </td>
  89. <td>(</td>
  90. <td class="paramtype">struct lws_context *&#160;</td>
  91. <td class="paramname"><em>context</em>, </td>
  92. </tr>
  93. <tr>
  94. <td class="paramkey"></td>
  95. <td></td>
  96. <td class="paramtype">lws_sockfd_type&#160;</td>
  97. <td class="paramname"><em>accept_fd</em>&#160;</td>
  98. </tr>
  99. <tr>
  100. <td></td>
  101. <td>)</td>
  102. <td></td><td></td>
  103. </tr>
  104. </table>
  105. </div><div class="memdoc">
  106. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  107. <p><a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket()</a> - adopt foreign socket as if listen socket accepted it </p><dl class="params"><dt>Parameters</dt><dd>
  108. <table class="params">
  109. <tr><td class="paramname">context</td><td>lws context </td></tr>
  110. <tr><td class="paramname">accept_fd</td><td>fd of already-accepted socket to adopt</td></tr>
  111. </table>
  112. </dd>
  113. </dl>
  114. <p>Either returns new wsi bound to accept_fd, or closes accept_fd and returns NULL, having cleaned up any new wsi pieces.</p>
  115. <p>LWS adopts the socket in http serving mode, it's ready to accept an upgrade to ws or just serve http. </p>
  116. </div>
  117. </div>
  118. <a class="anchor" id="gab2d045df0f81afe00891aaed312d552b"></a>
  119. <div class="memitem">
  120. <div class="memproto">
  121. <table class="memname">
  122. <tr>
  123. <td class="memname">LWS_VISIBLE LWS_EXTERN struct lws* lws_adopt_socket_readbuf </td>
  124. <td>(</td>
  125. <td class="paramtype">struct lws_context *&#160;</td>
  126. <td class="paramname"><em>context</em>, </td>
  127. </tr>
  128. <tr>
  129. <td class="paramkey"></td>
  130. <td></td>
  131. <td class="paramtype">lws_sockfd_type&#160;</td>
  132. <td class="paramname"><em>accept_fd</em>, </td>
  133. </tr>
  134. <tr>
  135. <td class="paramkey"></td>
  136. <td></td>
  137. <td class="paramtype">const char *&#160;</td>
  138. <td class="paramname"><em>readbuf</em>, </td>
  139. </tr>
  140. <tr>
  141. <td class="paramkey"></td>
  142. <td></td>
  143. <td class="paramtype">size_t&#160;</td>
  144. <td class="paramname"><em>len</em>&#160;</td>
  145. </tr>
  146. <tr>
  147. <td></td>
  148. <td>)</td>
  149. <td></td><td></td>
  150. </tr>
  151. </table>
  152. </div><div class="memdoc">
  153. <p><code>#include &lt;<a class="el" href="libwebsockets_8h.html">lib/libwebsockets.h</a>&gt;</code></p>
  154. <p><a class="el" href="group__sock-adopt.html#gab2d045df0f81afe00891aaed312d552b">lws_adopt_socket_readbuf()</a> - adopt foreign socket and first rx as if listen socket accepted it </p><dl class="params"><dt>Parameters</dt><dd>
  155. <table class="params">
  156. <tr><td class="paramname">context</td><td>lws context </td></tr>
  157. <tr><td class="paramname">accept_fd</td><td>fd of already-accepted socket to adopt </td></tr>
  158. <tr><td class="paramname">readbuf</td><td>NULL or pointer to data that must be drained before reading from accept_fd </td></tr>
  159. <tr><td class="paramname">len</td><td>The length of the data held at </td></tr>
  160. <tr><td class="paramname">readbuf</td><td>Either returns new wsi bound to accept_fd, or closes accept_fd and returns NULL, having cleaned up any new wsi pieces.</td></tr>
  161. </table>
  162. </dd>
  163. </dl>
  164. <p>LWS adopts the socket in http serving mode, it's ready to accept an upgrade to ws or just serve http.</p>
  165. <p>If your external code did not already read from the socket, you can use <a class="el" href="group__sock-adopt.html#gabe71b7462afb21c767bdc67334f305af">lws_adopt_socket()</a> instead.</p>
  166. <p>This api is guaranteed to use the data at </p><dl class="params"><dt>Parameters</dt><dd>
  167. <table class="params">
  168. <tr><td class="paramname">readbuf</td><td>first, before reading from the socket.</td></tr>
  169. </table>
  170. </dd>
  171. </dl>
  172. <p>readbuf is limited to the size of the ah rx buf, currently 2048 bytes. </p>
  173. </div>
  174. </div>
  175. </div><!-- contents -->
  176. </div><!-- doc-content -->
  177. <!-- start footer part -->
  178. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  179. <ul>
  180. <li class="footer">Generated by
  181. <a href="http://www.doxygen.org/index.html">
  182. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  183. </ul>
  184. </div>
  185. </body>
  186. </html>