Esempio n. 1
0
static int fds_kqueue(struct timeval *tv)
{
  scamper_fd_t *fdp;
  struct timespec ts, *tsp = NULL;
  struct kevent *kev;
  int fd, i, c;

  if((c = dlist_count(read_fds) + dlist_count(write_fds)) >= kevlistlen)
    {
      c += 8;
      if(realloc_wrap((void **)&kevlist, sizeof(struct kevent) * c) != 0)
	{
	  if(kevlistlen == 0)
	    {
	      printerror(errno, strerror, __func__, "could not alloc kevlist");
	      return -1;
	    }
	}
      else
	{
	  kevlistlen = c;
	}
    }

  if(tv != NULL)
    {
      ts.tv_sec  = tv->tv_sec;
      ts.tv_nsec = tv->tv_usec * 1000;
      tsp = &ts;
    }

  if((c = kevent(kq, NULL, 0, kevlist, kevlistlen, tsp)) == -1)
    {
      printerror(errno, strerror, __func__, "kevent failed");
      return -1;
    }

  for(i=0; i<c; i++)
    {
      kev = &kevlist[i];
      fd = kev->ident;

      if(fd < 0 || fd >= fd_array_s)
	continue;
      if((fdp = fd_array[fd]) == NULL)
	continue;
      if(kev->filter == EVFILT_READ)
	fdp->read.cb(fd, fdp->read.param);
      else if(kev->filter == EVFILT_WRITE)
	fdp->write.cb(fd, fdp->write.param);
    }

  return 0;
}
Esempio n. 2
0
static OS_STATUS _show_msgQ_info (MSG_QUE *pMsgQ, int unused)
{
    serial_printf("ID: %8X  cur_num: %3d  max_num: %3d  wait_send_task: %d wait_recv_task: %d\n",
                  pMsgQ,
                  pMsgQ->cur_num,
                  pMsgQ->max_num,
                  dlist_count (&pMsgQ->wait_send_list),
                  dlist_count (&pMsgQ->wait_recv_list)
                 );
    return OS_STATUS_OK;
}
Esempio n. 3
0
/*
 * scamper_fds_poll
 *
 * the money function: this function polls the file descriptors held by
 * scamper.  for each fd with an event, it calls the callback registered
 * with the fd.
 */
int scamper_fds_poll(struct timeval *timeout)
{
  scamper_fd_t *fdn;
  struct timeval tv;

  /*
   * if there are fds that can be reaped, then do so.
   * if there are fds left over after, use that to guide the select timeout.
   */
  if(dlist_count(refcnt_0) > 0)
    {
      gettimeofday_wrap(&tv);

      while((fdn = (scamper_fd_t *)dlist_head_get(refcnt_0)) != NULL)
	{
	  assert(fdn->refcnt == 0);

	  if(timeval_cmp(&fdn->tv, &tv) > 0)
	    break;

	  fd_close(fdn);
	  fd_free(fdn);
	}

      if(fdn != NULL)
	{
	  timeval_diff_tv(&tv, &tv, &fdn->tv);
	  if(timeout == NULL || timeval_cmp(&tv, timeout) < 0)
	    timeout = &tv;
	}
    }

  return pollfunc(timeout);
}
Esempio n. 4
0
/**********************************************************************************************************
  show the semC brief which in _G_semC_list
**********************************************************************************************************/
static OS_STATUS _show_semC_info (SEM_CNT *pSemC, int unused)
{
    serial_printf("ID: %8X  cur_cnt: %d  max_cnt: %3d  wait_task: %d\n",
                  pSemC,
                  pSemC->count,
                  pSemC->max_count,
                  dlist_count (&pSemC->wait_list)
                 );
    return OS_STATUS_OK;
}
static void sniff_check(scamper_dl_rec_t *dl)
{
  scamper_task_sig_t *sig;
  s2t_t *s2t;
  dlist_node_t *n;
  scamper_addr_t src;
  uint16_t id;

  if(dlist_count(sniff) <= 0)
    return;

  if(SCAMPER_DL_IS_ICMP_ECHO_REPLY(dl))
    id = dl->dl_icmp_id;
  else if(SCAMPER_DL_IS_ICMP_Q_ICMP_ECHO(dl))
    id = dl->dl_icmp_icmp_id;
  else
    return;

  if(SCAMPER_DL_IS_IPV4(dl))
    src.type = SCAMPER_ADDR_TYPE_IPV4;
  else if(SCAMPER_DL_IS_IPV6(dl))
    src.type = SCAMPER_ADDR_TYPE_IPV6;
  else
    return;
  src.addr = dl->dl_ip_dst;

  for(n = dlist_head_node(sniff); n != NULL; n = dlist_node_next(n))
    {
      s2t = dlist_node_item(n); sig = s2t->sig;
      if(sig->sig_sniff_icmp_id != id)
	continue;
      if(scamper_addr_cmp(sig->sig_sniff_src, &src) != 0)
	continue;

      if(s2t->task->funcs->handle_dl != NULL)
	s2t->task->funcs->handle_dl(s2t->task, dl);
    }

  return;
}
Esempio n. 6
0
/*==============================================================================
 * - app_album()
 *
 * - album application entry
 */
