Ejemplo n.º 1
0
Archivo: peer.c Proyecto: R7R8/simgrid
/** Peer function  */
int peer(int argc, char *argv[])
{
  float start_time, end_time;
  peer_t p = xbt_new(s_peer_t, 1);
  msg_error_t status;

  XBT_DEBUG("peer");

  peer_init(p, argc, argv);
  start_time = MSG_get_clock();
  status = peer_wait_for_message(p);
  peer_shutdown(p);
  end_time = MSG_get_clock();
  peer_print_stats(p, end_time - start_time);
  peer_delete(p);

  return status;
}
Ejemplo n.º 2
0
void CTorrent::clientError(const char *activity, int cs) 
{
    int i, j;
    char buf[128];
    btContext *ctx = &m_Context;

    const char *err = "connection closed";
    btPeer *p = ctx->sockpeer[cs];
    if (p->ios.error != 0) err = bts_strerror( p->ios.error);

    /* errors on a socket */
    //sprintf( buf, "%d: Peer %s shutdown %s (%s)", cs, inet_ntoa(ctx->sockpeer[cs]->sa.sin_addr), activity, err);
    //m_pListener->notify( buf );

    int dl=p->download;
    peer_shutdown( ctx, p, err);
    /* find where peer is */
    if(dl!=INT_MAX) {
        btPeerset *pset=&ctx->downloads[dl]->peerset;
        for (i=0; i < pset->len; i++) {
            if (pset->peer[i] == p) {
                j = i;
                pset->peer[i] = NULL;
                break;
            }
        }
        /* shift down the rest */
        for (i=j; i < pset->len-1; i++) {
            pset->peer[i] = pset->peer[i+1];
        }
        pset->len--;
    }
    btfree(p);
    close(cs);

    /* clear the execute bit if it was set */
    if (ctx->x_set[cs]) {
        ctx->xsock--;
        ctx->x_set[cs] = 0;
    }
}
Ejemplo n.º 3
0
void
Control::join (Federated_Test::Peer_ptr peer)
{
  {
    ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
    if (this->peers_count_ == this->peers_expected_)
      return;

    this->peers_[this->peers_count_++] =
      Federated_Test::Peer::_duplicate (peer);

    if (this->peers_count_ < this->peers_expected_)
      return;
  }

  /// Automatically shutdown the ORB
  ACE_Utils::Auto_Functor<CORBA::ORB,ORB_Shutdown> orb_shutdown (this->orb_.in ());

  /// Automatically shutdown the peers
  typedef ACE_Utils::Auto_Functor<Federated_Test::Peer,Shutdown<Federated_Test::Peer> > Peer_Shutdown;
  ACE_Auto_Basic_Array_Ptr<Peer_Shutdown> peer_shutdown (
      new Peer_Shutdown[this->peers_count_]
      );

  size_t i;
  for (i = 0; i != this->peers_count_; ++i)
    {
      peer_shutdown[i].reset(this->peers_[i].in());
    }

  ACE_DEBUG ((LM_DEBUG,
              "Control (%P|%t) Building the federation\n"));

  /// Build the EC federation
  for (i = 0; i != this->peers_count_; ++i)
    {
      for (size_t j = 0; j != this->peers_count_; ++j)
        {
          if (i != j)
            {
              this->peers_[j]->connect (this->peers_[i].in ());
            }
        }
    }

  /// ... run the test(s) ...
  for (i = 0; i != this->peers_count_; ++i)
    {
      /// ... automatically release the object references ...
      ACE_Auto_Basic_Array_Ptr<Federated_Test::Loopback_var> loopbacks (
          new Federated_Test::Loopback_var[2*this->peers_count_]
          );

      /// ... and automatically disconnect the loopbacks ...
      typedef Auto_Disconnect<Federated_Test::Loopback> Loopback_Disconnect;
      ACE_Auto_Basic_Array_Ptr<auto_ptr<Loopback_Disconnect> > disconnects (
          new auto_ptr<Loopback_Disconnect>[2*this->peers_count_]
          );

      ACE_DEBUG ((LM_DEBUG,
                  "Control (%P|%t) Running test for peer %d\n",
                  i));
      CORBA::Long experiment_id = 128 + i;
      CORBA::Long base_event_type = ACE_ES_EVENT_UNDEFINED;

      size_t lcount = 0;

      size_t j;
      for (j = 0; j != this->peers_count_; ++j)
        {
          if (j != i)
            {
              loopbacks[lcount] =
                this->peers_[j]->setup_loopback (experiment_id,
                                                 base_event_type);

              ACE_auto_ptr_reset (disconnects[lcount],
                                  new Loopback_Disconnect (
                                        loopbacks[lcount].in ()));
              lcount++;

              loopbacks[lcount] =
                this->peers_[j]->setup_loopback (experiment_id,
                                                 base_event_type + 2);

              ACE_auto_ptr_reset (disconnects[lcount],
                                  new Loopback_Disconnect (
                                        loopbacks[lcount].in ()));
              lcount++;
            }
        }

      Federated_Test::Experiment_Results_var results =
        this->peers_[i]->run_experiment (experiment_id,
                                         this->iterations_);

      ACE_Sample_History history (results->length ());
      for (CORBA::ULong k = 0; k != results->length (); ++k)
        history.sample (results[k]);

      // We use a fake scale factor because the peer already converted
      // to microseconds...
      const ACE_UINT32 fake_scale_factor = 1;

      ACE_Basic_Stats stats;
      history.collect_basic_stats (stats);
      stats.dump_results (ACE_TEXT("Total"), fake_scale_factor);

      if (this->do_dump_history_)
        {
          history.dump_samples (ACE_TEXT("HISTORY"), fake_scale_factor);
        }
    }
}