[Libwebsockets] how to get listen fd?

Peter Pentchev roam at ringlet.net
Sat Jan 9 14:26:51 CET 2016

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 listening
> >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. libwebsocket_get_socket_fd
> >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) / fcntl(F_SETFD)
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 some
examples (although most of the hits are glibc internal definitions).


Peter Pentchev  roam at ringlet.net roam at FreeBSD.org pp at storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20160109/5a287342/attachment.sig>

More information about the Libwebsockets mailing list