OS_STATUS app_album (GUI_CBI *pCBI_album, GUI_COOR *coor)
{
    GUI_COOR pic_left_up = {gra_scr_w(), 0};
    GUI_SIZE album_size = {gra_scr_w(), gra_scr_h()};

    GUI_CBI *pCBI = malloc (sizeof (GUI_CBI));
    if (pCBI == NULL) {
        return OS_STATUS_ERROR;
    }
    strcpy (pCBI->name, "album cbi");

    pCBI->left_up.x = 0;
    pCBI->left_up.y = 0;
    pCBI->right_down.x = gra_scr_w() - 1;
    pCBI->right_down.y = gra_scr_h() - 1;

    pCBI->func_press   = cbf_noop;
    pCBI->func_leave   = cbf_noop;
    pCBI->func_release = _album_cb_change;
    pCBI->func_drag    = cbf_hw_drag;

    pCBI->data = NULL;

    cbi_delete_all ();   /* delete all other cbis */

    _album_add_file (ALBUM_PIC_PATH, ".jpg");
    _album_add_file (ALBUM_PIC_PATH, ".JPG");

    _G_right_pic = (PIC_NAME_NODE *)DL_FIRST(&_G_pic_list);
    _G_left_pic  = (PIC_NAME_NODE *)DL_LAST(&_G_pic_list);
    GUI_ASSERT(_G_right_pic != NULL);

    jpeg_dump_pic (_G_right_pic->name, &pic_left_up, &album_size);

    gra_set_show_fb (1); /* show frame buffer 1 */

    font_printf (&pic_left_up, GUI_COLOR_GREEN,
                 "There are %d picture(s) in \""ALBUM_PIC_PATH"\" directory!",
                 dlist_count (&_G_pic_list));

    _G_right_pic = (PIC_NAME_NODE *)DL_NEXT(_G_right_pic);

    /* dump first and last picture in frame buffer */
    pic_left_up.x = 0;
    jpeg_dump_pic (_G_left_pic->name, &pic_left_up, &album_size);
    pic_left_up.x = gra_scr_w() * 2;
    jpeg_dump_pic (_G_right_pic->name, &pic_left_up, &album_size);

    cbi_register (pCBI);

    /* home cbi */
    {
        GUI_CBI *pCBI_home = NULL;
        GUI_COOR left_up = {gra_scr_w() - ICON_SIZE, 0};
        GUI_SIZE size = {0, 0};
        pCBI_home = cbi_create_default ("/n1/gui/cbi_home.jpg", &left_up, &size, FALSE);
        pCBI_home->func_release = _album_cb_home;

        cbi_register (pCBI_home);
    }


    return OS_STATUS_OK;
}