示例#1
0
int
ACE_ATM_Acceptor::accept (ACE_ATM_Stream &new_sap,
                          ACE_Addr *remote_addr,
                          ACE_Time_Value *timeout,
                          bool restart,
                          bool reset_new_handle,
                          ACE_ATM_Params params,
                          ACE_ATM_QoS qos)
{
  ACE_TRACE ("ACE_ATM_Acceptor::accept");
#if defined (ACE_HAS_FORE_ATM_XTI)
  ATM_QoS optbuf = qos.get_qos ();

  return (acceptor_.accept (new_sap.get_stream (),
                           remote_addr,
                           timeout,
                           restart,
                           reset_new_handle,
                           params.get_rw_flag (),
                           params.get_user_data (),
                           &optbuf));
#elif defined (ACE_HAS_FORE_ATM_WS2)
  ACE_HANDLE n_handle;
  ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
  struct sockaddr_atm *cli_addr
    = (struct sockaddr_atm *)remote_addr -> get_addr ();
  int caddr_len = sizeof (struct sockaddr_atm);

  do {
    n_handle = ACE_OS::accept (s_handle,
                               reinterpret_cast<struct sockaddr *> (cli_addr),
                              &caddr_len);
  } while (n_handle == ACE_INVALID_HANDLE && errno == EINTR);

 ((ACE_ATM_Addr *)remote_addr) -> set (cli_addr,
 ((ACE_ATM_Addr *)remote_addr) -> get_selector ());
 ((ACE_IPC_SAP *)&new_sap) -> set_handle (n_handle);

  return 0;
#elif defined (ACE_HAS_LINUX_ATM)
  ACE_UNUSED_ARG (params);

  ACE_HANDLE s_handle = ((ACE_SOCK_Acceptor *) this) -> get_handle ();
  struct atm_qos accept_qos = qos.get_qos ();

  if (ACE_OS::setsockopt (s_handle,
                         SOL_ATM,
                         SO_ATMQOS,
                         reinterpret_cast<char*> (&accept_qos),
                         sizeof (accept_qos)) < 0) {
    ACE_OS::printf ("Acceptor (accept): error setting Qos");
  }

  return (acceptor_.accept (new_sap.get_stream (),
                          remote_addr,
                          timeout,
                          restart,
                          reset_new_handle));
#else
  ACE_UNUSED_ARG (new_sap);
  ACE_UNUSED_ARG (remote_addr);
  ACE_UNUSED_ARG (timeout);
  ACE_UNUSED_ARG (restart);
  ACE_UNUSED_ARG (reset_new_handle);
  ACE_UNUSED_ARG (params);
  ACE_UNUSED_ARG (qos);
  return 0;
#endif /* ACE_HAS_FORE_ATM_XTI */
}
示例#2
0
int
ACE_ATM_Connector::connect (ACE_ATM_Stream &new_stream,
                            const ACE_ATM_Addr &remote_sap,
                            ACE_ATM_Params params,
                            ACE_ATM_QoS options,
                            ACE_Time_Value *timeout,
                            const ACE_ATM_Addr &local_sap,
                            int reuse_addr,
                            int flags,
                            int perms)
{
  ACE_TRACE ("ACE_ATM_Connector::connect");
#if defined (ACE_HAS_FORE_ATM_XTI)
  return connector_.connect(new_stream.get_stream(),
                            remote_sap,
                            timeout,
                            local_sap,
                            reuse_addr,
                            flags,
                            perms,
                            params.get_device(),
                            params.get_info(),
                            params.get_rw_flag(),
                            params.get_user_data(),
                            &options.get_qos());
#elif defined (ACE_HAS_FORE_ATM_WS2)
  ACE_DEBUG(LM_DEBUG,
            ACE_TEXT ("ATM_Connector(connect): set QoS parameters\n" ));

  ACE_HANDLE s = new_stream.get_handle();
  struct sockaddr_atm *saddr = ( struct sockaddr_atm *)remote_sap.get_addr();
  ACE_QoS cqos = options.get_qos();

  ACE_QoS_Params qos_params = ACE_QoS_Params(0,
                                             0,
                                             &cqos,
                                             0,
                                             0);

  ACE_DEBUG(LM_DEBUG,
            ACE_TEXT ("ATM_Connector(connect): connecting...\n"));

  int result = ACE_OS::connect( s,
                                ( struct sockaddr *)saddr,
                                sizeof( struct sockaddr_atm ),
                                qos_params );

  if( result != 0 )
    ACE_OS::printf( "ATM_Connector(connect): connection failed, %d\n",
                    ::WSAGetLastError());

  return result;
#elif defined (ACE_HAS_LINUX_ATM)
  ACE_UNUSED_ARG (params);
  ACE_UNUSED_ARG (timeout);
  ACE_UNUSED_ARG (reuse_addr);
  ACE_UNUSED_ARG (perms);
  ACE_UNUSED_ARG (flags);

  ACE_HANDLE handle = new_stream.get_handle();
  ATM_QoS qos =options.get_qos();
  ATM_Addr *local_addr=(ATM_Addr*)local_sap.get_addr(),
    *remote_addr=(ATM_Addr*)remote_sap.get_addr();

  if(ACE_OS::setsockopt(handle,
                         SOL_ATM,
                         SO_ATMSAP,
                         reinterpret_cast<char*> (&(local_addr->atmsap)),
                         sizeof(local_addr->atmsap)) < 0) {
    ACE_OS::printf( "ATM_Connector(connect): unable to set atmsap %d\nContinuing...",
                    errno);
  }
  if(ACE_OS::setsockopt(handle,
                         SOL_ATM,
                         SO_ATMQOS,
                         reinterpret_cast<char*> (&qos),
                         sizeof(qos)) < 0) {
    ACE_DEBUG((LM_DEBUG,ACE_TEXT ("ATM_Connector(connect): unable to set qos %d\n"),
               errno));
    return -1;
  }

  int result = ACE_OS::connect(handle,
                               (struct sockaddr *)&(remote_addr->sockaddratmsvc),
                               sizeof( remote_addr->sockaddratmsvc));

  if( result != 0 )
    ACE_DEBUG(LM_DEBUG,
              ACE_TEXT ("ATM_Connector(connect): connection failed, %d\n"),
              errno);

  return result;
#else
  ACE_UNUSED_ARG (new_stream);
  ACE_UNUSED_ARG (remote_sap);
  ACE_UNUSED_ARG (params);
  ACE_UNUSED_ARG (options);
  ACE_UNUSED_ARG (timeout);
  ACE_UNUSED_ARG (local_sap);
  ACE_UNUSED_ARG (reuse_addr);
  ACE_UNUSED_ARG (flags);
  ACE_UNUSED_ARG (perms);
  return 0;
#endif /* ACE_HAS_FORE_ATM_XTI || ACE_HAS_FORE_ATM_WS2 || ACE_HAS_LINUX_ATM */
}
示例#3
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if ( argc < 2 )
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Usage: %s <rate> <PDU> <session> <host> <selector> [ host sel ] ...\n"
                       "\tUse 0 for default values\n",
                       argv[0]),
                      1);

  int rate = ACE_OS::atoi( argv[ 1 ]);
  rate = ( rate != 0 ) ? rate : 170000;
  int pdu_size = ACE_OS::atoi( argv[ 2 ]) * 1024;
  pdu_size = ( pdu_size != 0 ) ? pdu_size : 8192;
  int session = ACE_OS::atoi( argv[ 3 ]);
  session = ( session != 0 ) ? session : 100;

  ACE_OS::printf( "ATM_Client: rate: %d c/s, PDU: %dB, session: %d pkts\n",
    rate, pdu_size, session );

  // Record all hosts/selectors
  ACE_ATM_Addr hosts[ MAX_LEAVES ];
  int num_leaves = argc / 2 - 2;

  ACE_OS::printf( "ATM_Client: Connecting to ...\n" );
  for ( int i = 0; i < num_leaves; i++ ) {
    hosts[ i ].set( argv[ i*2 + 4 ],
                    ( argv[ i*2 + 5 ] != 0 )
                      ? ACE_OS::atoi( argv[ i*2 + 5 ]) : ACE_ATM_Addr::DEFAULT_SELECTOR );
    ACE_OS::printf( "ATM_Client: leaf: %s (%s), sel: %d\n",
                    argv[ i*2 + 4 ],
                    hosts[ i ].addr_to_string(),
                    hosts[ i ].get_selector());
  }

  // The timeout really gets ignored since FORE's drivers don't work when
  //  ioctl or fcntl calls are made on the transport id/file descriptor
  int timeout = ACE_DEFAULT_TIMEOUT;
  char buf[BUFSIZ];
  ACE_ATM_Stream atm_stream;

  char hostname[ MAXNAMELEN ];
  ACE_OS::hostname( hostname, MAXNAMELEN );
  ACE_ATM_Addr local_addr( hostname, hosts[ 0 ].get_selector());

  ACE_OS::printf( "ATM_Client: local host: %s(%s)\n",
    hostname, local_addr.addr_to_string());

  // In order to construct connections options the file handle is
  // needed.  Therefore, we need to open the ATM_Stream before we
  // construct the options.
  ACE_OS::printf( "ATM_Client: to open a stream\n" );
  if (atm_stream.open () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open failed"),
                      1);

  ACE_DEBUG ((LM_DEBUG,
              "ATM_Client: starting non-blocking connection\n"));

  // Initiate timed, non-blocking connection with server.
  ACE_ATM_Connector con;

  // Construct QoS options - currently FORE only supports bandwidth
  ACE_OS::printf( "ATM_Client: specify cell rate at %d c/s\n", rate );
  ACE_ATM_QoS qos;
  qos.set_rate(atm_stream.get_handle (),
               rate,
               ACE_ATM_QoS::OPT_FLAGS_CPID);

  if ( num_leaves == 1 ) {
    // Point-to-point connection
    // Not sure why but reuse_addr set to true/1 causes problems for
    // FORE/XTI/ATM - this is now handled in ACE_ATM_Connector::connect()
    ACE_OS::printf( "ATM_Client: to open a connection \n" );
    ACE_ATM_Params params = ACE_ATM_Params();
    if (con.connect (atm_stream,
                     hosts[ 0 ],
                     params,
                     qos,
                     (ACE_Time_Value *) &ACE_Time_Value::zero,
                     local_addr,
                     0,
                     0 ) == -1) {
      if (errno != EWOULDBLOCK)
	      ACE_ERROR_RETURN ((LM_ERROR,
                          "%p\n",
                          "ATM_Client: connection failed"),
                          1);

      ACE_DEBUG ((LM_DEBUG,
                    "ATM_Client: starting timed connection\n"));

      // Check if non-blocking connection is in progress, and wait up
      // to timeout seconds for it to complete.
      ACE_Time_Value tv (timeout);

      ACE_OS::printf( "ATM_Client: connection completed\n" );
      if (con.complete (atm_stream,
                        &hosts[ 0 ],
                        &tv) == -1)
		    ACE_ERROR_RETURN ((LM_ERROR,
                          "%p\n",
                          "ATM_Client: connection failed"),
                          1);
      else
		    ACE_DEBUG ((LM_DEBUG,
                   "ATM_Client: connected to %s\n",
		               hosts[ 0 ].addr_to_string()));
    }
  } else {
    // Point-to-multipoint connection
    for ( int i = 0; i < num_leaves; i++ ) {
      con.add_leaf( atm_stream,
                    hosts[ i ],
                    i,
                    0 );

    }
  } /* if num_leaves == 1 */

  ACE_UINT16 vpi, vci;
  atm_stream.get_vpi_vci(vpi, vci);
  ACE_DEBUG ((LM_DEBUG,
              "ATM_Client: connected to VPI %d VCI %d\n",
              vpi, vci));

  // Send data to server (correctly handles "incomplete writes").

  int s_bytes;
  int total;
  int xmit = 0;
  ACE_High_Res_Timer timer;
  ACE_Time_Value elapsed;
  double real_time;
  double actual_rate;

  for ( ;; ) {
    total = 0;

    timer.start_incr();

    for ( ;; ) {
      s_bytes = atm_stream.send_n( buf, BUFSIZ, 0 );
      if ( s_bytes == -1 )
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "send_n"),
                           1);

      total += s_bytes;

      if ( total >= session * pdu_size )
        break;
    }

    timer.stop_incr();
    timer.elapsed_time_incr( elapsed );
    real_time = elapsed.sec() * ACE_ONE_SECOND_IN_USECS + elapsed.usec();
    xmit += total;
    actual_rate = ( double )xmit * ( double )8 / real_time;

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) bytes = %d, usec = %f, rate = %0.00f Mbps\n"),
                xmit,
                real_time,
                actual_rate < 0 ? 0 : actual_rate ));
  }

  // Explicitly close the connection.
  ACE_OS::printf( "ATM_Client: close connection\n" );
  if (atm_stream.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                       -1);
  return 0;
}
示例#4
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  if (argc < 2)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Usage: %s [-s selector] hostname [QoS in KB/sec]\n",
                       argv[0]),
                      1);

  unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR;
  int selector_specified = 0;
  extern int optind;
  int opt;
  while ((opt = ACE_OS::getopt (argc, argv, "s:?h")) != EOF)
    {
    switch(opt)
      {
      case 's':
        selector = ACE_OS::atoi (optarg);
        selector_specified = 1;
        break;
      case '?':
      case 'h':
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Usage: %s hostname [-s selector] [QoS in KB/s]\n",
                           argv[0]),
                          1);
      } // switch
    } // while getopt

  const char *host = argv[optind];

  int rate = (argc == 3) ? ACE_OS::atoi (argv[2]) :
    (argc == 5) ? ACE_OS::atoi (argv[4]) : 0;
  // The timeout really gets ignored since FORE's drivers don't work when
  //  ioctl or fcntl calls are made on the transport id/file descriptor
  int timeout = ACE_DEFAULT_TIMEOUT;

  char buf[BUFSIZ];

  ACE_TLI_Stream cli_stream;

  ACE_ATM_Addr remote_addr (host);
  if (selector_specified)
    remote_addr.set_selector(selector);
  char hostname[MAXNAMELEN];
  ACE_OS::hostname(hostname, MAXNAMELEN);
  ACE_ATM_Addr local_addr (hostname);

  // In order to construct connections options the file handle is
  // needed.  Therefore, we need to open the TLI_Stream before we
  // construct the options.
  if (cli_stream.open (ACE_XTI_ATM_DEVICE, O_RDWR, 0) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open failed"),
                      1);

  ACE_DEBUG ((LM_DEBUG,
              "starting non-blocking connect\n"));

  // Initiate timed, non-blocking connection with server.
  ACE_TLI_Connector con;

  // Construct QoS options - currently FORE only supports bandwidth
  ACE_ATM_QoS qos;
  qos.set_rate(cli_stream.get_handle (),
               rate,
               ACE_ATM_QoS::OPT_FLAGS_CPID);

  struct netbuf optbuf = qos.get_qos();
