Skip to content
Snippets Groups Projects
Select Git revision
  • c43e8cadd02224b249156fd2ff3e44e8f71c7b88
  • master default protected
  • 8.0
  • nt-tools
  • 9.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
41 results

compilation.h

Blame
    • Per Hedbor's avatar
      18cec059
      Some more RAM + binary size optimizations. · 18cec059
      Per Hedbor authored
      o type_stack_mark is no longer inline, saves ~10Kb code size
      
      o The type_stack and pike_type_mark_stack are now allocated on demand
        when possible (using mmap, the pages are allocated when accessed at
        least on macosx and linux)
      
        This saves about 1Mb of RSS in a freshly started pike.
      18cec059
      History
      Some more RAM + binary size optimizations.
      Per Hedbor authored
      o type_stack_mark is no longer inline, saves ~10Kb code size
      
      o The type_stack and pike_type_mark_stack are now allocated on demand
        when possible (using mmap, the pages are allocated when accessed at
        least on macosx and linux)
      
        This saves about 1Mb of RSS in a freshly started pike.
    fd_control.c 2.19 KiB
    /*\
    ||| This file a part of Pike, and is copyright by Fredrik Hubinette
    ||| Pike is distributed as GPL (General Public License)
    ||| See the files COPYING and DISCLAIMER for more information.
    \*/
    #include <sys/types.h>
    #include <sys/ioctl.h>
    #include <sys/socket.h>
    #include "fd_control.h"
    
    #ifndef TESTING
    #include "global.h"
    #include "error.h"
    #else
    #undef DEBUG
    #endif
    
    #ifdef HAVE_FCNTL_H
    #include <fcntl.h>
    #endif
    #ifdef HAVE_SYS_FILIO_H
    #include <sys/filio.h>
    #endif
    #ifdef HAVE_SYS_SOCKIO_H
    #include <sys/sockio.h>
    #endif
    
    void set_nonblocking(int fd,int which)
    {
    #ifdef DEBUG
      if(fd<0 || fd >MAX_OPEN_FILEDESCRIPTORS)
        fatal("Filedescriptor out of range.\n");
    #endif
    
    #ifdef USE_IOCTL_FIONBIO
      ioctl(fd, FIONBIO, &which);
    #else
    
    #ifdef USE_FCNTL_O_NDELAY
      fcntl(fd, F_SETFL, which?O_NDELAY:0);
    #else
    
    #ifdef USE_FCNTL_O_NONBLOCK
      fcntl(fd, F_SETFL, which?O_NONBLOCK:0);
    #else
    
    #ifdef USE_FCNTL_FNDELAY
      fcntl(fd, F_SETFL, which?FNDELAY:0);
    #else
    #error Do not know how to set your filedescriptors nonblocking.
    #endif
    #endif
    #endif
    #endif
    }
    
    int query_nonblocking(int fd)
    {
    #ifdef DEBUG
      if(fd<0 || fd > MAX_OPEN_FILEDESCRIPTORS)
        fatal("Filedescriptor out of range.\n");
    #endif
    
    #ifdef USE_IOCTL_FIONBIO
      /* I don't know how to query this!!!! */
      return 0;
    #else
    
    #ifdef USE_FCNTL_O_NDELAY
      return fcntl(fd, F_GETFL, 0) & O_NDELAY;
    #else
    
    #ifdef USE_FCNTL_O_NONBLOCK
      return fcntl(fd, F_GETFL, 0) & O_NONBLOCK;
    #else
    
    #ifdef USE_FCNTL_FNDELAY
      return fcntl(fd, F_GETFL, 0) & FNDELAY;
    #else
    #error Do not know how to set your filedescriptors nonblocking.
    #endif
    #endif
    #endif
    #endif
    }
    
    int set_close_on_exec(int fd, int which)
    {
      return fcntl(fd, F_SETFD, !!which);
    }
    
    #ifdef TESTING
    
    #include <signal.h>
    #ifdef HAVE_UNISTD_H
    #include <unistd.h>
    #endif
    /* a part of the autoconf thingy */
    
    RETSIGTYPE sigalrm_handler0(int tmp) { exit(0); }
    RETSIGTYPE sigalrm_handler1(int tmp) { exit(1); }
    
    main()
    {
      int tmp[2];
      char foo[1000];
    
      tmp[0]=0;
      tmp[1]=0;
    #ifdef HAVE_PIPE
      pipe(tmp);
    #endif
      
      set_nonblocking(tmp[0],1);
      signal(SIGALRM, sigalrm_handler1);
      alarm(1);
      read(tmp[0],foo,999);
      set_nonblocking(tmp[0],0);
      signal(SIGALRM, sigalrm_handler0);
      alarm(1);
      read(tmp[0],foo,999);
      exit(1);
    }
    #endif