Blame src/microhttpd/mhd_itc.c

Packit 875988
/*
Packit 875988
  This file is part of libmicrohttpd
Packit 875988
  Copyright (C) 2016 Karlson2k (Evgeny Grin)
Packit 875988
Packit 875988
  This library is free software; you can redistribute it and/or
Packit 875988
  modify it under the terms of the GNU Lesser General Public
Packit 875988
  License as published by the Free Software Foundation; either
Packit 875988
  version 2.1 of the License, or (at your option) any later version.
Packit 875988
Packit 875988
  This library is distributed in the hope that it will be useful,
Packit 875988
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 875988
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 875988
  Lesser General Public License for more details.
Packit 875988
Packit 875988
  You should have received a copy of the GNU Lesser General Public
Packit 875988
  License along with this library; if not, write to the Free Software
Packit 875988
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 875988
Packit 875988
*/
Packit 875988
Packit 875988
/**
Packit 875988
 * @file microhttpd/mhd_itc.c
Packit 875988
 * @brief  Implementation of inter-thread communication functions
Packit 875988
 * @author Karlson2k (Evgeny Grin)
Packit 875988
 * @author Christian Grothoff
Packit 875988
 */
Packit 875988
Packit 875988
#include "mhd_itc.h"
Packit 875988
#ifdef HAVE_UNISTD_H
Packit 875988
#include <unistd.h>
Packit 875988
#endif /* HAVE_UNISTD_H */
Packit 875988
#include <fcntl.h>
Packit 875988
#include "internal.h"
Packit 875988
Packit 875988
Packit 875988
#if defined(_MHD_ITC_PIPE)
Packit 875988
#if !defined(_WIN32) || defined(__CYGWIN__)
Packit 875988
Packit 875988
#ifndef HAVE_PIPE2_FUNC
Packit 875988
/**
Packit 875988
 * Change itc FD options to be non-blocking.
Packit 875988
 *
Packit 875988
 * @param itc the inter-thread communication primitive to manipulate
Packit 875988
 * @return non-zero if succeeded, zero otherwise
Packit 875988
 */
Packit 875988
int
Packit 875988
MHD_itc_nonblocking_ (struct MHD_itc_ itc)
Packit 875988
{
Packit 875988
  unsigned int i;
Packit 875988
Packit 875988
  for (i=0;i<2;i++)
Packit 875988
  {
Packit 875988
    int flags;
Packit 875988
Packit 875988
    flags = fcntl (itc.fd[i],
Packit 875988
                   F_GETFL);
Packit 875988
    if (-1 == flags)
Packit 875988
      return 0;
Packit 875988
Packit 875988
    if ( ((flags | O_NONBLOCK) != flags) &&
Packit 875988
         (0 != fcntl (itc.fd[i],
Packit 875988
                      F_SETFL,
Packit 875988
                      flags | O_NONBLOCK)) )
Packit 875988
      return 0;
Packit 875988
  }
Packit 875988
  return !0;
Packit 875988
}
Packit 875988
#endif /* ! HAVE_PIPE2_FUNC */
Packit 875988
#endif /* !_WIN32 || __CYGWIN__ */
Packit 875988
#endif /* _MHD_ITC_EVENTFD ||  _MHD_ITC_PIPE */