Ejemplo n.º 1
0
CTEST2(tube, close)
{
    tube *t;
    struct sockaddr_in6 remoteAddr;

    ASSERT_TRUE( ls_sockaddr_get_remote_ip_addr("127.0.0.1",
                                                "1402",
                                                (struct sockaddr *)&remoteAddr,
                                                sizeof(remoteAddr),
                                                &data->err));

    ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err));
    ASSERT_TRUE( tube_close(t, &data->err));
}
Ejemplo n.º 2
0
static int
markov()
{
  struct timespec timer;
  struct timespec remaining;
  tube*           t;
  ls_err          err;
  int             i;
  int*            iptr;

  timer.tv_sec = 0;

  while ( tube_manager_running(mgr) )
  {
    timer.tv_nsec = gauss(50000000, 10000000);
    nanosleep(&timer, &remaining);
    i = random() % NUM_TUBES;
    t = tubes[i];
    if (!t)
    {
      if ( !tube_create(&t, &err) )
      {
        LS_LOG_ERR(err, "tube_create");
        return 1;
      }
      tubes[i] = t;
      iptr     = malloc( sizeof(*iptr) );
      *iptr    = i;
      tube_set_data(t, iptr);
    }
    switch ( tube_get_state(t) )
    {
    case TS_START:
      ls_log(LS_LOG_ERROR, "invalid tube state");
      return 1;
    case TS_UNKNOWN:
      if ( !tube_manager_open_tube(mgr,
                                   (const struct sockaddr*)&remoteAddr,
                                   &t,
                                   &err) )
      {
        LS_LOG_ERR(err, "tube_manager_open_tube");
        return 1;
      }
      break;
    case TS_OPENING:
      /* keep waiting by the mailbox, Charlie Brown */
      break;
    case TS_RUNNING:
      /* .1% chance of close */
      if ( (random() % 10000) < 10 )
      {
        if ( !tube_close(t, &err) )
        {
          LS_LOG_ERR(err, "tube_close");
          return 1;
        }
      }
      else
      {
        /* TODO: put something intersting in the buffer */
        if ( !tube_data(t, data, random() % sizeof(data), &err) )
        {
          LS_LOG_ERR(err, "tube_data");
          return 1;
        }
      }
    case TS_RESUMING:
      /* can't get here yet */
      break;
    }
  }
  return 0;
}