pike.git / src / fd_control.c

version» Context lines:

pike.git/src/fd_control.c:105:   #error Do not know how to set your filedescriptors nonblocking.   #endif      #endif    } while(ret <0 && errno==EINTR);    return ret;   }      PMOD_EXPORT int query_nonblocking(int fd)   { -  int ret; +  int ret = 0;   #ifdef PIKE_DEBUG    if(fd<0)    Pike_fatal("Filedescriptor out of range.\n");   #endif    -  do -  { +    #ifdef FCNTL_NBFLAG -  ret = fcntl(fd, F_GETFL, 0) & FCNTL_NBFLAG; - #else -  return 0; - #endif +  do { +  ret = fcntl(fd, F_GETFL, 0);    } while(ret <0 && errno==EINTR); -  +  return ret & FCNTL_NBFLAG; + #else    return ret; -  + #endif   }      /* The following code doesn't link without help, and    * since it isn't needed by the nonblocking test, we    * can safely disable it.    */   #ifndef TESTING      #ifndef FD_CLOEXEC   #define FD_CLOEXEC 1
pike.git/src/fd_control.c:149:      static void grow_fds_to_close(void)   {    if(!fds_to_close_size)    fds_to_close_size = 1;    fds_to_close_size *= 2;    fds_to_close = realloc( fds_to_close, sizeof( int ) * fds_to_close_size );    if(!fds_to_close)    Pike_fatal("Out of memory in fd_control::grow_fds_to_close()\n"    "Tried to allocate %d fd_datum structs\n", fds_to_close_size); -  MEMSET( fds_to_close+(fds_to_close_size/2), 0, fds_to_close_size*sizeof(int)/2 ); +  memset( fds_to_close+(fds_to_close_size/2), 0, fds_to_close_size*sizeof(int)/2 );   }      void do_close_on_exec(void)   {    int i;    for(i=0; i < num_fds_to_close; i++) {    while( fd_close(fds_to_close[i]) <0 && errno==EINTR) ;    }    num_fds_to_close = 0;   }
pike.git/src/fd_control.c:217:    while (fds_to_close[i] == fd && (i < num_fds_to_close)) {    fds_to_close[i] = fds_to_close[--num_fds_to_close];    }    }    return(0);    }    return 0;   #endif /* !HAVE_BROKEN_F_SETFD */   }    + #ifndef HAVE_ACCEPT4 + int accept4(int fd, struct sockaddr *addr, ACCEPT_SIZE_T *addrlen, int flags) + { +  fd = fd_accept(fd, addr, addrlen); +  if (!flags || (fd < 0)) return fd; +  if (((flags & SOCK_NONBLOCK) && (set_nonblocking(fd, 1) < 0)) || +  ((flags & SOCK_CLOEXEC) && (set_close_on_exec(fd, 1) < 0))) { +  int e = errno; +  fd_close(fd); +  errno = e; +  return -1; +  } +  return fd; + } + #endif /* !HAVE_ACCEPT4 */ +    #endif /* !TESTING */      #ifdef TESTING         #if defined(HAVE_WINSOCK_H) && defined(USE_IOCTLSOCKET_FIONBIO)   int main()   {    exit(0);   }