[Libwebsockets] how to get listen fd?

Andy Green andy at warmcat.com
Sat Jan 9 14:44:24 CET 2016

On January 9, 2016 9:26:51 PM GMT+08:00, Peter Pentchev <roam at ringlet.net> wrote:
>On Sat, Jan 09, 2016 at 03:46:36PM +0800, Andy Green wrote:
>> On January 9, 2016 3:37:18 PM GMT+08:00, Ash 20001
><ash20001 at hotmail.com> wrote:
>> >I have looked at the source code in server.c to see when the
>> >fd is created. I would like to gain access to this fd to set a
>> >different sock option on it (close on exec flag) using fcntl.
>However I
>> >can't seem to get this fd from a public API.
>> >only seems to work on wsi and wsi pointer is not provided in most
>> >callbacks.
>> >Any ideas?
>> I'd be willing to either expose it or add a context creation flag to
>perform the operation, but from a quick google you can only attach that
>attribute to files, at open() time.
>Hmm, if you mean the O_CLOEXEC flag, it's actually a relatively recent
>addition; the historical (though non-atomic) way to mark a file for
>closing upon exec() is, as Ash mentioned, a fcntl(F_GETFD) /
>sequence, or-ing the file descriptor flags with FD_CLOEXEC in between;
>see e.g. https://codesearch.debian.net/results/FD_CLOEXEC/page_9 for
>examples (although most of the hits are glibc internal definitions).

I see... but these hits are all on file descriptors... do you know if it works the same on sockets, as he's trying to do?

Or Ash if you are already satisfied it works, can you send a diff with it just hacked into context create as you tested it?



More information about the Libwebsockets mailing list