Esempio n. 1
0
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
{
  if (real_pwrite == NULL) __mtrace_init();
  struct stat st;
  if (fstat(fd, &st) == 0)
  {
    /*
    char buf[BUFSIZ];
    int len = snprintf(buf, BUFSIZ, "pwrite fd=%d st_mode=%X\n", fd, st.st_mode);
    int wl = real_write(test_fd, buf, len);
    if (wl != len)
    {
      fprintf(stderr, "log write error: %s\n", strerror(errno));
    }
    fsync(test_fd);
    */
    if (S_ISREG(st.st_mode))
    {
      int64_t st = get_sleep_time();
      if (st > 0)
      {
        usleep(st);
      }
    }
  }
  return real_pwrite(fd, buf, count, offset);
}
Esempio n. 2
0
    void gen()
    {
        timespec sleep;
        while(running_)
        {
            auto h = pool_.getHeader();
            if(h.first == true)
            {
                uint8_t *pkt_data = NULL;
                uint32_t pkt_len = 0;
                gen_pkt(*h.second, &pkt_data, &pkt_len);
                pcap_sendpacket(pd, pkt_data, pkt_len);

                //std::cerr <<"sent a packet." << std::endl;
                delete [] pkt_data;
                ++counter_;
            }
            else
            {
                // std::cerr << "pool empty" << std::endl;
            }
            get_sleep_time(&sleep);
            nanosleep(&sleep,NULL);
        }
    }
Esempio n. 3
0
 void gen()
 {
     timespec sleep_timer_;
     while(running_)
     {
         pool_.addHeader(make_header());
         get_sleep_time(&sleep_timer_);
         nanosleep(&sleep_timer_,NULL);
     }
 }
Esempio n. 4
0
gboolean run(void *data)
{
    update_lists();
    static int timeout_cnt = 0;
    static int next_timeout = 0;

    if (data) {
        timeout_cnt--;
    }

    if (displayed->length > 0 && !xctx.visible && !pause_display) {
        x_win_show();
    }

    if (xctx.visible && (pause_display || displayed->length == 0)) {
        x_win_hide();
    }

    if (xctx.visible) {
        x_win_draw();
    }

    if (xctx.visible) {
        int now = time(NULL);
        int sleep = get_sleep_time();

        if (sleep > 0) {
            int timeout_at = now + sleep;
            if (timeout_cnt == 0 || timeout_at < next_timeout) {
                g_timeout_add_seconds(sleep, run, mainloop);
                next_timeout = timeout_at;
                timeout_cnt++;
            }
        }
    }

    /* always return false to delete timers */
    return false;
}
network_time_seconds network_throttle::get_sleep_time_after_tick(size_t packet_size) {
	tick();
	return get_sleep_time(packet_size);
}