コード例 #1
0
int
ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io,
			      const ACE_SPIPE_Addr &remote_sap,
			      ACE_Time_Value *timeout,
			      const ACE_Addr & /* local_sap */,
			      int /* reuse_addr */,
			      int flags,
			      int perms)
{
  ACE_TRACE ("ACE_SPIPE_Connector::connect");

  // Make darn sure that the O_CREAT flag is not set!
#if ! defined (ACE_PSOS_DIAB_MIPS)
  ACE_CLR_BITS (flags, O_CREAT);
# endif /* !ACE_PSOS_DIAB_MIPS */
  ACE_HANDLE handle = ACE_Handle_Ops::handle_timed_open (timeout,
                                                         remote_sap.get_path_name (),
                                                         flags, perms);
  new_io.set_handle (handle);
  new_io.remote_addr_ = remote_sap; // class copy.

#if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
  DWORD pipe_mode = PIPE_READMODE_MESSAGE | PIPE_WAIT;

  // Set named pipe mode and buffering characteristics.
  if (handle != ACE_INVALID_HANDLE)
    return ::SetNamedPipeHandleState (handle,
				      &pipe_mode,
				      NULL,
				      NULL);
#endif
  return handle == ACE_INVALID_HANDLE ? -1 : 0;
}
コード例 #2
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  parse_arguments (argc, argv);

  ACE_SPIPE_Stream spipe;
  ACE_SPIPE_Connector con;

  if (con.connect (spipe,
                   ACE_SPIPE_Addr (rendezvous_spipe)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Cannot open %s for requesting a new ")
                       ACE_TEXT ("communication channel in %p\n"),
                       rendezvous_spipe,
                       ACE_TEXT ("local_spipe_client_test")),
                      -1);

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Mem_Map mmap (file_name);
  void *cp;

  if (mmap (cp) == -1)
  //FUZZ: enable check_for_lack_ACE_OS
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("mmap")),
                      -1);

  // Next, send the file's contents.

  ACE_Str_Buf msg (cp, int (mmap.size ()));

  if (spipe.send ((ACE_Str_Buf *) 0, &msg) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("%p\n"),
                       ACE_TEXT ("send")),
                      -1);
  return 0;
}
コード例 #3
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  parse_arguments (argc, argv);

  ACE_SPIPE_Stream spipe;
  ACE_SPIPE_Connector con;

  if (con.connect (spipe,
                   ACE_SPIPE_Addr (rendezvous_spipe)) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
		       "Cannot open %s for requesting a new communication channel"
		       " in local_spipe_client_test.\n",
                       rendezvous_spipe),
                      -1);

  ACE_Mem_Map mmap (file_name);
  void *cp;

  if (mmap (cp) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "mmap"),
                      -1);

  // Next, send the file's contents.

  ACE_Str_Buf msg (cp, int (mmap.size ()));

  if (spipe.send ((ACE_Str_Buf *) 0, &msg) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "send"),
                      -1);
  return 0;
}
コード例 #4
0
int
ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io,
                              const ACE_SPIPE_Addr &remote_sap,
                              ACE_Time_Value *timeout,
                              const ACE_Addr & /* local_sap */,
                              int /* reuse_addr */,
                              int flags,
                              int perms,
                              LPSECURITY_ATTRIBUTES sa,
                              int pipe_mode)
{
  ACE_TRACE ("ACE_SPIPE_Connector::connect");
  // Make darn sure that the O_CREAT flag is not set!
  ACE_CLR_BITS (flags, O_CREAT);

  ACE_HANDLE handle;

  ACE_UNUSED_ARG (pipe_mode);
#if defined (ACE_WIN32) && \
   !defined (ACE_HAS_PHARLAP) && !defined (ACE_HAS_WINCE)
  // We need to allow for more than one attempt to connect,
  // calculate the absolute time at which we give up.
  ACE_Time_Value absolute_time;
  if (timeout != 0)
    absolute_time = ACE_OS::gettimeofday () + *timeout;

  // Loop until success or failure.
  for (;;)
    {
      handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa);
      if (handle != ACE_INVALID_HANDLE)
        // Success!
        break;

      // Check if we have a busy pipe condition.
      if (::GetLastError() != ERROR_PIPE_BUSY)
        // Nope, this is a failure condition.
        break;

      // This will hold the time out value used in the ::WaitNamedPipe
      // call.
      DWORD time_out_value;

      // Check if we are to block until we connect.
      if (timeout == 0)
        // Wait for as long as it takes.
        time_out_value = NMPWAIT_WAIT_FOREVER;
      else
        {
          // Calculate the amount of time left to wait.
          ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ());
          // Check if we have run out of time.
          if (relative_time <= ACE_Time_Value::zero)
            {
              // Mimick the errno value returned by
              // ACE::handle_timed_open.
              if (*timeout == ACE_Time_Value::zero)
                errno = EWOULDBLOCK;
              else
                errno = ETIMEDOUT;
              // Exit the connect loop with the failure.
              break;
            }
          // Get the amount of time remaining for ::WaitNamedPipe.
          time_out_value = relative_time.msec ();

        }

      // Wait for the named pipe to become available.
      ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (),
                              time_out_value);

      // Regardless of the return value, we'll do one more attempt to
      // connect to see if it is now available and to return
      // consistent error values.
    }

  // Set named pipe mode if we have a valid handle.
  if (handle != ACE_INVALID_HANDLE)
    {
      // Check if we are changing the pipe mode from the default.
      if (pipe_mode != (PIPE_READMODE_BYTE | PIPE_WAIT))
        {
          DWORD dword_pipe_mode = pipe_mode;
          if (!::SetNamedPipeHandleState (handle,
                                          &dword_pipe_mode,
                                          0,
                                          0))
            {
              // We were not able to put the pipe into the requested
              // mode.
              ACE_OS::close (handle);
              handle = ACE_INVALID_HANDLE;
            }
        }
    }
