//////////////////////////////////////////////////////////////////////////////// /// @brief collection of socket functions /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2012 triagens GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler /// @author Copyright 2008-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #include "socket-utils.h" #ifdef TRI_HAVE_LINUX_SOCKETS #include #include #include #include #include #include #include #include #endif #include "BasicsC/logging.h" #include "BasicsC/locks.h" // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Sockets /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Sockets /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief sets non-blocking mode for a socket //////////////////////////////////////////////////////////////////////////////// #ifdef TRI_HAVE_WIN32_NON_BLOCKING bool TRI_SetNonBlockingSocket (socket_t fd) { DWORD ul = 1; return ioctlsocket(fd, FIONBIO, &ul) == SOCKET_ERROR ? false : true; } #else bool TRI_SetNonBlockingSocket (socket_t fd) { long flags = fcntl(fd, F_GETFL, 0); if (flags < 0) { return false; } flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK); if (flags < 0) { return false; } return true; } #endif //////////////////////////////////////////////////////////////////////////////// /// @brief sets close-on-exit for a socket //////////////////////////////////////////////////////////////////////////////// #ifdef TRI_HAVE_WIN32_CLOSE_ON_EXEC bool TRI_SetCloseOnExecSocket (socket_t fd) { return true; } #else bool TRI_SetCloseOnExecSocket (socket_t fd) { long flags = fcntl(fd, F_GETFD, 0); if (flags < 0) { return false; } flags = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); if (flags < 0) { return false; } return true; } #endif //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- MODULE // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // --SECTION-- public functions // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Sockets /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief initialises the sockets components //////////////////////////////////////////////////////////////////////////////// void TRI_InitialiseSockets (void) { } //////////////////////////////////////////////////////////////////////////////// /// @brief shut downs the sockets components //////////////////////////////////////////////////////////////////////////////// void TRI_ShutdownSockets (void) { } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)" // End: