pike.git / src / modules / _Stdio / socket.c

version» Context lines:

pike.git/src/modules/_Stdio/socket.c:216:    }       change_fd_for_box (&p->box, fd);    if(cb) assign_accept_cb (p, cb);    p->my_errno=0;    pop_n_elems(args);    push_int(1);   }      /*! @decl int bind(int|string port, void|function accept_callback, @ -  *! void|string ip) +  *! void|string ip, void|string reuse_port)    *!    *! Opens a socket and binds it to port number on the local machine.    *! If the second argument is present, the socket is set to    *! nonblocking and the callback funcition is called whenever    *! something connects to it. The callback will receive the id for    *! this port as argument and should typically call @[accept] to    *! establish a connection.    *!    *! If the optional argument @[ip] is given, @[bind] will try to bind    *! to an interface with that host name or IP number. Omitting this    *! will bind to all available IPv4 addresses; specifying "::" will    *! bind to all IPv4 and IPv6 addresses.    *!    *! If the OS supports TCP_FASTOPEN it is enabled automatically.    *! -  +  *! If the OS supports SO_REUSEPORT it is enabled if the fourth argument is true. +  *!    *! @returns    *! 1 is returned on success, zero on failure. @[errno] provides    *! further details about the error in the latter case.    *!    *! @seealso    *! @[accept], @[set_id]    */   static void port_bind(INT32 args)   {    struct port *p = THIS;
pike.git/src/modules/_Stdio/socket.c:255:    do_close(p);       if(args < 1)    SIMPLE_TOO_FEW_ARGS_ERROR("bind", 1);       if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT &&    (TYPEOF(Pike_sp[-args]) != PIKE_T_STRING ||    Pike_sp[-args].u.string->size_shift))    SIMPLE_BAD_ARG_ERROR("bind", 1, "int|string(8bit)");    -  addr_len = get_inet_addr(&addr, (args > 2 && TYPEOF(Pike_sp[2-args])==PIKE_T_STRING? +  addr_len = get_inet_addr(&addr, +  (args > 2 && TYPEOF(Pike_sp[2-args])==PIKE_T_STRING?    Pike_sp[2-args].u.string->str : NULL),    (TYPEOF(Pike_sp[-args]) == PIKE_T_STRING?    Pike_sp[-args].u.string->str : NULL),    (TYPEOF(Pike_sp[-args]) == PIKE_T_INT?    Pike_sp[-args].u.integer : -1), 0);    INVALIDATE_CURRENT_TIME();       fd=fd_socket(SOCKADDR_FAMILY(addr), SOCK_STREAM, 0);       if(fd < 0)    {    p->my_errno=errno;    pop_n_elems(args);    push_int(0);    return;    } -  + #ifdef SO_REUSEPORT +  if( args > 3 && Pike_sp[3-args].u.integer ) +  { +  int o=1; +  if(fd_setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (char *)&o, sizeof(int)) < 0) +  { +  p->my_errno=errno; +  while (fd_close(fd) && errno == EINTR) {} +  errno = p->my_errno; +  pop_n_elems(args); +  push_int(0); +  return; +  } +  } + #endif   #ifndef __NT__    {    int o=1;    if(fd_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&o, sizeof(int)) < 0)    {    p->my_errno=errno;    while (fd_close(fd) && errno == EINTR) {}    errno = p->my_errno;    pop_n_elems(args);    push_int(0);