#else /* ACE_WIN32 && !ACE_HAS_PHARLAP */
  handle = ACE::handle_timed_open (timeout,
                                              remote_sap.get_path_name (),
                                              flags, perms, sa);
#endif /* !ACE_WIN32 || ACE_HAS_PHARLAP || ACE_HAS_WINCE */

  new_io.set_handle (handle);
  new_io.remote_addr_ = remote_sap; // class copy.

  return handle == ACE_INVALID_HANDLE ? -1 : 0;
}
コード例 #5
0
int
ACE_SPIPE_Acceptor::accept (ACE_SPIPE_Stream &new_io,
                            ACE_SPIPE_Addr *remote_addr,
                            ACE_Time_Value *timeout,
                            bool restart,
                            bool reset_new_handle)
{
  ACE_TRACE ("ACE_SPIPE_Acceptor::accept");
  ACE_UNUSED_ARG (reset_new_handle);

#if defined (ACE_HAS_STREAM_PIPES)
  strrecvfd r_handle;

  // Note that if THIS->MILLI_SECOND_DELAY == -1 we block on
  // ACE_OS::ioctl (). Otherwise, we will wait for the desired number
  // of milli seconds using ACE_OS::poll.

  if (timeout != 0 &&
      ACE::handle_timed_accept (this->get_handle (),
                                timeout,
                                restart) == -1)
    return -1;
  else if (ACE_OS::ioctl (this->get_handle (),
                          I_RECVFD,
                          &r_handle) == -1)
    return -1;

  new_io.set_handle (r_handle.fd);
  new_io.local_addr_ = this->local_addr_;
  new_io.remote_addr_.set_size (sizeof r_handle.gid + sizeof r_handle.uid);
  new_io.remote_addr_.group_id (r_handle.gid);
  new_io.remote_addr_.user_id (r_handle.uid);

  // This is for compatibility with ACE_SOCK_Acceptor and
  // ACE_TLI_Acceptor.
  if (remote_addr != 0)
    *remote_addr = new_io.remote_addr_;

  return 0;
#elif defined (ACE_HAS_WIN32_NAMED_PIPES)
  ACE_UNUSED_ARG (restart);
  ACE_UNUSED_ARG (remote_addr);

  // Check to see if we have a valid pipe
  if (this->pipe_handle_ == ACE_INVALID_HANDLE)
    return -1;

  // open () started the Connect in asynchronous mode.  Wait for the event
  // in the OVERLAPPED structure to be signalled, then grab the status.
  if (this->already_connected_ == 0)
    {
      if (timeout != 0)
        {
          ACE_Time_Value abstime (ACE_OS::gettimeofday () + *timeout);
          if (this->event_.wait (&abstime) == -1)
            return -1;
        }
      else
        if (this->event_.wait () == -1)
          return -1;

      // Should be here with the ConnectNamedPipe operation complete.
      // Steal the already_connected_ flag to record the results.
      DWORD unused;
      this->already_connected_ = ::GetOverlappedResult (this->pipe_handle_,
                                                        &this->overlapped_,
                                                        &unused,
                                                        FALSE);
    }

  if (this->already_connected_)
    {
      new_io.set_handle (this->pipe_handle_);
      this->pipe_handle_ = ACE_INVALID_HANDLE;
      new_io.local_addr_ = this->local_addr_;

      // Create a new instance of the pipe for the next connection.
      this->create_new_instance ();
      return 0;
    }
  return -1;
#else
  ACE_UNUSED_ARG (restart);
  ACE_UNUSED_ARG (timeout);
  ACE_UNUSED_ARG (remote_addr);
  ACE_UNUSED_ARG (new_io);
  ACE_NOTSUP_RETURN (-1);
#endif /* ACE_HAS_STREAM_PIPES */
}