From 4d416e8d111f9d60e5c82482e71e59212274782c Mon Sep 17 00:00:00 2001 From: Per Hedbor <ph@opera.com> Date: Thu, 4 Sep 2014 15:39:49 +0200 Subject: [PATCH] Include a constant in Stdio.Port for reuseport and fastopen support. Especially SO_REUSEPORT needs different code if it is supported than when it is not. --- src/modules/_Stdio/socket.c | 26 +++++++++++++++++++------- src/pike_netlib.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/modules/_Stdio/socket.c b/src/modules/_Stdio/socket.c index 75b369cbed..50270f724c 100644 --- a/src/modules/_Stdio/socket.c +++ b/src/modules/_Stdio/socket.c @@ -63,7 +63,6 @@ #ifdef HAVE_SYS_UN_H #include <sys/un.h> #endif - #include "dmalloc.h" /*! @module Stdio @@ -735,6 +734,17 @@ static void exit_port_struct(struct object *UNUSED(o)) /* map_variable takes care of id and accept_callback. */ } +int fd_from_portobject( struct object *p ) +{ + struct port *po = get_storage( p, port_program ); + if(!po) return -1; + return po->box.fd; +} + +static void port_query_fd(INT32 UNUSED(args)) +{ + push_int(fd_from_portobject(Pike_fp->current_object)); +} /*! @endclass */ @@ -787,17 +797,19 @@ void init_stdio_port(void) tVoid), 0); ADD_FUNCTION ("set_backend", port_set_backend, tFunc(tObj,tVoid), 0); ADD_FUNCTION ("query_backend", port_query_backend, tFunc(tVoid,tObj), 0); + ADD_FUNCTION ("query_fd", port_query_fd, tFunc(tVoid,tInt), 0); +#ifdef SO_REUSEPORT + ADD_INT_CONSTANT( "SO_REUSEPORT_SUPPORT", SO_REUSEPORT, 0 ); +#endif +#ifdef TCP_FASTOPEN + ADD_INT_CONSTANT( "TCP_FASTOPEN_SUPPORT", TCP_FASTOPEN, 0 ); +#endif set_init_callback(init_port_struct); set_exit_callback(exit_port_struct); port_program = end_program(); add_program_constant( "_port", port_program, 0 ); -} -int fd_from_portobject( struct object *p ) -{ - struct port *po = get_storage( p, port_program ); - if(!po) return -1; - return po->box.fd; } + diff --git a/src/pike_netlib.h b/src/pike_netlib.h index 3358686241..0403d96483 100644 --- a/src/pike_netlib.h +++ b/src/pike_netlib.h @@ -18,6 +18,7 @@ #endif /* HAVE_SYS_SOCKET_H */ #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> +#include <netinet/tcp.h> #endif /* HAVE_NETINET_IN_H */ #ifdef HAVE_WINSOCK2_H -- GitLab