basic_socket_acceptor.hpp 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. //
  2. // basic_socket_acceptor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP
  11. #define BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/basic_socket.hpp>
  17. #include <boost/asio/detail/handler_type_requirements.hpp>
  18. #include <boost/asio/detail/io_object_impl.hpp>
  19. #include <boost/asio/detail/non_const_lvalue.hpp>
  20. #include <boost/asio/detail/throw_error.hpp>
  21. #include <boost/asio/detail/type_traits.hpp>
  22. #include <boost/asio/error.hpp>
  23. #include <boost/asio/execution_context.hpp>
  24. #include <boost/asio/executor.hpp>
  25. #include <boost/asio/socket_base.hpp>
  26. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  27. # include <boost/asio/detail/null_socket_service.hpp>
  28. #elif defined(BOOST_ASIO_HAS_IOCP)
  29. # include <boost/asio/detail/win_iocp_socket_service.hpp>
  30. #else
  31. # include <boost/asio/detail/reactive_socket_service.hpp>
  32. #endif
  33. #if defined(BOOST_ASIO_HAS_MOVE)
  34. # include <utility>
  35. #endif // defined(BOOST_ASIO_HAS_MOVE)
  36. #include <boost/asio/detail/push_options.hpp>
  37. namespace boost {
  38. namespace asio {
  39. #if !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL)
  40. #define BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL
  41. // Forward declaration with defaulted arguments.
  42. template <typename Protocol, typename Executor = executor>
  43. class basic_socket_acceptor;
  44. #endif // !defined(BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_FWD_DECL)
  45. /// Provides the ability to accept new connections.
  46. /**
  47. * The basic_socket_acceptor class template is used for accepting new socket
  48. * connections.
  49. *
  50. * @par Thread Safety
  51. * @e Distinct @e objects: Safe.@n
  52. * @e Shared @e objects: Unsafe.
  53. *
  54. * @par Example
  55. * Opening a socket acceptor with the SO_REUSEADDR option enabled:
  56. * @code
  57. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  58. * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
  59. * acceptor.open(endpoint.protocol());
  60. * acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
  61. * acceptor.bind(endpoint);
  62. * acceptor.listen();
  63. * @endcode
  64. */
  65. template <typename Protocol, typename Executor>
  66. class basic_socket_acceptor
  67. : public socket_base
  68. {
  69. public:
  70. /// The type of the executor associated with the object.
  71. typedef Executor executor_type;
  72. /// The native representation of an acceptor.
  73. #if defined(GENERATING_DOCUMENTATION)
  74. typedef implementation_defined native_handle_type;
  75. #elif defined(BOOST_ASIO_WINDOWS_RUNTIME)
  76. typedef typename detail::null_socket_service<
  77. Protocol>::native_handle_type native_handle_type;
  78. #elif defined(BOOST_ASIO_HAS_IOCP)
  79. typedef typename detail::win_iocp_socket_service<
  80. Protocol>::native_handle_type native_handle_type;
  81. #else
  82. typedef typename detail::reactive_socket_service<
  83. Protocol>::native_handle_type native_handle_type;
  84. #endif
  85. /// The protocol type.
  86. typedef Protocol protocol_type;
  87. /// The endpoint type.
  88. typedef typename Protocol::endpoint endpoint_type;
  89. /// Construct an acceptor without opening it.
  90. /**
  91. * This constructor creates an acceptor without opening it to listen for new
  92. * connections. The open() function must be called before the acceptor can
  93. * accept new socket connections.
  94. *
  95. * @param ex The I/O executor that the acceptor will use, by default, to
  96. * dispatch handlers for any asynchronous operations performed on the
  97. * acceptor.
  98. */
  99. explicit basic_socket_acceptor(const executor_type& ex)
  100. : impl_(ex)
  101. {
  102. }
  103. /// Construct an acceptor without opening it.
  104. /**
  105. * This constructor creates an acceptor without opening it to listen for new
  106. * connections. The open() function must be called before the acceptor can
  107. * accept new socket connections.
  108. *
  109. * @param context An execution context which provides the I/O executor that
  110. * the acceptor will use, by default, to dispatch handlers for any
  111. * asynchronous operations performed on the acceptor.
  112. */
  113. template <typename ExecutionContext>
  114. explicit basic_socket_acceptor(ExecutionContext& context,
  115. typename enable_if<
  116. is_convertible<ExecutionContext&, execution_context&>::value
  117. >::type* = 0)
  118. : impl_(context)
  119. {
  120. }
  121. /// Construct an open acceptor.
  122. /**
  123. * This constructor creates an acceptor and automatically opens it.
  124. *
  125. * @param ex The I/O executor that the acceptor will use, by default, to
  126. * dispatch handlers for any asynchronous operations performed on the
  127. * acceptor.
  128. *
  129. * @param protocol An object specifying protocol parameters to be used.
  130. *
  131. * @throws boost::system::system_error Thrown on failure.
  132. */
  133. basic_socket_acceptor(const executor_type& ex, const protocol_type& protocol)
  134. : impl_(ex)
  135. {
  136. boost::system::error_code ec;
  137. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  138. boost::asio::detail::throw_error(ec, "open");
  139. }
  140. /// Construct an open acceptor.
  141. /**
  142. * This constructor creates an acceptor and automatically opens it.
  143. *
  144. * @param context An execution context which provides the I/O executor that
  145. * the acceptor will use, by default, to dispatch handlers for any
  146. * asynchronous operations performed on the acceptor.
  147. *
  148. * @param protocol An object specifying protocol parameters to be used.
  149. *
  150. * @throws boost::system::system_error Thrown on failure.
  151. */
  152. template <typename ExecutionContext>
  153. basic_socket_acceptor(ExecutionContext& context,
  154. const protocol_type& protocol,
  155. typename enable_if<
  156. is_convertible<ExecutionContext&, execution_context&>::value
  157. >::type* = 0)
  158. : impl_(context)
  159. {
  160. boost::system::error_code ec;
  161. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  162. boost::asio::detail::throw_error(ec, "open");
  163. }
  164. /// Construct an acceptor opened on the given endpoint.
  165. /**
  166. * This constructor creates an acceptor and automatically opens it to listen
  167. * for new connections on the specified endpoint.
  168. *
  169. * @param ex The I/O executor that the acceptor will use, by default, to
  170. * dispatch handlers for any asynchronous operations performed on the
  171. * acceptor.
  172. *
  173. * @param endpoint An endpoint on the local machine on which the acceptor
  174. * will listen for new connections.
  175. *
  176. * @param reuse_addr Whether the constructor should set the socket option
  177. * socket_base::reuse_address.
  178. *
  179. * @throws boost::system::system_error Thrown on failure.
  180. *
  181. * @note This constructor is equivalent to the following code:
  182. * @code
  183. * basic_socket_acceptor<Protocol> acceptor(my_context);
  184. * acceptor.open(endpoint.protocol());
  185. * if (reuse_addr)
  186. * acceptor.set_option(socket_base::reuse_address(true));
  187. * acceptor.bind(endpoint);
  188. * acceptor.listen();
  189. * @endcode
  190. */
  191. basic_socket_acceptor(const executor_type& ex,
  192. const endpoint_type& endpoint, bool reuse_addr = true)
  193. : impl_(ex)
  194. {
  195. boost::system::error_code ec;
  196. const protocol_type protocol = endpoint.protocol();
  197. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  198. boost::asio::detail::throw_error(ec, "open");
  199. if (reuse_addr)
  200. {
  201. impl_.get_service().set_option(impl_.get_implementation(),
  202. socket_base::reuse_address(true), ec);
  203. boost::asio::detail::throw_error(ec, "set_option");
  204. }
  205. impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
  206. boost::asio::detail::throw_error(ec, "bind");
  207. impl_.get_service().listen(impl_.get_implementation(),
  208. socket_base::max_listen_connections, ec);
  209. boost::asio::detail::throw_error(ec, "listen");
  210. }
  211. /// Construct an acceptor opened on the given endpoint.
  212. /**
  213. * This constructor creates an acceptor and automatically opens it to listen
  214. * for new connections on the specified endpoint.
  215. *
  216. * @param context An execution context which provides the I/O executor that
  217. * the acceptor will use, by default, to dispatch handlers for any
  218. * asynchronous operations performed on the acceptor.
  219. *
  220. * @param endpoint An endpoint on the local machine on which the acceptor
  221. * will listen for new connections.
  222. *
  223. * @param reuse_addr Whether the constructor should set the socket option
  224. * socket_base::reuse_address.
  225. *
  226. * @throws boost::system::system_error Thrown on failure.
  227. *
  228. * @note This constructor is equivalent to the following code:
  229. * @code
  230. * basic_socket_acceptor<Protocol> acceptor(my_context);
  231. * acceptor.open(endpoint.protocol());
  232. * if (reuse_addr)
  233. * acceptor.set_option(socket_base::reuse_address(true));
  234. * acceptor.bind(endpoint);
  235. * acceptor.listen();
  236. * @endcode
  237. */
  238. template <typename ExecutionContext>
  239. basic_socket_acceptor(ExecutionContext& context,
  240. const endpoint_type& endpoint, bool reuse_addr = true,
  241. typename enable_if<
  242. is_convertible<ExecutionContext&, execution_context&>::value
  243. >::type* = 0)
  244. : impl_(context)
  245. {
  246. boost::system::error_code ec;
  247. const protocol_type protocol = endpoint.protocol();
  248. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  249. boost::asio::detail::throw_error(ec, "open");
  250. if (reuse_addr)
  251. {
  252. impl_.get_service().set_option(impl_.get_implementation(),
  253. socket_base::reuse_address(true), ec);
  254. boost::asio::detail::throw_error(ec, "set_option");
  255. }
  256. impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
  257. boost::asio::detail::throw_error(ec, "bind");
  258. impl_.get_service().listen(impl_.get_implementation(),
  259. socket_base::max_listen_connections, ec);
  260. boost::asio::detail::throw_error(ec, "listen");
  261. }
  262. /// Construct a basic_socket_acceptor on an existing native acceptor.
  263. /**
  264. * This constructor creates an acceptor object to hold an existing native
  265. * acceptor.
  266. *
  267. * @param ex The I/O executor that the acceptor will use, by default, to
  268. * dispatch handlers for any asynchronous operations performed on the
  269. * acceptor.
  270. *
  271. * @param protocol An object specifying protocol parameters to be used.
  272. *
  273. * @param native_acceptor A native acceptor.
  274. *
  275. * @throws boost::system::system_error Thrown on failure.
  276. */
  277. basic_socket_acceptor(const executor_type& ex,
  278. const protocol_type& protocol, const native_handle_type& native_acceptor)
  279. : impl_(ex)
  280. {
  281. boost::system::error_code ec;
  282. impl_.get_service().assign(impl_.get_implementation(),
  283. protocol, native_acceptor, ec);
  284. boost::asio::detail::throw_error(ec, "assign");
  285. }
  286. /// Construct a basic_socket_acceptor on an existing native acceptor.
  287. /**
  288. * This constructor creates an acceptor object to hold an existing native
  289. * acceptor.
  290. *
  291. * @param context An execution context which provides the I/O executor that
  292. * the acceptor will use, by default, to dispatch handlers for any
  293. * asynchronous operations performed on the acceptor.
  294. *
  295. * @param protocol An object specifying protocol parameters to be used.
  296. *
  297. * @param native_acceptor A native acceptor.
  298. *
  299. * @throws boost::system::system_error Thrown on failure.
  300. */
  301. template <typename ExecutionContext>
  302. basic_socket_acceptor(ExecutionContext& context,
  303. const protocol_type& protocol, const native_handle_type& native_acceptor,
  304. typename enable_if<
  305. is_convertible<ExecutionContext&, execution_context&>::value
  306. >::type* = 0)
  307. : impl_(context)
  308. {
  309. boost::system::error_code ec;
  310. impl_.get_service().assign(impl_.get_implementation(),
  311. protocol, native_acceptor, ec);
  312. boost::asio::detail::throw_error(ec, "assign");
  313. }
  314. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  315. /// Move-construct a basic_socket_acceptor from another.
  316. /**
  317. * This constructor moves an acceptor from one object to another.
  318. *
  319. * @param other The other basic_socket_acceptor object from which the move
  320. * will occur.
  321. *
  322. * @note Following the move, the moved-from object is in the same state as if
  323. * constructed using the @c basic_socket_acceptor(const executor_type&)
  324. * constructor.
  325. */
  326. basic_socket_acceptor(basic_socket_acceptor&& other)
  327. : impl_(std::move(other.impl_))
  328. {
  329. }
  330. /// Move-assign a basic_socket_acceptor from another.
  331. /**
  332. * This assignment operator moves an acceptor from one object to another.
  333. *
  334. * @param other The other basic_socket_acceptor object from which the move
  335. * will occur.
  336. *
  337. * @note Following the move, the moved-from object is in the same state as if
  338. * constructed using the @c basic_socket_acceptor(const executor_type&)
  339. * constructor.
  340. */
  341. basic_socket_acceptor& operator=(basic_socket_acceptor&& other)
  342. {
  343. impl_ = std::move(other.impl_);
  344. return *this;
  345. }
  346. // All socket acceptors have access to each other's implementations.
  347. template <typename Protocol1, typename Executor1>
  348. friend class basic_socket_acceptor;
  349. /// Move-construct a basic_socket_acceptor from an acceptor of another
  350. /// protocol type.
  351. /**
  352. * This constructor moves an acceptor from one object to another.
  353. *
  354. * @param other The other basic_socket_acceptor object from which the move
  355. * will occur.
  356. *
  357. * @note Following the move, the moved-from object is in the same state as if
  358. * constructed using the @c basic_socket_acceptor(const executor_type&)
  359. * constructor.
  360. */
  361. template <typename Protocol1, typename Executor1>
  362. basic_socket_acceptor(basic_socket_acceptor<Protocol1, Executor1>&& other,
  363. typename enable_if<
  364. is_convertible<Protocol1, Protocol>::value
  365. && is_convertible<Executor1, Executor>::value
  366. >::type* = 0)
  367. : impl_(std::move(other.impl_))
  368. {
  369. }
  370. /// Move-assign a basic_socket_acceptor from an acceptor of another protocol
  371. /// type.
  372. /**
  373. * This assignment operator moves an acceptor from one object to another.
  374. *
  375. * @param other The other basic_socket_acceptor object from which the move
  376. * will occur.
  377. *
  378. * @note Following the move, the moved-from object is in the same state as if
  379. * constructed using the @c basic_socket_acceptor(const executor_type&)
  380. * constructor.
  381. */
  382. template <typename Protocol1, typename Executor1>
  383. typename enable_if<
  384. is_convertible<Protocol1, Protocol>::value
  385. && is_convertible<Executor1, Executor>::value,
  386. basic_socket_acceptor&
  387. >::type operator=(basic_socket_acceptor<Protocol1, Executor1>&& other)
  388. {
  389. basic_socket_acceptor tmp(std::move(other));
  390. impl_ = std::move(tmp.impl_);
  391. return *this;
  392. }
  393. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  394. /// Destroys the acceptor.
  395. /**
  396. * This function destroys the acceptor, cancelling any outstanding
  397. * asynchronous operations associated with the acceptor as if by calling
  398. * @c cancel.
  399. */
  400. ~basic_socket_acceptor()
  401. {
  402. }
  403. /// Get the executor associated with the object.
  404. executor_type get_executor() BOOST_ASIO_NOEXCEPT
  405. {
  406. return impl_.get_executor();
  407. }
  408. /// Open the acceptor using the specified protocol.
  409. /**
  410. * This function opens the socket acceptor so that it will use the specified
  411. * protocol.
  412. *
  413. * @param protocol An object specifying which protocol is to be used.
  414. *
  415. * @throws boost::system::system_error Thrown on failure.
  416. *
  417. * @par Example
  418. * @code
  419. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  420. * acceptor.open(boost::asio::ip::tcp::v4());
  421. * @endcode
  422. */
  423. void open(const protocol_type& protocol = protocol_type())
  424. {
  425. boost::system::error_code ec;
  426. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  427. boost::asio::detail::throw_error(ec, "open");
  428. }
  429. /// Open the acceptor using the specified protocol.
  430. /**
  431. * This function opens the socket acceptor so that it will use the specified
  432. * protocol.
  433. *
  434. * @param protocol An object specifying which protocol is to be used.
  435. *
  436. * @param ec Set to indicate what error occurred, if any.
  437. *
  438. * @par Example
  439. * @code
  440. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  441. * boost::system::error_code ec;
  442. * acceptor.open(boost::asio::ip::tcp::v4(), ec);
  443. * if (ec)
  444. * {
  445. * // An error occurred.
  446. * }
  447. * @endcode
  448. */
  449. BOOST_ASIO_SYNC_OP_VOID open(const protocol_type& protocol,
  450. boost::system::error_code& ec)
  451. {
  452. impl_.get_service().open(impl_.get_implementation(), protocol, ec);
  453. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  454. }
  455. /// Assigns an existing native acceptor to the acceptor.
  456. /*
  457. * This function opens the acceptor to hold an existing native acceptor.
  458. *
  459. * @param protocol An object specifying which protocol is to be used.
  460. *
  461. * @param native_acceptor A native acceptor.
  462. *
  463. * @throws boost::system::system_error Thrown on failure.
  464. */
  465. void assign(const protocol_type& protocol,
  466. const native_handle_type& native_acceptor)
  467. {
  468. boost::system::error_code ec;
  469. impl_.get_service().assign(impl_.get_implementation(),
  470. protocol, native_acceptor, ec);
  471. boost::asio::detail::throw_error(ec, "assign");
  472. }
  473. /// Assigns an existing native acceptor to the acceptor.
  474. /*
  475. * This function opens the acceptor to hold an existing native acceptor.
  476. *
  477. * @param protocol An object specifying which protocol is to be used.
  478. *
  479. * @param native_acceptor A native acceptor.
  480. *
  481. * @param ec Set to indicate what error occurred, if any.
  482. */
  483. BOOST_ASIO_SYNC_OP_VOID assign(const protocol_type& protocol,
  484. const native_handle_type& native_acceptor, boost::system::error_code& ec)
  485. {
  486. impl_.get_service().assign(impl_.get_implementation(),
  487. protocol, native_acceptor, ec);
  488. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  489. }
  490. /// Determine whether the acceptor is open.
  491. bool is_open() const
  492. {
  493. return impl_.get_service().is_open(impl_.get_implementation());
  494. }
  495. /// Bind the acceptor to the given local endpoint.
  496. /**
  497. * This function binds the socket acceptor to the specified endpoint on the
  498. * local machine.
  499. *
  500. * @param endpoint An endpoint on the local machine to which the socket
  501. * acceptor will be bound.
  502. *
  503. * @throws boost::system::system_error Thrown on failure.
  504. *
  505. * @par Example
  506. * @code
  507. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  508. * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345);
  509. * acceptor.open(endpoint.protocol());
  510. * acceptor.bind(endpoint);
  511. * @endcode
  512. */
  513. void bind(const endpoint_type& endpoint)
  514. {
  515. boost::system::error_code ec;
  516. impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
  517. boost::asio::detail::throw_error(ec, "bind");
  518. }
  519. /// Bind the acceptor to the given local endpoint.
  520. /**
  521. * This function binds the socket acceptor to the specified endpoint on the
  522. * local machine.
  523. *
  524. * @param endpoint An endpoint on the local machine to which the socket
  525. * acceptor will be bound.
  526. *
  527. * @param ec Set to indicate what error occurred, if any.
  528. *
  529. * @par Example
  530. * @code
  531. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  532. * boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345);
  533. * acceptor.open(endpoint.protocol());
  534. * boost::system::error_code ec;
  535. * acceptor.bind(endpoint, ec);
  536. * if (ec)
  537. * {
  538. * // An error occurred.
  539. * }
  540. * @endcode
  541. */
  542. BOOST_ASIO_SYNC_OP_VOID bind(const endpoint_type& endpoint,
  543. boost::system::error_code& ec)
  544. {
  545. impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
  546. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  547. }
  548. /// Place the acceptor into the state where it will listen for new
  549. /// connections.
  550. /**
  551. * This function puts the socket acceptor into the state where it may accept
  552. * new connections.
  553. *
  554. * @param backlog The maximum length of the queue of pending connections.
  555. *
  556. * @throws boost::system::system_error Thrown on failure.
  557. */
  558. void listen(int backlog = socket_base::max_listen_connections)
  559. {
  560. boost::system::error_code ec;
  561. impl_.get_service().listen(impl_.get_implementation(), backlog, ec);
  562. boost::asio::detail::throw_error(ec, "listen");
  563. }
  564. /// Place the acceptor into the state where it will listen for new
  565. /// connections.
  566. /**
  567. * This function puts the socket acceptor into the state where it may accept
  568. * new connections.
  569. *
  570. * @param backlog The maximum length of the queue of pending connections.
  571. *
  572. * @param ec Set to indicate what error occurred, if any.
  573. *
  574. * @par Example
  575. * @code
  576. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  577. * ...
  578. * boost::system::error_code ec;
  579. * acceptor.listen(boost::asio::socket_base::max_listen_connections, ec);
  580. * if (ec)
  581. * {
  582. * // An error occurred.
  583. * }
  584. * @endcode
  585. */
  586. BOOST_ASIO_SYNC_OP_VOID listen(int backlog, boost::system::error_code& ec)
  587. {
  588. impl_.get_service().listen(impl_.get_implementation(), backlog, ec);
  589. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  590. }
  591. /// Close the acceptor.
  592. /**
  593. * This function is used to close the acceptor. Any asynchronous accept
  594. * operations will be cancelled immediately.
  595. *
  596. * A subsequent call to open() is required before the acceptor can again be
  597. * used to again perform socket accept operations.
  598. *
  599. * @throws boost::system::system_error Thrown on failure.
  600. */
  601. void close()
  602. {
  603. boost::system::error_code ec;
  604. impl_.get_service().close(impl_.get_implementation(), ec);
  605. boost::asio::detail::throw_error(ec, "close");
  606. }
  607. /// Close the acceptor.
  608. /**
  609. * This function is used to close the acceptor. Any asynchronous accept
  610. * operations will be cancelled immediately.
  611. *
  612. * A subsequent call to open() is required before the acceptor can again be
  613. * used to again perform socket accept operations.
  614. *
  615. * @param ec Set to indicate what error occurred, if any.
  616. *
  617. * @par Example
  618. * @code
  619. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  620. * ...
  621. * boost::system::error_code ec;
  622. * acceptor.close(ec);
  623. * if (ec)
  624. * {
  625. * // An error occurred.
  626. * }
  627. * @endcode
  628. */
  629. BOOST_ASIO_SYNC_OP_VOID close(boost::system::error_code& ec)
  630. {
  631. impl_.get_service().close(impl_.get_implementation(), ec);
  632. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  633. }
  634. /// Release ownership of the underlying native acceptor.
  635. /**
  636. * This function causes all outstanding asynchronous accept operations to
  637. * finish immediately, and the handlers for cancelled operations will be
  638. * passed the boost::asio::error::operation_aborted error. Ownership of the
  639. * native acceptor is then transferred to the caller.
  640. *
  641. * @throws boost::system::system_error Thrown on failure.
  642. *
  643. * @note This function is unsupported on Windows versions prior to Windows
  644. * 8.1, and will fail with boost::asio::error::operation_not_supported on
  645. * these platforms.
  646. */
  647. #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
  648. && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
  649. __declspec(deprecated("This function always fails with "
  650. "operation_not_supported when used on Windows versions "
  651. "prior to Windows 8.1."))
  652. #endif
  653. native_handle_type release()
  654. {
  655. boost::system::error_code ec;
  656. native_handle_type s = impl_.get_service().release(
  657. impl_.get_implementation(), ec);
  658. boost::asio::detail::throw_error(ec, "release");
  659. return s;
  660. }
  661. /// Release ownership of the underlying native acceptor.
  662. /**
  663. * This function causes all outstanding asynchronous accept operations to
  664. * finish immediately, and the handlers for cancelled operations will be
  665. * passed the boost::asio::error::operation_aborted error. Ownership of the
  666. * native acceptor is then transferred to the caller.
  667. *
  668. * @param ec Set to indicate what error occurred, if any.
  669. *
  670. * @note This function is unsupported on Windows versions prior to Windows
  671. * 8.1, and will fail with boost::asio::error::operation_not_supported on
  672. * these platforms.
  673. */
  674. #if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC >= 1400) \
  675. && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0603)
  676. __declspec(deprecated("This function always fails with "
  677. "operation_not_supported when used on Windows versions "
  678. "prior to Windows 8.1."))
  679. #endif
  680. native_handle_type release(boost::system::error_code& ec)
  681. {
  682. return impl_.get_service().release(impl_.get_implementation(), ec);
  683. }
  684. /// Get the native acceptor representation.
  685. /**
  686. * This function may be used to obtain the underlying representation of the
  687. * acceptor. This is intended to allow access to native acceptor functionality
  688. * that is not otherwise provided.
  689. */
  690. native_handle_type native_handle()
  691. {
  692. return impl_.get_service().native_handle(impl_.get_implementation());
  693. }
  694. /// Cancel all asynchronous operations associated with the acceptor.
  695. /**
  696. * This function causes all outstanding asynchronous connect, send and receive
  697. * operations to finish immediately, and the handlers for cancelled operations
  698. * will be passed the boost::asio::error::operation_aborted error.
  699. *
  700. * @throws boost::system::system_error Thrown on failure.
  701. */
  702. void cancel()
  703. {
  704. boost::system::error_code ec;
  705. impl_.get_service().cancel(impl_.get_implementation(), ec);
  706. boost::asio::detail::throw_error(ec, "cancel");
  707. }
  708. /// Cancel all asynchronous operations associated with the acceptor.
  709. /**
  710. * This function causes all outstanding asynchronous connect, send and receive
  711. * operations to finish immediately, and the handlers for cancelled operations
  712. * will be passed the boost::asio::error::operation_aborted error.
  713. *
  714. * @param ec Set to indicate what error occurred, if any.
  715. */
  716. BOOST_ASIO_SYNC_OP_VOID cancel(boost::system::error_code& ec)
  717. {
  718. impl_.get_service().cancel(impl_.get_implementation(), ec);
  719. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  720. }
  721. /// Set an option on the acceptor.
  722. /**
  723. * This function is used to set an option on the acceptor.
  724. *
  725. * @param option The new option value to be set on the acceptor.
  726. *
  727. * @throws boost::system::system_error Thrown on failure.
  728. *
  729. * @sa SettableSocketOption @n
  730. * boost::asio::socket_base::reuse_address
  731. * boost::asio::socket_base::enable_connection_aborted
  732. *
  733. * @par Example
  734. * Setting the SOL_SOCKET/SO_REUSEADDR option:
  735. * @code
  736. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  737. * ...
  738. * boost::asio::ip::tcp::acceptor::reuse_address option(true);
  739. * acceptor.set_option(option);
  740. * @endcode
  741. */
  742. template <typename SettableSocketOption>
  743. void set_option(const SettableSocketOption& option)
  744. {
  745. boost::system::error_code ec;
  746. impl_.get_service().set_option(impl_.get_implementation(), option, ec);
  747. boost::asio::detail::throw_error(ec, "set_option");
  748. }
  749. /// Set an option on the acceptor.
  750. /**
  751. * This function is used to set an option on the acceptor.
  752. *
  753. * @param option The new option value to be set on the acceptor.
  754. *
  755. * @param ec Set to indicate what error occurred, if any.
  756. *
  757. * @sa SettableSocketOption @n
  758. * boost::asio::socket_base::reuse_address
  759. * boost::asio::socket_base::enable_connection_aborted
  760. *
  761. * @par Example
  762. * Setting the SOL_SOCKET/SO_REUSEADDR option:
  763. * @code
  764. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  765. * ...
  766. * boost::asio::ip::tcp::acceptor::reuse_address option(true);
  767. * boost::system::error_code ec;
  768. * acceptor.set_option(option, ec);
  769. * if (ec)
  770. * {
  771. * // An error occurred.
  772. * }
  773. * @endcode
  774. */
  775. template <typename SettableSocketOption>
  776. BOOST_ASIO_SYNC_OP_VOID set_option(const SettableSocketOption& option,
  777. boost::system::error_code& ec)
  778. {
  779. impl_.get_service().set_option(impl_.get_implementation(), option, ec);
  780. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  781. }
  782. /// Get an option from the acceptor.
  783. /**
  784. * This function is used to get the current value of an option on the
  785. * acceptor.
  786. *
  787. * @param option The option value to be obtained from the acceptor.
  788. *
  789. * @throws boost::system::system_error Thrown on failure.
  790. *
  791. * @sa GettableSocketOption @n
  792. * boost::asio::socket_base::reuse_address
  793. *
  794. * @par Example
  795. * Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
  796. * @code
  797. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  798. * ...
  799. * boost::asio::ip::tcp::acceptor::reuse_address option;
  800. * acceptor.get_option(option);
  801. * bool is_set = option.get();
  802. * @endcode
  803. */
  804. template <typename GettableSocketOption>
  805. void get_option(GettableSocketOption& option) const
  806. {
  807. boost::system::error_code ec;
  808. impl_.get_service().get_option(impl_.get_implementation(), option, ec);
  809. boost::asio::detail::throw_error(ec, "get_option");
  810. }
  811. /// Get an option from the acceptor.
  812. /**
  813. * This function is used to get the current value of an option on the
  814. * acceptor.
  815. *
  816. * @param option The option value to be obtained from the acceptor.
  817. *
  818. * @param ec Set to indicate what error occurred, if any.
  819. *
  820. * @sa GettableSocketOption @n
  821. * boost::asio::socket_base::reuse_address
  822. *
  823. * @par Example
  824. * Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
  825. * @code
  826. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  827. * ...
  828. * boost::asio::ip::tcp::acceptor::reuse_address option;
  829. * boost::system::error_code ec;
  830. * acceptor.get_option(option, ec);
  831. * if (ec)
  832. * {
  833. * // An error occurred.
  834. * }
  835. * bool is_set = option.get();
  836. * @endcode
  837. */
  838. template <typename GettableSocketOption>
  839. BOOST_ASIO_SYNC_OP_VOID get_option(GettableSocketOption& option,
  840. boost::system::error_code& ec) const
  841. {
  842. impl_.get_service().get_option(impl_.get_implementation(), option, ec);
  843. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  844. }
  845. /// Perform an IO control command on the acceptor.
  846. /**
  847. * This function is used to execute an IO control command on the acceptor.
  848. *
  849. * @param command The IO control command to be performed on the acceptor.
  850. *
  851. * @throws boost::system::system_error Thrown on failure.
  852. *
  853. * @sa IoControlCommand @n
  854. * boost::asio::socket_base::non_blocking_io
  855. *
  856. * @par Example
  857. * Getting the number of bytes ready to read:
  858. * @code
  859. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  860. * ...
  861. * boost::asio::ip::tcp::acceptor::non_blocking_io command(true);
  862. * socket.io_control(command);
  863. * @endcode
  864. */
  865. template <typename IoControlCommand>
  866. void io_control(IoControlCommand& command)
  867. {
  868. boost::system::error_code ec;
  869. impl_.get_service().io_control(impl_.get_implementation(), command, ec);
  870. boost::asio::detail::throw_error(ec, "io_control");
  871. }
  872. /// Perform an IO control command on the acceptor.
  873. /**
  874. * This function is used to execute an IO control command on the acceptor.
  875. *
  876. * @param command The IO control command to be performed on the acceptor.
  877. *
  878. * @param ec Set to indicate what error occurred, if any.
  879. *
  880. * @sa IoControlCommand @n
  881. * boost::asio::socket_base::non_blocking_io
  882. *
  883. * @par Example
  884. * Getting the number of bytes ready to read:
  885. * @code
  886. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  887. * ...
  888. * boost::asio::ip::tcp::acceptor::non_blocking_io command(true);
  889. * boost::system::error_code ec;
  890. * socket.io_control(command, ec);
  891. * if (ec)
  892. * {
  893. * // An error occurred.
  894. * }
  895. * @endcode
  896. */
  897. template <typename IoControlCommand>
  898. BOOST_ASIO_SYNC_OP_VOID io_control(IoControlCommand& command,
  899. boost::system::error_code& ec)
  900. {
  901. impl_.get_service().io_control(impl_.get_implementation(), command, ec);
  902. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  903. }
  904. /// Gets the non-blocking mode of the acceptor.
  905. /**
  906. * @returns @c true if the acceptor's synchronous operations will fail with
  907. * boost::asio::error::would_block if they are unable to perform the requested
  908. * operation immediately. If @c false, synchronous operations will block
  909. * until complete.
  910. *
  911. * @note The non-blocking mode has no effect on the behaviour of asynchronous
  912. * operations. Asynchronous operations will never fail with the error
  913. * boost::asio::error::would_block.
  914. */
  915. bool non_blocking() const
  916. {
  917. return impl_.get_service().non_blocking(impl_.get_implementation());
  918. }
  919. /// Sets the non-blocking mode of the acceptor.
  920. /**
  921. * @param mode If @c true, the acceptor's synchronous operations will fail
  922. * with boost::asio::error::would_block if they are unable to perform the
  923. * requested operation immediately. If @c false, synchronous operations will
  924. * block until complete.
  925. *
  926. * @throws boost::system::system_error Thrown on failure.
  927. *
  928. * @note The non-blocking mode has no effect on the behaviour of asynchronous
  929. * operations. Asynchronous operations will never fail with the error
  930. * boost::asio::error::would_block.
  931. */
  932. void non_blocking(bool mode)
  933. {
  934. boost::system::error_code ec;
  935. impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
  936. boost::asio::detail::throw_error(ec, "non_blocking");
  937. }
  938. /// Sets the non-blocking mode of the acceptor.
  939. /**
  940. * @param mode If @c true, the acceptor's synchronous operations will fail
  941. * with boost::asio::error::would_block if they are unable to perform the
  942. * requested operation immediately. If @c false, synchronous operations will
  943. * block until complete.
  944. *
  945. * @param ec Set to indicate what error occurred, if any.
  946. *
  947. * @note The non-blocking mode has no effect on the behaviour of asynchronous
  948. * operations. Asynchronous operations will never fail with the error
  949. * boost::asio::error::would_block.
  950. */
  951. BOOST_ASIO_SYNC_OP_VOID non_blocking(
  952. bool mode, boost::system::error_code& ec)
  953. {
  954. impl_.get_service().non_blocking(impl_.get_implementation(), mode, ec);
  955. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  956. }
  957. /// Gets the non-blocking mode of the native acceptor implementation.
  958. /**
  959. * This function is used to retrieve the non-blocking mode of the underlying
  960. * native acceptor. This mode has no effect on the behaviour of the acceptor
  961. * object's synchronous operations.
  962. *
  963. * @returns @c true if the underlying acceptor is in non-blocking mode and
  964. * direct system calls may fail with boost::asio::error::would_block (or the
  965. * equivalent system error).
  966. *
  967. * @note The current non-blocking mode is cached by the acceptor object.
  968. * Consequently, the return value may be incorrect if the non-blocking mode
  969. * was set directly on the native acceptor.
  970. */
  971. bool native_non_blocking() const
  972. {
  973. return impl_.get_service().native_non_blocking(impl_.get_implementation());
  974. }
  975. /// Sets the non-blocking mode of the native acceptor implementation.
  976. /**
  977. * This function is used to modify the non-blocking mode of the underlying
  978. * native acceptor. It has no effect on the behaviour of the acceptor object's
  979. * synchronous operations.
  980. *
  981. * @param mode If @c true, the underlying acceptor is put into non-blocking
  982. * mode and direct system calls may fail with boost::asio::error::would_block
  983. * (or the equivalent system error).
  984. *
  985. * @throws boost::system::system_error Thrown on failure. If the @c mode is
  986. * @c false, but the current value of @c non_blocking() is @c true, this
  987. * function fails with boost::asio::error::invalid_argument, as the
  988. * combination does not make sense.
  989. */
  990. void native_non_blocking(bool mode)
  991. {
  992. boost::system::error_code ec;
  993. impl_.get_service().native_non_blocking(
  994. impl_.get_implementation(), mode, ec);
  995. boost::asio::detail::throw_error(ec, "native_non_blocking");
  996. }
  997. /// Sets the non-blocking mode of the native acceptor implementation.
  998. /**
  999. * This function is used to modify the non-blocking mode of the underlying
  1000. * native acceptor. It has no effect on the behaviour of the acceptor object's
  1001. * synchronous operations.
  1002. *
  1003. * @param mode If @c true, the underlying acceptor is put into non-blocking
  1004. * mode and direct system calls may fail with boost::asio::error::would_block
  1005. * (or the equivalent system error).
  1006. *
  1007. * @param ec Set to indicate what error occurred, if any. If the @c mode is
  1008. * @c false, but the current value of @c non_blocking() is @c true, this
  1009. * function fails with boost::asio::error::invalid_argument, as the
  1010. * combination does not make sense.
  1011. */
  1012. BOOST_ASIO_SYNC_OP_VOID native_non_blocking(
  1013. bool mode, boost::system::error_code& ec)
  1014. {
  1015. impl_.get_service().native_non_blocking(
  1016. impl_.get_implementation(), mode, ec);
  1017. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  1018. }
  1019. /// Get the local endpoint of the acceptor.
  1020. /**
  1021. * This function is used to obtain the locally bound endpoint of the acceptor.
  1022. *
  1023. * @returns An object that represents the local endpoint of the acceptor.
  1024. *
  1025. * @throws boost::system::system_error Thrown on failure.
  1026. *
  1027. * @par Example
  1028. * @code
  1029. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1030. * ...
  1031. * boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint();
  1032. * @endcode
  1033. */
  1034. endpoint_type local_endpoint() const
  1035. {
  1036. boost::system::error_code ec;
  1037. endpoint_type ep = impl_.get_service().local_endpoint(
  1038. impl_.get_implementation(), ec);
  1039. boost::asio::detail::throw_error(ec, "local_endpoint");
  1040. return ep;
  1041. }
  1042. /// Get the local endpoint of the acceptor.
  1043. /**
  1044. * This function is used to obtain the locally bound endpoint of the acceptor.
  1045. *
  1046. * @param ec Set to indicate what error occurred, if any.
  1047. *
  1048. * @returns An object that represents the local endpoint of the acceptor.
  1049. * Returns a default-constructed endpoint object if an error occurred and the
  1050. * error handler did not throw an exception.
  1051. *
  1052. * @par Example
  1053. * @code
  1054. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1055. * ...
  1056. * boost::system::error_code ec;
  1057. * boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec);
  1058. * if (ec)
  1059. * {
  1060. * // An error occurred.
  1061. * }
  1062. * @endcode
  1063. */
  1064. endpoint_type local_endpoint(boost::system::error_code& ec) const
  1065. {
  1066. return impl_.get_service().local_endpoint(impl_.get_implementation(), ec);
  1067. }
  1068. /// Wait for the acceptor to become ready to read, ready to write, or to have
  1069. /// pending error conditions.
  1070. /**
  1071. * This function is used to perform a blocking wait for an acceptor to enter
  1072. * a ready to read, write or error condition state.
  1073. *
  1074. * @param w Specifies the desired acceptor state.
  1075. *
  1076. * @par Example
  1077. * Waiting for an acceptor to become readable.
  1078. * @code
  1079. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1080. * ...
  1081. * acceptor.wait(boost::asio::ip::tcp::acceptor::wait_read);
  1082. * @endcode
  1083. */
  1084. void wait(wait_type w)
  1085. {
  1086. boost::system::error_code ec;
  1087. impl_.get_service().wait(impl_.get_implementation(), w, ec);
  1088. boost::asio::detail::throw_error(ec, "wait");
  1089. }
  1090. /// Wait for the acceptor to become ready to read, ready to write, or to have
  1091. /// pending error conditions.
  1092. /**
  1093. * This function is used to perform a blocking wait for an acceptor to enter
  1094. * a ready to read, write or error condition state.
  1095. *
  1096. * @param w Specifies the desired acceptor state.
  1097. *
  1098. * @param ec Set to indicate what error occurred, if any.
  1099. *
  1100. * @par Example
  1101. * Waiting for an acceptor to become readable.
  1102. * @code
  1103. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1104. * ...
  1105. * boost::system::error_code ec;
  1106. * acceptor.wait(boost::asio::ip::tcp::acceptor::wait_read, ec);
  1107. * @endcode
  1108. */
  1109. BOOST_ASIO_SYNC_OP_VOID wait(wait_type w, boost::system::error_code& ec)
  1110. {
  1111. impl_.get_service().wait(impl_.get_implementation(), w, ec);
  1112. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  1113. }
  1114. /// Asynchronously wait for the acceptor to become ready to read, ready to
  1115. /// write, or to have pending error conditions.
  1116. /**
  1117. * This function is used to perform an asynchronous wait for an acceptor to
  1118. * enter a ready to read, write or error condition state.
  1119. *
  1120. * @param w Specifies the desired acceptor state.
  1121. *
  1122. * @param handler The handler to be called when the wait operation completes.
  1123. * Copies will be made of the handler as required. The function signature of
  1124. * the handler must be:
  1125. * @code void handler(
  1126. * const boost::system::error_code& error // Result of operation
  1127. * ); @endcode
  1128. * Regardless of whether the asynchronous operation completes immediately or
  1129. * not, the handler will not be invoked from within this function. On
  1130. * immediate completion, invocation of the handler will be performed in a
  1131. * manner equivalent to using boost::asio::post().
  1132. *
  1133. * @par Example
  1134. * @code
  1135. * void wait_handler(const boost::system::error_code& error)
  1136. * {
  1137. * if (!error)
  1138. * {
  1139. * // Wait succeeded.
  1140. * }
  1141. * }
  1142. *
  1143. * ...
  1144. *
  1145. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1146. * ...
  1147. * acceptor.async_wait(
  1148. * boost::asio::ip::tcp::acceptor::wait_read,
  1149. * wait_handler);
  1150. * @endcode
  1151. */
  1152. template <typename WaitHandler>
  1153. BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
  1154. void (boost::system::error_code))
  1155. async_wait(wait_type w, BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  1156. {
  1157. return async_initiate<WaitHandler, void (boost::system::error_code)>(
  1158. initiate_async_wait(), handler, this, w);
  1159. }
  1160. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  1161. /// Accept a new connection.
  1162. /**
  1163. * This function is used to accept a new connection from a peer into the
  1164. * given socket. The function call will block until a new connection has been
  1165. * accepted successfully or an error occurs.
  1166. *
  1167. * @param peer The socket into which the new connection will be accepted.
  1168. *
  1169. * @throws boost::system::system_error Thrown on failure.
  1170. *
  1171. * @par Example
  1172. * @code
  1173. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1174. * ...
  1175. * boost::asio::ip::tcp::socket socket(my_context);
  1176. * acceptor.accept(socket);
  1177. * @endcode
  1178. */
  1179. template <typename Protocol1, typename Executor1>
  1180. void accept(basic_socket<Protocol1, Executor1>& peer,
  1181. typename enable_if<
  1182. is_convertible<Protocol, Protocol1>::value
  1183. >::type* = 0)
  1184. {
  1185. boost::system::error_code ec;
  1186. impl_.get_service().accept(impl_.get_implementation(),
  1187. peer, static_cast<endpoint_type*>(0), ec);
  1188. boost::asio::detail::throw_error(ec, "accept");
  1189. }
  1190. /// Accept a new connection.
  1191. /**
  1192. * This function is used to accept a new connection from a peer into the
  1193. * given socket. The function call will block until a new connection has been
  1194. * accepted successfully or an error occurs.
  1195. *
  1196. * @param peer The socket into which the new connection will be accepted.
  1197. *
  1198. * @param ec Set to indicate what error occurred, if any.
  1199. *
  1200. * @par Example
  1201. * @code
  1202. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1203. * ...
  1204. * boost::asio::ip::tcp::socket socket(my_context);
  1205. * boost::system::error_code ec;
  1206. * acceptor.accept(socket, ec);
  1207. * if (ec)
  1208. * {
  1209. * // An error occurred.
  1210. * }
  1211. * @endcode
  1212. */
  1213. template <typename Protocol1, typename Executor1>
  1214. BOOST_ASIO_SYNC_OP_VOID accept(
  1215. basic_socket<Protocol1, Executor1>& peer, boost::system::error_code& ec,
  1216. typename enable_if<
  1217. is_convertible<Protocol, Protocol1>::value
  1218. >::type* = 0)
  1219. {
  1220. impl_.get_service().accept(impl_.get_implementation(),
  1221. peer, static_cast<endpoint_type*>(0), ec);
  1222. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  1223. }
  1224. /// Start an asynchronous accept.
  1225. /**
  1226. * This function is used to asynchronously accept a new connection into a
  1227. * socket. The function call always returns immediately.
  1228. *
  1229. * @param peer The socket into which the new connection will be accepted.
  1230. * Ownership of the peer object is retained by the caller, which must
  1231. * guarantee that it is valid until the handler is called.
  1232. *
  1233. * @param handler The handler to be called when the accept operation
  1234. * completes. Copies will be made of the handler as required. The function
  1235. * signature of the handler must be:
  1236. * @code void handler(
  1237. * const boost::system::error_code& error // Result of operation.
  1238. * ); @endcode
  1239. * Regardless of whether the asynchronous operation completes immediately or
  1240. * not, the handler will not be invoked from within this function. On
  1241. * immediate completion, invocation of the handler will be performed in a
  1242. * manner equivalent to using boost::asio::post().
  1243. *
  1244. * @par Example
  1245. * @code
  1246. * void accept_handler(const boost::system::error_code& error)
  1247. * {
  1248. * if (!error)
  1249. * {
  1250. * // Accept succeeded.
  1251. * }
  1252. * }
  1253. *
  1254. * ...
  1255. *
  1256. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1257. * ...
  1258. * boost::asio::ip::tcp::socket socket(my_context);
  1259. * acceptor.async_accept(socket, accept_handler);
  1260. * @endcode
  1261. */
  1262. template <typename Protocol1, typename Executor1, typename AcceptHandler>
  1263. BOOST_ASIO_INITFN_RESULT_TYPE(AcceptHandler,
  1264. void (boost::system::error_code))
  1265. async_accept(basic_socket<Protocol1, Executor1>& peer,
  1266. BOOST_ASIO_MOVE_ARG(AcceptHandler) handler,
  1267. typename enable_if<
  1268. is_convertible<Protocol, Protocol1>::value
  1269. >::type* = 0)
  1270. {
  1271. return async_initiate<AcceptHandler, void (boost::system::error_code)>(
  1272. initiate_async_accept(), handler, this,
  1273. &peer, static_cast<endpoint_type*>(0));
  1274. }
  1275. /// Accept a new connection and obtain the endpoint of the peer
  1276. /**
  1277. * This function is used to accept a new connection from a peer into the
  1278. * given socket, and additionally provide the endpoint of the remote peer.
  1279. * The function call will block until a new connection has been accepted
  1280. * successfully or an error occurs.
  1281. *
  1282. * @param peer The socket into which the new connection will be accepted.
  1283. *
  1284. * @param peer_endpoint An endpoint object which will receive the endpoint of
  1285. * the remote peer.
  1286. *
  1287. * @throws boost::system::system_error Thrown on failure.
  1288. *
  1289. * @par Example
  1290. * @code
  1291. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1292. * ...
  1293. * boost::asio::ip::tcp::socket socket(my_context);
  1294. * boost::asio::ip::tcp::endpoint endpoint;
  1295. * acceptor.accept(socket, endpoint);
  1296. * @endcode
  1297. */
  1298. template <typename Executor1>
  1299. void accept(basic_socket<protocol_type, Executor1>& peer,
  1300. endpoint_type& peer_endpoint)
  1301. {
  1302. boost::system::error_code ec;
  1303. impl_.get_service().accept(impl_.get_implementation(),
  1304. peer, &peer_endpoint, ec);
  1305. boost::asio::detail::throw_error(ec, "accept");
  1306. }
  1307. /// Accept a new connection and obtain the endpoint of the peer
  1308. /**
  1309. * This function is used to accept a new connection from a peer into the
  1310. * given socket, and additionally provide the endpoint of the remote peer.
  1311. * The function call will block until a new connection has been accepted
  1312. * successfully or an error occurs.
  1313. *
  1314. * @param peer The socket into which the new connection will be accepted.
  1315. *
  1316. * @param peer_endpoint An endpoint object which will receive the endpoint of
  1317. * the remote peer.
  1318. *
  1319. * @param ec Set to indicate what error occurred, if any.
  1320. *
  1321. * @par Example
  1322. * @code
  1323. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1324. * ...
  1325. * boost::asio::ip::tcp::socket socket(my_context);
  1326. * boost::asio::ip::tcp::endpoint endpoint;
  1327. * boost::system::error_code ec;
  1328. * acceptor.accept(socket, endpoint, ec);
  1329. * if (ec)
  1330. * {
  1331. * // An error occurred.
  1332. * }
  1333. * @endcode
  1334. */
  1335. template <typename Executor1>
  1336. BOOST_ASIO_SYNC_OP_VOID accept(basic_socket<protocol_type, Executor1>& peer,
  1337. endpoint_type& peer_endpoint, boost::system::error_code& ec)
  1338. {
  1339. impl_.get_service().accept(
  1340. impl_.get_implementation(), peer, &peer_endpoint, ec);
  1341. BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  1342. }
  1343. /// Start an asynchronous accept.
  1344. /**
  1345. * This function is used to asynchronously accept a new connection into a
  1346. * socket, and additionally obtain the endpoint of the remote peer. The
  1347. * function call always returns immediately.
  1348. *
  1349. * @param peer The socket into which the new connection will be accepted.
  1350. * Ownership of the peer object is retained by the caller, which must
  1351. * guarantee that it is valid until the handler is called.
  1352. *
  1353. * @param peer_endpoint An endpoint object into which the endpoint of the
  1354. * remote peer will be written. Ownership of the peer_endpoint object is
  1355. * retained by the caller, which must guarantee that it is valid until the
  1356. * handler is called.
  1357. *
  1358. * @param handler The handler to be called when the accept operation
  1359. * completes. Copies will be made of the handler as required. The function
  1360. * signature of the handler must be:
  1361. * @code void handler(
  1362. * const boost::system::error_code& error // Result of operation.
  1363. * ); @endcode
  1364. * Regardless of whether the asynchronous operation completes immediately or
  1365. * not, the handler will not be invoked from within this function. On
  1366. * immediate completion, invocation of the handler will be performed in a
  1367. * manner equivalent to using boost::asio::post().
  1368. */
  1369. template <typename Executor1, typename AcceptHandler>
  1370. BOOST_ASIO_INITFN_RESULT_TYPE(AcceptHandler,
  1371. void (boost::system::error_code))
  1372. async_accept(basic_socket<protocol_type, Executor1>& peer,
  1373. endpoint_type& peer_endpoint, BOOST_ASIO_MOVE_ARG(AcceptHandler) handler)
  1374. {
  1375. return async_initiate<AcceptHandler, void (boost::system::error_code)>(
  1376. initiate_async_accept(), handler, this, &peer, &peer_endpoint);
  1377. }
  1378. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  1379. #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  1380. /// Accept a new connection.
  1381. /**
  1382. * This function is used to accept a new connection from a peer. The function
  1383. * call will block until a new connection has been accepted successfully or
  1384. * an error occurs.
  1385. *
  1386. * This overload requires that the Protocol template parameter satisfy the
  1387. * AcceptableProtocol type requirements.
  1388. *
  1389. * @returns A socket object representing the newly accepted connection.
  1390. *
  1391. * @throws boost::system::system_error Thrown on failure.
  1392. *
  1393. * @par Example
  1394. * @code
  1395. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1396. * ...
  1397. * boost::asio::ip::tcp::socket socket(acceptor.accept());
  1398. * @endcode
  1399. */
  1400. typename Protocol::socket accept()
  1401. {
  1402. boost::system::error_code ec;
  1403. typename Protocol::socket peer(impl_.get_executor());
  1404. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1405. boost::asio::detail::throw_error(ec, "accept");
  1406. return peer;
  1407. }
  1408. /// Accept a new connection.
  1409. /**
  1410. * This function is used to accept a new connection from a peer. The function
  1411. * call will block until a new connection has been accepted successfully or
  1412. * an error occurs.
  1413. *
  1414. * This overload requires that the Protocol template parameter satisfy the
  1415. * AcceptableProtocol type requirements.
  1416. *
  1417. * @param ec Set to indicate what error occurred, if any.
  1418. *
  1419. * @returns On success, a socket object representing the newly accepted
  1420. * connection. On error, a socket object where is_open() is false.
  1421. *
  1422. * @par Example
  1423. * @code
  1424. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1425. * ...
  1426. * boost::asio::ip::tcp::socket socket(acceptor.accept(ec));
  1427. * if (ec)
  1428. * {
  1429. * // An error occurred.
  1430. * }
  1431. * @endcode
  1432. */
  1433. typename Protocol::socket accept(boost::system::error_code& ec)
  1434. {
  1435. typename Protocol::socket peer(impl_.get_executor());
  1436. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1437. return peer;
  1438. }
  1439. /// Start an asynchronous accept.
  1440. /**
  1441. * This function is used to asynchronously accept a new connection. The
  1442. * function call always returns immediately.
  1443. *
  1444. * This overload requires that the Protocol template parameter satisfy the
  1445. * AcceptableProtocol type requirements.
  1446. *
  1447. * @param handler The handler to be called when the accept operation
  1448. * completes. Copies will be made of the handler as required. The function
  1449. * signature of the handler must be:
  1450. * @code void handler(
  1451. * const boost::system::error_code& error, // Result of operation.
  1452. * typename Protocol::socket peer // On success, the newly accepted socket.
  1453. * ); @endcode
  1454. * Regardless of whether the asynchronous operation completes immediately or
  1455. * not, the handler will not be invoked from within this function. On
  1456. * immediate completion, invocation of the handler will be performed in a
  1457. * manner equivalent to using boost::asio::post().
  1458. *
  1459. * @par Example
  1460. * @code
  1461. * void accept_handler(const boost::system::error_code& error,
  1462. * boost::asio::ip::tcp::socket peer)
  1463. * {
  1464. * if (!error)
  1465. * {
  1466. * // Accept succeeded.
  1467. * }
  1468. * }
  1469. *
  1470. * ...
  1471. *
  1472. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1473. * ...
  1474. * acceptor.async_accept(accept_handler);
  1475. * @endcode
  1476. */
  1477. template <typename MoveAcceptHandler>
  1478. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  1479. void (boost::system::error_code, typename Protocol::socket))
  1480. async_accept(BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler)
  1481. {
  1482. return async_initiate<MoveAcceptHandler,
  1483. void (boost::system::error_code, typename Protocol::socket)>(
  1484. initiate_async_move_accept(), handler, this,
  1485. impl_.get_executor(), static_cast<endpoint_type*>(0),
  1486. static_cast<typename Protocol::socket*>(0));
  1487. }
  1488. /// Accept a new connection.
  1489. /**
  1490. * This function is used to accept a new connection from a peer. The function
  1491. * call will block until a new connection has been accepted successfully or
  1492. * an error occurs.
  1493. *
  1494. * This overload requires that the Protocol template parameter satisfy the
  1495. * AcceptableProtocol type requirements.
  1496. *
  1497. * @param ex The I/O executor object to be used for the newly
  1498. * accepted socket.
  1499. *
  1500. * @returns A socket object representing the newly accepted connection.
  1501. *
  1502. * @throws boost::system::system_error Thrown on failure.
  1503. *
  1504. * @par Example
  1505. * @code
  1506. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1507. * ...
  1508. * boost::asio::ip::tcp::socket socket(acceptor.accept());
  1509. * @endcode
  1510. */
  1511. template <typename Executor1>
  1512. typename Protocol::socket::template rebind_executor<Executor1>::other
  1513. accept(const Executor1& ex,
  1514. typename enable_if<
  1515. is_executor<Executor1>::value
  1516. >::type* = 0)
  1517. {
  1518. boost::system::error_code ec;
  1519. typename Protocol::socket::template
  1520. rebind_executor<Executor1>::other peer(ex);
  1521. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1522. boost::asio::detail::throw_error(ec, "accept");
  1523. return peer;
  1524. }
  1525. /// Accept a new connection.
  1526. /**
  1527. * This function is used to accept a new connection from a peer. The function
  1528. * call will block until a new connection has been accepted successfully or
  1529. * an error occurs.
  1530. *
  1531. * This overload requires that the Protocol template parameter satisfy the
  1532. * AcceptableProtocol type requirements.
  1533. *
  1534. * @param context The I/O execution context object to be used for the newly
  1535. * accepted socket.
  1536. *
  1537. * @returns A socket object representing the newly accepted connection.
  1538. *
  1539. * @throws boost::system::system_error Thrown on failure.
  1540. *
  1541. * @par Example
  1542. * @code
  1543. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1544. * ...
  1545. * boost::asio::ip::tcp::socket socket(acceptor.accept());
  1546. * @endcode
  1547. */
  1548. template <typename ExecutionContext>
  1549. typename Protocol::socket::template rebind_executor<
  1550. typename ExecutionContext::executor_type>::other
  1551. accept(ExecutionContext& context,
  1552. typename enable_if<
  1553. is_convertible<ExecutionContext&, execution_context&>::value
  1554. >::type* = 0)
  1555. {
  1556. boost::system::error_code ec;
  1557. typename Protocol::socket::template rebind_executor<
  1558. typename ExecutionContext::executor_type>::other peer(context);
  1559. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1560. boost::asio::detail::throw_error(ec, "accept");
  1561. return peer;
  1562. }
  1563. /// Accept a new connection.
  1564. /**
  1565. * This function is used to accept a new connection from a peer. The function
  1566. * call will block until a new connection has been accepted successfully or
  1567. * an error occurs.
  1568. *
  1569. * This overload requires that the Protocol template parameter satisfy the
  1570. * AcceptableProtocol type requirements.
  1571. *
  1572. * @param ex The I/O executor object to be used for the newly accepted
  1573. * socket.
  1574. *
  1575. * @param ec Set to indicate what error occurred, if any.
  1576. *
  1577. * @returns On success, a socket object representing the newly accepted
  1578. * connection. On error, a socket object where is_open() is false.
  1579. *
  1580. * @par Example
  1581. * @code
  1582. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1583. * ...
  1584. * boost::asio::ip::tcp::socket socket(acceptor.accept(my_context2, ec));
  1585. * if (ec)
  1586. * {
  1587. * // An error occurred.
  1588. * }
  1589. * @endcode
  1590. */
  1591. template <typename Executor1>
  1592. typename Protocol::socket::template rebind_executor<Executor1>::other
  1593. accept(const Executor1& ex, boost::system::error_code& ec,
  1594. typename enable_if<
  1595. is_executor<Executor1>::value
  1596. >::type* = 0)
  1597. {
  1598. typename Protocol::socket::template
  1599. rebind_executor<Executor1>::other peer(ex);
  1600. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1601. return peer;
  1602. }
  1603. /// Accept a new connection.
  1604. /**
  1605. * This function is used to accept a new connection from a peer. The function
  1606. * call will block until a new connection has been accepted successfully or
  1607. * an error occurs.
  1608. *
  1609. * This overload requires that the Protocol template parameter satisfy the
  1610. * AcceptableProtocol type requirements.
  1611. *
  1612. * @param context The I/O execution context object to be used for the newly
  1613. * accepted socket.
  1614. *
  1615. * @param ec Set to indicate what error occurred, if any.
  1616. *
  1617. * @returns On success, a socket object representing the newly accepted
  1618. * connection. On error, a socket object where is_open() is false.
  1619. *
  1620. * @par Example
  1621. * @code
  1622. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1623. * ...
  1624. * boost::asio::ip::tcp::socket socket(acceptor.accept(my_context2, ec));
  1625. * if (ec)
  1626. * {
  1627. * // An error occurred.
  1628. * }
  1629. * @endcode
  1630. */
  1631. template <typename ExecutionContext>
  1632. typename Protocol::socket::template rebind_executor<
  1633. typename ExecutionContext::executor_type>::other
  1634. accept(ExecutionContext& context, boost::system::error_code& ec,
  1635. typename enable_if<
  1636. is_convertible<ExecutionContext&, execution_context&>::value
  1637. >::type* = 0)
  1638. {
  1639. typename Protocol::socket::template rebind_executor<
  1640. typename ExecutionContext::executor_type>::other peer(context);
  1641. impl_.get_service().accept(impl_.get_implementation(), peer, 0, ec);
  1642. return peer;
  1643. }
  1644. /// Start an asynchronous accept.
  1645. /**
  1646. * This function is used to asynchronously accept a new connection. The
  1647. * function call always returns immediately.
  1648. *
  1649. * This overload requires that the Protocol template parameter satisfy the
  1650. * AcceptableProtocol type requirements.
  1651. *
  1652. * @param ex The I/O executor object to be used for the newly accepted
  1653. * socket.
  1654. *
  1655. * @param handler The handler to be called when the accept operation
  1656. * completes. Copies will be made of the handler as required. The function
  1657. * signature of the handler must be:
  1658. * @code void handler(
  1659. * const boost::system::error_code& error, // Result of operation.
  1660. * typename Protocol::socket::template rebind_executor<
  1661. * Executor1>::other peer // On success, the newly accepted socket.
  1662. * ); @endcode
  1663. * Regardless of whether the asynchronous operation completes immediately or
  1664. * not, the handler will not be invoked from within this function. On
  1665. * immediate completion, invocation of the handler will be performed in a
  1666. * manner equivalent to using boost::asio::post().
  1667. *
  1668. * @par Example
  1669. * @code
  1670. * void accept_handler(const boost::system::error_code& error,
  1671. * boost::asio::ip::tcp::socket peer)
  1672. * {
  1673. * if (!error)
  1674. * {
  1675. * // Accept succeeded.
  1676. * }
  1677. * }
  1678. *
  1679. * ...
  1680. *
  1681. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1682. * ...
  1683. * acceptor.async_accept(my_context2, accept_handler);
  1684. * @endcode
  1685. */
  1686. template <typename Executor1, typename MoveAcceptHandler>
  1687. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  1688. void (boost::system::error_code,
  1689. typename Protocol::socket::template rebind_executor<
  1690. Executor1>::other))
  1691. async_accept(const Executor1& ex,
  1692. BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
  1693. typename enable_if<
  1694. is_executor<Executor1>::value
  1695. >::type* = 0)
  1696. {
  1697. typedef typename Protocol::socket::template rebind_executor<
  1698. Executor1>::other other_socket_type;
  1699. return async_initiate<MoveAcceptHandler,
  1700. void (boost::system::error_code, other_socket_type)>(
  1701. initiate_async_move_accept(), handler, this,
  1702. ex, static_cast<endpoint_type*>(0),
  1703. static_cast<other_socket_type*>(0));
  1704. }
  1705. /// Start an asynchronous accept.
  1706. /**
  1707. * This function is used to asynchronously accept a new connection. The
  1708. * function call always returns immediately.
  1709. *
  1710. * This overload requires that the Protocol template parameter satisfy the
  1711. * AcceptableProtocol type requirements.
  1712. *
  1713. * @param context The I/O execution context object to be used for the newly
  1714. * accepted socket.
  1715. *
  1716. * @param handler The handler to be called when the accept operation
  1717. * completes. Copies will be made of the handler as required. The function
  1718. * signature of the handler must be:
  1719. * @code void handler(
  1720. * const boost::system::error_code& error, // Result of operation.
  1721. * typename Protocol::socket::template rebind_executor<
  1722. * typename ExecutionContext::executor_type>::other peer
  1723. * // On success, the newly accepted socket.
  1724. * ); @endcode
  1725. * Regardless of whether the asynchronous operation completes immediately or
  1726. * not, the handler will not be invoked from within this function. On
  1727. * immediate completion, invocation of the handler will be performed in a
  1728. * manner equivalent to using boost::asio::post().
  1729. *
  1730. * @par Example
  1731. * @code
  1732. * void accept_handler(const boost::system::error_code& error,
  1733. * boost::asio::ip::tcp::socket peer)
  1734. * {
  1735. * if (!error)
  1736. * {
  1737. * // Accept succeeded.
  1738. * }
  1739. * }
  1740. *
  1741. * ...
  1742. *
  1743. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1744. * ...
  1745. * acceptor.async_accept(my_context2, accept_handler);
  1746. * @endcode
  1747. */
  1748. template <typename ExecutionContext, typename MoveAcceptHandler>
  1749. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  1750. void (boost::system::error_code,
  1751. typename Protocol::socket::template rebind_executor<
  1752. typename ExecutionContext::executor_type>::other))
  1753. async_accept(ExecutionContext& context,
  1754. BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
  1755. typename enable_if<
  1756. is_convertible<ExecutionContext&, execution_context&>::value
  1757. >::type* = 0)
  1758. {
  1759. typedef typename Protocol::socket::template rebind_executor<
  1760. typename ExecutionContext::executor_type>::other other_socket_type;
  1761. return async_initiate<MoveAcceptHandler,
  1762. void (boost::system::error_code, other_socket_type)>(
  1763. initiate_async_move_accept(), handler, this,
  1764. context.get_executor(), static_cast<endpoint_type*>(0),
  1765. static_cast<other_socket_type*>(0));
  1766. }
  1767. /// Accept a new connection.
  1768. /**
  1769. * This function is used to accept a new connection from a peer. The function
  1770. * call will block until a new connection has been accepted successfully or
  1771. * an error occurs.
  1772. *
  1773. * This overload requires that the Protocol template parameter satisfy the
  1774. * AcceptableProtocol type requirements.
  1775. *
  1776. * @param peer_endpoint An endpoint object into which the endpoint of the
  1777. * remote peer will be written.
  1778. *
  1779. * @returns A socket object representing the newly accepted connection.
  1780. *
  1781. * @throws boost::system::system_error Thrown on failure.
  1782. *
  1783. * @par Example
  1784. * @code
  1785. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1786. * ...
  1787. * boost::asio::ip::tcp::endpoint endpoint;
  1788. * boost::asio::ip::tcp::socket socket(acceptor.accept(endpoint));
  1789. * @endcode
  1790. */
  1791. typename Protocol::socket accept(endpoint_type& peer_endpoint)
  1792. {
  1793. boost::system::error_code ec;
  1794. typename Protocol::socket peer(impl_.get_executor());
  1795. impl_.get_service().accept(impl_.get_implementation(),
  1796. peer, &peer_endpoint, ec);
  1797. boost::asio::detail::throw_error(ec, "accept");
  1798. return peer;
  1799. }
  1800. /// Accept a new connection.
  1801. /**
  1802. * This function is used to accept a new connection from a peer. The function
  1803. * call will block until a new connection has been accepted successfully or
  1804. * an error occurs.
  1805. *
  1806. * This overload requires that the Protocol template parameter satisfy the
  1807. * AcceptableProtocol type requirements.
  1808. *
  1809. * @param peer_endpoint An endpoint object into which the endpoint of the
  1810. * remote peer will be written.
  1811. *
  1812. * @param ec Set to indicate what error occurred, if any.
  1813. *
  1814. * @returns On success, a socket object representing the newly accepted
  1815. * connection. On error, a socket object where is_open() is false.
  1816. *
  1817. * @par Example
  1818. * @code
  1819. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1820. * ...
  1821. * boost::asio::ip::tcp::endpoint endpoint;
  1822. * boost::asio::ip::tcp::socket socket(acceptor.accept(endpoint, ec));
  1823. * if (ec)
  1824. * {
  1825. * // An error occurred.
  1826. * }
  1827. * @endcode
  1828. */
  1829. typename Protocol::socket accept(
  1830. endpoint_type& peer_endpoint, boost::system::error_code& ec)
  1831. {
  1832. typename Protocol::socket peer(impl_.get_executor());
  1833. impl_.get_service().accept(impl_.get_implementation(),
  1834. peer, &peer_endpoint, ec);
  1835. return peer;
  1836. }
  1837. /// Start an asynchronous accept.
  1838. /**
  1839. * This function is used to asynchronously accept a new connection. The
  1840. * function call always returns immediately.
  1841. *
  1842. * This overload requires that the Protocol template parameter satisfy the
  1843. * AcceptableProtocol type requirements.
  1844. *
  1845. * @param peer_endpoint An endpoint object into which the endpoint of the
  1846. * remote peer will be written. Ownership of the peer_endpoint object is
  1847. * retained by the caller, which must guarantee that it is valid until the
  1848. * handler is called.
  1849. *
  1850. * @param handler The handler to be called when the accept operation
  1851. * completes. Copies will be made of the handler as required. The function
  1852. * signature of the handler must be:
  1853. * @code void handler(
  1854. * const boost::system::error_code& error, // Result of operation.
  1855. * typename Protocol::socket peer // On success, the newly accepted socket.
  1856. * ); @endcode
  1857. * Regardless of whether the asynchronous operation completes immediately or
  1858. * not, the handler will not be invoked from within this function. On
  1859. * immediate completion, invocation of the handler will be performed in a
  1860. * manner equivalent to using boost::asio::post().
  1861. *
  1862. * @par Example
  1863. * @code
  1864. * void accept_handler(const boost::system::error_code& error,
  1865. * boost::asio::ip::tcp::socket peer)
  1866. * {
  1867. * if (!error)
  1868. * {
  1869. * // Accept succeeded.
  1870. * }
  1871. * }
  1872. *
  1873. * ...
  1874. *
  1875. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1876. * ...
  1877. * boost::asio::ip::tcp::endpoint endpoint;
  1878. * acceptor.async_accept(endpoint, accept_handler);
  1879. * @endcode
  1880. */
  1881. template <typename MoveAcceptHandler>
  1882. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  1883. void (boost::system::error_code, typename Protocol::socket))
  1884. async_accept(endpoint_type& peer_endpoint,
  1885. BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler)
  1886. {
  1887. return async_initiate<MoveAcceptHandler,
  1888. void (boost::system::error_code, typename Protocol::socket)>(
  1889. initiate_async_move_accept(), handler, this,
  1890. impl_.get_executor(), &peer_endpoint,
  1891. static_cast<typename Protocol::socket*>(0));
  1892. }
  1893. /// Accept a new connection.
  1894. /**
  1895. * This function is used to accept a new connection from a peer. The function
  1896. * call will block until a new connection has been accepted successfully or
  1897. * an error occurs.
  1898. *
  1899. * This overload requires that the Protocol template parameter satisfy the
  1900. * AcceptableProtocol type requirements.
  1901. *
  1902. * @param ex The I/O executor object to be used for the newly accepted
  1903. * socket.
  1904. *
  1905. * @param peer_endpoint An endpoint object into which the endpoint of the
  1906. * remote peer will be written.
  1907. *
  1908. * @returns A socket object representing the newly accepted connection.
  1909. *
  1910. * @throws boost::system::system_error Thrown on failure.
  1911. *
  1912. * @par Example
  1913. * @code
  1914. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1915. * ...
  1916. * boost::asio::ip::tcp::endpoint endpoint;
  1917. * boost::asio::ip::tcp::socket socket(
  1918. * acceptor.accept(my_context2, endpoint));
  1919. * @endcode
  1920. */
  1921. template <typename Executor1>
  1922. typename Protocol::socket::template rebind_executor<Executor1>::other
  1923. accept(const Executor1& ex, endpoint_type& peer_endpoint,
  1924. typename enable_if<
  1925. is_executor<Executor1>::value
  1926. >::type* = 0)
  1927. {
  1928. boost::system::error_code ec;
  1929. typename Protocol::socket::template
  1930. rebind_executor<Executor1>::other peer(ex);
  1931. impl_.get_service().accept(impl_.get_implementation(),
  1932. peer, &peer_endpoint, ec);
  1933. boost::asio::detail::throw_error(ec, "accept");
  1934. return peer;
  1935. }
  1936. /// Accept a new connection.
  1937. /**
  1938. * This function is used to accept a new connection from a peer. The function
  1939. * call will block until a new connection has been accepted successfully or
  1940. * an error occurs.
  1941. *
  1942. * This overload requires that the Protocol template parameter satisfy the
  1943. * AcceptableProtocol type requirements.
  1944. *
  1945. * @param context The I/O execution context object to be used for the newly
  1946. * accepted socket.
  1947. *
  1948. * @param peer_endpoint An endpoint object into which the endpoint of the
  1949. * remote peer will be written.
  1950. *
  1951. * @returns A socket object representing the newly accepted connection.
  1952. *
  1953. * @throws boost::system::system_error Thrown on failure.
  1954. *
  1955. * @par Example
  1956. * @code
  1957. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  1958. * ...
  1959. * boost::asio::ip::tcp::endpoint endpoint;
  1960. * boost::asio::ip::tcp::socket socket(
  1961. * acceptor.accept(my_context2, endpoint));
  1962. * @endcode
  1963. */
  1964. template <typename ExecutionContext>
  1965. typename Protocol::socket::template rebind_executor<
  1966. typename ExecutionContext::executor_type>::other
  1967. accept(ExecutionContext& context, endpoint_type& peer_endpoint,
  1968. typename enable_if<
  1969. is_convertible<ExecutionContext&, execution_context&>::value
  1970. >::type* = 0)
  1971. {
  1972. boost::system::error_code ec;
  1973. typename Protocol::socket::template rebind_executor<
  1974. typename ExecutionContext::executor_type>::other peer(context);
  1975. impl_.get_service().accept(impl_.get_implementation(),
  1976. peer, &peer_endpoint, ec);
  1977. boost::asio::detail::throw_error(ec, "accept");
  1978. return peer;
  1979. }
  1980. /// Accept a new connection.
  1981. /**
  1982. * This function is used to accept a new connection from a peer. The function
  1983. * call will block until a new connection has been accepted successfully or
  1984. * an error occurs.
  1985. *
  1986. * This overload requires that the Protocol template parameter satisfy the
  1987. * AcceptableProtocol type requirements.
  1988. *
  1989. * @param ex The I/O executor object to be used for the newly accepted
  1990. * socket.
  1991. *
  1992. * @param peer_endpoint An endpoint object into which the endpoint of the
  1993. * remote peer will be written.
  1994. *
  1995. * @param ec Set to indicate what error occurred, if any.
  1996. *
  1997. * @returns On success, a socket object representing the newly accepted
  1998. * connection. On error, a socket object where is_open() is false.
  1999. *
  2000. * @par Example
  2001. * @code
  2002. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  2003. * ...
  2004. * boost::asio::ip::tcp::endpoint endpoint;
  2005. * boost::asio::ip::tcp::socket socket(
  2006. * acceptor.accept(my_context2, endpoint, ec));
  2007. * if (ec)
  2008. * {
  2009. * // An error occurred.
  2010. * }
  2011. * @endcode
  2012. */
  2013. template <typename Executor1>
  2014. typename Protocol::socket::template rebind_executor<Executor1>::other
  2015. accept(const executor_type& ex,
  2016. endpoint_type& peer_endpoint, boost::system::error_code& ec,
  2017. typename enable_if<
  2018. is_executor<Executor1>::value
  2019. >::type* = 0)
  2020. {
  2021. typename Protocol::socket::template
  2022. rebind_executor<Executor1>::other peer(ex);
  2023. impl_.get_service().accept(impl_.get_implementation(),
  2024. peer, &peer_endpoint, ec);
  2025. return peer;
  2026. }
  2027. /// Accept a new connection.
  2028. /**
  2029. * This function is used to accept a new connection from a peer. The function
  2030. * call will block until a new connection has been accepted successfully or
  2031. * an error occurs.
  2032. *
  2033. * This overload requires that the Protocol template parameter satisfy the
  2034. * AcceptableProtocol type requirements.
  2035. *
  2036. * @param context The I/O execution context object to be used for the newly
  2037. * accepted socket.
  2038. *
  2039. * @param peer_endpoint An endpoint object into which the endpoint of the
  2040. * remote peer will be written.
  2041. *
  2042. * @param ec Set to indicate what error occurred, if any.
  2043. *
  2044. * @returns On success, a socket object representing the newly accepted
  2045. * connection. On error, a socket object where is_open() is false.
  2046. *
  2047. * @par Example
  2048. * @code
  2049. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  2050. * ...
  2051. * boost::asio::ip::tcp::endpoint endpoint;
  2052. * boost::asio::ip::tcp::socket socket(
  2053. * acceptor.accept(my_context2, endpoint, ec));
  2054. * if (ec)
  2055. * {
  2056. * // An error occurred.
  2057. * }
  2058. * @endcode
  2059. */
  2060. template <typename ExecutionContext>
  2061. typename Protocol::socket::template rebind_executor<
  2062. typename ExecutionContext::executor_type>::other
  2063. accept(ExecutionContext& context,
  2064. endpoint_type& peer_endpoint, boost::system::error_code& ec,
  2065. typename enable_if<
  2066. is_convertible<ExecutionContext&, execution_context&>::value
  2067. >::type* = 0)
  2068. {
  2069. typename Protocol::socket::template rebind_executor<
  2070. typename ExecutionContext::executor_type>::other peer(context);
  2071. impl_.get_service().accept(impl_.get_implementation(),
  2072. peer, &peer_endpoint, ec);
  2073. return peer;
  2074. }
  2075. /// Start an asynchronous accept.
  2076. /**
  2077. * This function is used to asynchronously accept a new connection. The
  2078. * function call always returns immediately.
  2079. *
  2080. * This overload requires that the Protocol template parameter satisfy the
  2081. * AcceptableProtocol type requirements.
  2082. *
  2083. * @param ex The I/O executor object to be used for the newly accepted
  2084. * socket.
  2085. *
  2086. * @param peer_endpoint An endpoint object into which the endpoint of the
  2087. * remote peer will be written. Ownership of the peer_endpoint object is
  2088. * retained by the caller, which must guarantee that it is valid until the
  2089. * handler is called.
  2090. *
  2091. * @param handler The handler to be called when the accept operation
  2092. * completes. Copies will be made of the handler as required. The function
  2093. * signature of the handler must be:
  2094. * @code void handler(
  2095. * const boost::system::error_code& error, // Result of operation.
  2096. * typename Protocol::socket::template rebind_executor<
  2097. * Executor1>::other peer // On success, the newly accepted socket.
  2098. * ); @endcode
  2099. * Regardless of whether the asynchronous operation completes immediately or
  2100. * not, the handler will not be invoked from within this function. On
  2101. * immediate completion, invocation of the handler will be performed in a
  2102. * manner equivalent to using boost::asio::post().
  2103. *
  2104. * @par Example
  2105. * @code
  2106. * void accept_handler(const boost::system::error_code& error,
  2107. * boost::asio::ip::tcp::socket peer)
  2108. * {
  2109. * if (!error)
  2110. * {
  2111. * // Accept succeeded.
  2112. * }
  2113. * }
  2114. *
  2115. * ...
  2116. *
  2117. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  2118. * ...
  2119. * boost::asio::ip::tcp::endpoint endpoint;
  2120. * acceptor.async_accept(my_context2, endpoint, accept_handler);
  2121. * @endcode
  2122. */
  2123. template <typename Executor1, typename MoveAcceptHandler>
  2124. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  2125. void (boost::system::error_code,
  2126. typename Protocol::socket::template rebind_executor<
  2127. Executor1>::other))
  2128. async_accept(const Executor1& ex, endpoint_type& peer_endpoint,
  2129. BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
  2130. typename enable_if<
  2131. is_executor<Executor1>::value
  2132. >::type* = 0)
  2133. {
  2134. typedef typename Protocol::socket::template rebind_executor<
  2135. Executor1>::other other_socket_type;
  2136. return async_initiate<MoveAcceptHandler,
  2137. void (boost::system::error_code, other_socket_type)>(
  2138. initiate_async_move_accept(), handler, this,
  2139. ex, &peer_endpoint,
  2140. static_cast<other_socket_type*>(0));
  2141. }
  2142. /// Start an asynchronous accept.
  2143. /**
  2144. * This function is used to asynchronously accept a new connection. The
  2145. * function call always returns immediately.
  2146. *
  2147. * This overload requires that the Protocol template parameter satisfy the
  2148. * AcceptableProtocol type requirements.
  2149. *
  2150. * @param context The I/O execution context object to be used for the newly
  2151. * accepted socket.
  2152. *
  2153. * @param peer_endpoint An endpoint object into which the endpoint of the
  2154. * remote peer will be written. Ownership of the peer_endpoint object is
  2155. * retained by the caller, which must guarantee that it is valid until the
  2156. * handler is called.
  2157. *
  2158. * @param handler The handler to be called when the accept operation
  2159. * completes. Copies will be made of the handler as required. The function
  2160. * signature of the handler must be:
  2161. * @code void handler(
  2162. * const boost::system::error_code& error, // Result of operation.
  2163. * typename Protocol::socket::template rebind_executor<
  2164. * typename ExecutionContext::executor_type>::other peer
  2165. * // On success, the newly accepted socket.
  2166. * ); @endcode
  2167. * Regardless of whether the asynchronous operation completes immediately or
  2168. * not, the handler will not be invoked from within this function. On
  2169. * immediate completion, invocation of the handler will be performed in a
  2170. * manner equivalent to using boost::asio::post().
  2171. *
  2172. * @par Example
  2173. * @code
  2174. * void accept_handler(const boost::system::error_code& error,
  2175. * boost::asio::ip::tcp::socket peer)
  2176. * {
  2177. * if (!error)
  2178. * {
  2179. * // Accept succeeded.
  2180. * }
  2181. * }
  2182. *
  2183. * ...
  2184. *
  2185. * boost::asio::ip::tcp::acceptor acceptor(my_context);
  2186. * ...
  2187. * boost::asio::ip::tcp::endpoint endpoint;
  2188. * acceptor.async_accept(my_context2, endpoint, accept_handler);
  2189. * @endcode
  2190. */
  2191. template <typename ExecutionContext, typename MoveAcceptHandler>
  2192. BOOST_ASIO_INITFN_RESULT_TYPE(MoveAcceptHandler,
  2193. void (boost::system::error_code,
  2194. typename Protocol::socket::template rebind_executor<
  2195. typename ExecutionContext::executor_type>::other))
  2196. async_accept(ExecutionContext& context,
  2197. endpoint_type& peer_endpoint,
  2198. BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
  2199. typename enable_if<
  2200. is_convertible<ExecutionContext&, execution_context&>::value
  2201. >::type* = 0)
  2202. {
  2203. typedef typename Protocol::socket::template rebind_executor<
  2204. typename ExecutionContext::executor_type>::other other_socket_type;
  2205. return async_initiate<MoveAcceptHandler,
  2206. void (boost::system::error_code, other_socket_type)>(
  2207. initiate_async_move_accept(), handler, this,
  2208. context.get_executor(), &peer_endpoint,
  2209. static_cast<other_socket_type*>(0));
  2210. }
  2211. #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
  2212. private:
  2213. // Disallow copying and assignment.
  2214. basic_socket_acceptor(const basic_socket_acceptor&) BOOST_ASIO_DELETED;
  2215. basic_socket_acceptor& operator=(
  2216. const basic_socket_acceptor&) BOOST_ASIO_DELETED;
  2217. struct initiate_async_wait
  2218. {
  2219. template <typename WaitHandler>
  2220. void operator()(BOOST_ASIO_MOVE_ARG(WaitHandler) handler,
  2221. basic_socket_acceptor* self, wait_type w) const
  2222. {
  2223. // If you get an error on the following line it means that your handler
  2224. // does not meet the documented type requirements for a WaitHandler.
  2225. BOOST_ASIO_WAIT_HANDLER_CHECK(WaitHandler, handler) type_check;
  2226. detail::non_const_lvalue<WaitHandler> handler2(handler);
  2227. self->impl_.get_service().async_wait(
  2228. self->impl_.get_implementation(), w, handler2.value,
  2229. self->impl_.get_implementation_executor());
  2230. }
  2231. };
  2232. struct initiate_async_accept
  2233. {
  2234. template <typename AcceptHandler, typename Protocol1, typename Executor1>
  2235. void operator()(BOOST_ASIO_MOVE_ARG(AcceptHandler) handler,
  2236. basic_socket_acceptor* self, basic_socket<Protocol1, Executor1>* peer,
  2237. endpoint_type* peer_endpoint) const
  2238. {
  2239. // If you get an error on the following line it means that your handler
  2240. // does not meet the documented type requirements for a AcceptHandler.
  2241. BOOST_ASIO_ACCEPT_HANDLER_CHECK(AcceptHandler, handler) type_check;
  2242. detail::non_const_lvalue<AcceptHandler> handler2(handler);
  2243. self->impl_.get_service().async_accept(
  2244. self->impl_.get_implementation(), *peer, peer_endpoint,
  2245. handler2.value, self->impl_.get_implementation_executor());
  2246. }
  2247. };
  2248. struct initiate_async_move_accept
  2249. {
  2250. template <typename MoveAcceptHandler, typename Executor1, typename Socket>
  2251. void operator()(BOOST_ASIO_MOVE_ARG(MoveAcceptHandler) handler,
  2252. basic_socket_acceptor* self, const Executor1& peer_ex,
  2253. endpoint_type* peer_endpoint, Socket*) const
  2254. {
  2255. // If you get an error on the following line it means that your handler
  2256. // does not meet the documented type requirements for a MoveAcceptHandler.
  2257. BOOST_ASIO_MOVE_ACCEPT_HANDLER_CHECK(
  2258. MoveAcceptHandler, handler, Socket) type_check;
  2259. detail::non_const_lvalue<MoveAcceptHandler> handler2(handler);
  2260. self->impl_.get_service().async_move_accept(
  2261. self->impl_.get_implementation(), peer_ex, peer_endpoint,
  2262. handler2.value, self->impl_.get_implementation_executor());
  2263. }
  2264. };
  2265. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  2266. detail::io_object_impl<
  2267. detail::null_socket_service<Protocol>, Executor> impl_;
  2268. #elif defined(BOOST_ASIO_HAS_IOCP)
  2269. detail::io_object_impl<
  2270. detail::win_iocp_socket_service<Protocol>, Executor> impl_;
  2271. #else
  2272. detail::io_object_impl<
  2273. detail::reactive_socket_service<Protocol>, Executor> impl_;
  2274. #endif
  2275. };
  2276. } // namespace asio
  2277. } // namespace boost
  2278. #include <boost/asio/detail/pop_options.hpp>
  2279. #endif // BOOST_ASIO_BASIC_SOCKET_ACCEPTOR_HPP