예제 #1
0
int main()
{
    ba::io_service io_service;

    MemoryStream port(io_service);

    // spin up worker thread for the io_service
    boost::thread worker_thread(boost::bind(&boost::asio::io_service::run, &io_service));

    // spin up the dummy data generator simulating packets from server
    RandomDataGenerator data_gen(port);
    boost::thread worker_thread2(boost::bind(&RandomDataGenerator::run, &data_gen));

    // async reader & writer
    AsyncReader reader(port);
    AsyncWriter writer(port);
    reader.do_read();
    writer.do_write();

    while(true)
    {
        std::cerr << port.popWriteBuffer() << std::endl;
        //boost::this_thread::sleep_for(boost::chrono::seconds(1));
    }

}
예제 #2
0
파일: parse.c 프로젝트: NetSys/sts
void
parse_dir (const char *outdir, const char *tfdir, const char *name)
{
  printf ("Parsing: ");
  fflush (stdout);

  struct parse_ntf *ntf;
  struct parse_tf *ttf;
  int stages;

  char buf[PATH_MAX + 1];
  snprintf (buf, sizeof buf, "%s/%s", tfdir, name);
  char *base = buf + strlen (buf);

  strcpy (base, "/stages");
  FILE *f = fopen (buf, "r");
  if (!f) err (1, "Can't open %s", buf);
  if (!fscanf (f, "%d", &stages)) errx (1, "Can't read NTF stages from %s", buf);
  fclose (f);

  *base = 0;
  struct dirent **tfs;
  int n = scandir (buf, &tfs, filter_tfs, alphasort);
  if (n <= 0) err (1, "Couldn't find .tf files in %s", buf);

  ntf = xmalloc (sizeof *ntf + n * sizeof *ntf->tfs);
  ntf->ntfs = n;
  ntf->stages = stages;
  *base = '/';
  for (int i = 0; i < n; i++) {
    strcpy (base + 1, tfs[i]->d_name);
    free (tfs[i]);
    struct parse_tf *tf = parse_tf (buf);
    assert (tf);
    ntf->tfs[i] = tf;
  }
  free (tfs);

  strcpy (base, "/topology.tf");
  ttf = parse_tf (buf);
  assert (ttf);
  printf ("done\n");

  snprintf (buf, sizeof buf, "%s/%s.dat", outdir, name);
  data_gen (buf, ntf, ttf);

  free_ntf (ntf);
  free_tf (ttf);
}