Hi Guys
Perhaps it would be a good idea to modify ASIO to allow for specialization of the socket creation or initial socket flags. It could be as simple as an optional function pointer, virtual method, or functor that could be chosen at socket creation time via a template parameter.
Regards,
Jeff
On May 25, 2014, at 15:46, Roger Austin (Australia) <***@innovyze.com> wrote:
> Hi Philippe,
>
> There is a similar issue on Windows when threads create child processes that inherit handles. Recent versions of Windows allow WSA_FLAG_NO_HANDLE_INHERIT to be set at socket creation to avoid this. I think it would be useful for asio to provide a portable no-inherit option with suitable implementations on POSIX and Windows systems.
>
> A workaround would be to serialize all socket creation, either via a native synchronisation method or through an asio strand, and set the appropriate flag on the handle/FD after creation.
>
> Regards,
> Roger Austin
>
> From: Philippe Leuba [mailto:***@swissonline.ch]
> Sent: Monday, 26 May 2014 12:00 AM
> To: asio-***@lists.sourceforge.net
> Subject: Re: [asio-users] How to prevent Asio TCP socket to be inherited by child when using fork/exec
>
> Hi Yuri,
>
> I agree that SOCK_CLOEXEC is Posix only, but Asio has some file specific to Posix, like epoll_reactor where SOCK_CLOEXEC is used for epoll_create and timers_create.
>
> Setting CLOEXEC afterwards can cause race condition if the fork is executed between socket creation and fnctl.
>
> Regards
>
> Philippe Leuba
>
> On 24 mai 2014, at 14:13, Yuri Timenkov <***@timenkov.ru> wrote:
>
> Hi,
>
> First of all, fork() and CLOEXEC are not portable (work only on POSIX systems) that's why ASIO doesn't have it.
>
> I would recommend setting CLOEXEC afterwards, with something like:
>
> fcntl(mysock.native_handle(), F_SETFD, FD_CLOEXEC);
>
> Which should be equivalent to passing SOCK_CLOEXEC to open().
>
> Regards,
> Yuri
>
>
> From: ***@swissonline.ch
> Date: Tue, 20 May 2014 21:27:26 +0200
> To: asio-***@lists.sourceforge.net
> Subject: Re: [asio-users] How to prevent Asio TCP socket to be inherited by child when using fork/exec
>
> Hi,
>
> For what I have understood, the SOCK_CLOEXEC flag is especially intended to set the close-on-exec flag atomically at socket creation time: socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP).
>
> But how to do this with Asio?
>
> Philippe Leuba
>
> On 20 mai 2014, at 20:33, "Gruenke,Matt" <***@Tycoint.com> wrote:
>
> Race conditions at what level? If your fork/exec is not synchronized with your socket creation & configuration, then theres a race condition even if you set it immediately after opening it.
>
>
>
>
>
> Matt
>
>
>
>
>
> From: Philippe Leuba [mailto:***@swissonline.ch]
> Sent: May 20, 2014 11:25
> To: asio-***@lists.sourceforge.net
> Subject: [asio-users] How to prevent Asio TCP socket to be inherited by child when using fork/exec
>
>
>
> Hi,
>
>
>
> How can we prevent Asio TCP socket to be inherited by child process when using fork/exec. Normally this can be achieved by adding the SOCK_CLOEXEC flag at socket creation time.
>
>
>
> Adding the O_CLOEXEC flag later is not really a solution due to potential race conditions.
>
>
>
> Creating the socket outside of boost and assigning it to the boost::ip::tcp::socket neither because async_connect will close it and open a new one.
>
>
>
> Any others ideas?
>
> Philippe Leuba
>
>
>
> This e-mail contains privileged and confidential information intended for the use of the addressees named above. If you are not the intended recipient of this e-mail, you are hereby notified that you must not disseminate, copy or take any action in respect of any information contained in it. If you have received this e-mail in error, please notify the sender immediately by e-mail and immediately destroy this e-mail and its attachments.
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> asio-users mailing list
> asio-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/asio-users
> _______________________________________________
> Using Asio? List your project at
> http://think-async.com/Asio/WhoIsUsingAsio
>
> ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs
> _______________________________________________ asio-users mailing list asio-***@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/asio-users _______________________________________________ Using Asio? List your project at http://think-async.com/Asio/WhoIsUsingAsio
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> asio-users mailing list
> asio-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/asio-users
> _______________________________________________
> Using Asio? List your project at
> http://think-async.com/Asio/WhoIsUsingAsio
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs_______________________________________________
> asio-users mailing list
> asio-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/asio-users
> _______________________________________________
> Using Asio? List your project at
> http://think-async.com/Asio/WhoIsUsingAsio