//   long optlen = 0;
//   char *options = remote_addr.construct_options (cli_stream.get_handle (),
//                                                  rate,
//                                                  ACE_ATM_Addr::OPT_FLAGS_CPID,
//                                                  &optlen);
//   struct netbuf optbuf;
//   optbuf.len = optlen;
//   optbuf.buf = options;

  // Not sure why but reuse_addr set to true/1 causes problems for
  // FORE/XTI/ATM - this is now handled in ACE_TLI_Connector::connect()
  if (con.connect (cli_stream,
                   remote_addr,
                   (ACE_Time_Value *) &ACE_Time_Value::zero,
                   local_addr,
                   1,
                   O_RDWR,
                   0,
                   ACE_XTI_ATM_DEVICE,
                   0,
                   1,
                   0,
                   &optbuf) == -1)
    {
      if (errno != EWOULDBLOCK)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "connection failed"),
                          1);

      ACE_DEBUG ((LM_DEBUG,
                  "starting timed connect\n"));

      // Check if non-blocking connection is in progress, and wait up
      // to timeout seconds for it to complete.
      ACE_Time_Value tv (timeout);

      if (con.complete (cli_stream,
                        &remote_addr,
                        &tv) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "connection failed"),
                          1);
      else
        ACE_DEBUG ((LM_DEBUG,
                    "connected to %s\n",
                    remote_addr.addr_to_string ()));
    }

  // Send data to server (correctly handles "incomplete writes").

  for (int r_bytes;
       (r_bytes = ACE_OS::read (ACE_STDIN, buf, sizeof buf)) > 0;
       )
    if (cli_stream.send_n (buf,
                           r_bytes,
                           0) == -1)
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "send_n"),
                        1);

  // Explicitly close the connection.
  if (cli_stream.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                      -1);
  return 0;
}