Exemplo n.º 1
0
int
TAO_Connection_Handler::set_socket_option (ACE_SOCK &sock,
                                           int snd_size,
                                           int rcv_size)
{
#if !defined (ACE_LACKS_SO_SNDBUF)
  if (snd_size != 0
      && sock.set_option (SOL_SOCKET,
                          SO_SNDBUF,
                          (void *) &snd_size,
                          sizeof (snd_size)) == -1)
  {
    if (TAO_debug_level)
      TAOLIB_DEBUG ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) - Connection_Handler::")
                  ACE_TEXT ("set_socket_option, setting SO_SNDBUF failed ")
                  ACE_TEXT ("'%m'\n")));

    if (errno != ENOTSUP)
      return -1;
  }
#endif /* !ACE_LACKS_SO_SNDBUF */

#if !defined (ACE_LACKS_SO_RCVBUF)
  if (rcv_size != 0
      && sock.set_option (SOL_SOCKET,
                          SO_RCVBUF,
                          (void *) &rcv_size,
                          sizeof (int)) == -1)
  {
      if (TAO_debug_level)
        TAOLIB_ERROR ((LM_ERROR,
                    ACE_TEXT ("TAO (%P|%t) - Connection_Handler::")
                    ACE_TEXT ("set_socket_option, setting SO_RCVBUF failed ")
                    ACE_TEXT ("'%m'\n")));

    if (errno != ENOTSUP)
      return -1;
  }
#endif /* !ACE_LACKS_SO_RCVBUF */

#if defined (ACE_LACKS_SO_SNDBUF) && defined (ACE_LACKS_SO_RCVBUF)
  ACE_UNUSED_ARG (snd_size);
  ACE_UNUSED_ARG (rcv_size);
#endif

  // Set the close-on-exec flag for that file descriptor. If the
  // operation fails we are out of luck (some platforms do not support
  // it and return -1).
  (void) sock.enable (ACE_CLOEXEC);

  return 0;
}
Exemplo n.º 2
0
/** \brief Closes a socket and deregisters it from the reactor
 *
 * \ingroup group__library__network
 *
 * \param sk Reference to the socket to close
 * \param reactor Reactor from which the socket will be deregistered. May be
 *   NULL.
 *
 * \return true if the socket was previously closed, false otherwise. There
 *   is no error return
 *
 * Usage is simple. Just specify the socket to close and, optionally, the
 * reactor with which it is registered.
 *
\code

// close and deregister m_upstreamPeer and m_downstreamPeer (both ACE_SOCK_Stream)
acestl::close_and_deregister(m_peer, reactor());

\endcode
 */
inline as_bool_t close_and_deregister(ACE_SOCK &sk, ACE_Reactor *reactor)
{
    if(ACE_INVALID_HANDLE == sk.get_handle())
    {
        return false;
    }

    if(NULL != reactor)
    {
        const ACE_Reactor_Mask close_mask   =   ACE_Event_Handler::ALL_EVENTS_MASK
                                            |   ACE_Event_Handler::DONT_CALL;

        reactor->remove_handler(sk.get_handle(), close_mask);
    }

    sk.close();

    return true;
}
Exemplo n.º 3
0
void
DataLink::set_dscp_codepoint(int cp, ACE_SOCK& socket)
{
  /**
   * The following IPV6 code was lifted in spirit from the RTCORBA
   * implementation of setting the DiffServ codepoint.
   */
  int result = 0;

  // Shift the code point up to bits, so that we only use the DS field
  int tos = cp << 2;

  const char* which = "IPV4 TOS";
#if defined (ACE_HAS_IPV6)
  ACE_INET_Addr local_address;

  if (socket.get_local_addr(local_address) == -1) {
    return;

  } else if (local_address.get_type() == AF_INET6)
#if !defined (IPV6_TCLASS)
  {
    if (DCPS_debug_level > 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("(%P|%t) ERROR: DataLink::set_dscp_codepoint() - ")
                 ACE_TEXT("IPV6 TCLASS not supported yet, not setting codepoint %d.\n"),
                 cp));
    }

    return;
  }

#else /* IPV6_TCLASS */
  {
    which = "IPV6 TCLASS";
    result = socket.set_option(
               IPPROTO_IPV6,
               IPV6_TCLASS,
               &tos,
               sizeof(tos));

  } else // This is a bit tricky and might be hard to follow...