示例#1
0
文件: ev_select.c 项目: Belkacem/node
int inline_size
select_init (EV_P_ int flags)
{
  backend_fudge  = 0.; /* posix says this is zero */
  backend_modify = select_modify;
  backend_poll   = select_poll;

#if EV_SELECT_USE_FD_SET
  vec_ri  = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri);
  vec_ro  = ev_malloc (sizeof (fd_set));
  vec_wi  = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi);
  vec_wo  = ev_malloc (sizeof (fd_set));
  #ifdef _WIN32
  vec_eo  = ev_malloc (sizeof (fd_set));
  #endif
#else
  vec_max = 0;
  vec_ri  = 0; 
  vec_ro  = 0;   
  vec_wi  = 0; 
  vec_wo  = 0; 
  #ifdef _WIN32
  vec_eo  = 0;
  #endif
#endif

  return EVBACKEND_SELECT;
}
示例#2
0
inline_size int
select_init (EV_P_ int flags)
{
  backend_mintime = 1e-6;
  backend_modify  = select_modify;
  backend_poll    = select_poll;

#if EV_SELECT_USE_FD_SET
  vec_ri  = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri);
  vec_ro  = ev_malloc (sizeof (fd_set));
  vec_wi  = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi);
  vec_wo  = ev_malloc (sizeof (fd_set));
  #ifdef _WIN32
  vec_eo  = ev_malloc (sizeof (fd_set));
  #endif
#else
  vec_max = 0;
  vec_ri  = 0;
  vec_ro  = 0;
  vec_wi  = 0;
  vec_wo  = 0;
  #ifdef _WIN32
  vec_eo  = 0;
  #endif
#endif

  return EVBACKEND_SELECT;
}
示例#3
0
文件: texture.c 项目: ibawt/ev
ev_texture* ev_texture_create(void)
{
    ev_texture *t = ev_malloc( sizeof(ev_texture));
    memset( t, 0, sizeof(ev_texture));

    return t;
}
示例#4
0
文件: vertex_buffer.c 项目: ibawt/ev
ev_vbuff* ev_vbuff_create(void)
{
    ev_vbuff* p = ev_malloc(sizeof(ev_vbuff));
    if( p ) {
        memset(p, 0, sizeof(ev_vbuff));
    }
    return p;
}
示例#5
0
文件: array_list.c 项目: ibawt/ev
ev_err_t ev_arraylist_init(ev_arraylist *al, size_t initial)
{
    assert(al);

    al->len = initial;
    al->top = 0;
    al->buff = ev_malloc(sizeof(void*)*initial);

    if( !al->buff ) {
        return EV_NOMEM;
    }

    return EV_OK;
}
示例#6
0
文件: array_list.c 项目: ibawt/ev
ev_err_t ev_arraylist_reserve(ev_arraylist *al, size_t s)
{
    void **p = ev_malloc(s * sizeof(void*));
    if( !p ) {
        return EV_NOMEM;
    }

    memcpy(p, al->buff, (al->top-1) * sizeof(void*));

    ev_free(al->buff);

    al->buff = p;
    al->len = s;

    return EV_OK;
}
示例#7
0
static void
port_poll (EV_P_ ev_tstamp timeout)
{
  int res, i;
  struct timespec ts;
  uint_t nget = 1;

  EV_RELEASE_CB;
  ts.tv_sec  = (time_t)timeout;
  ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9;
  res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
  EV_ACQUIRE_CB;

  if (res == -1)
    { 
      if (errno != EINTR && errno != ETIME)
        ev_syserr ("(libev) port_getn");

      return;
    } 

  for (i = 0; i < nget; ++i)
    {
      if (port_events [i].portev_source == PORT_SOURCE_FD)
        {
          int fd = port_events [i].portev_object;

          fd_event (
            EV_A_
            fd,
            (port_events [i].portev_events & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0)
            | (port_events [i].portev_events & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0)
          );

          port_associate_and_check (EV_A_ fd, anfds [fd].events);
        }
    }

  if (expect_false (nget == port_eventmax))
    {
      ev_free (port_events);
      port_eventmax = array_nextsize (sizeof (port_event_t), port_eventmax, port_eventmax + 1);
      port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);
    }
}
示例#8
0
int inline_size
port_init (EV_P_ int flags)
{
  /* Initalize the kernel queue */
  if ((backend_fd = port_create ()) < 0)
    return 0;

  fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */

  backend_fudge  = 1e-3; /* needed to compensate for port_getn returning early */
  backend_modify = port_modify;
  backend_poll   = port_poll;

  port_eventmax = 64; /* intiial number of events receivable per poll */
  port_events = (port_event_t *)ev_malloc (sizeof (port_event_t) * port_eventmax);

  return EVBACKEND_PORT;
}
示例#9
0
文件: array_list.c 项目: ibawt/ev
static ev_err_t grow_list(ev_arraylist *al)
{
    void   *b;
    size_t  new_size = (al->len * 3) / 2;

    b = ev_malloc(new_size * sizeof(void*));
    if( !b )
        return EV_NOMEM;

    memcpy(b, al->buff, al->top * sizeof(void*));

    ev_free(al->buff);

    al->buff = b;

    al->len = new_size;

    return EV_OK;
}
int inline_size
kqueue_init (EV_P_ int flags)
{
  /* Initialize the kernel queue */
  if ((backend_fd = kqueue ()) < 0)
    return 0;

  fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* not sure if necessary, hopefully doesn't hurt */

  backend_mintime = 1e-9; /* apparently, they did the right thing in freebsd */
  backend_modify  = kqueue_modify;
  backend_poll    = kqueue_poll;

  kqueue_eventmax = 64; /* initial number of events receivable per poll */
  kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);

  kqueue_changes   = 0;
  kqueue_changemax = 0;
  kqueue_changecnt = 0;

  return EVBACKEND_KQUEUE;
}
示例#11
0
文件: vertex_buffer.c 项目: ibawt/ev
ev_err_t ev_vbuff_set_capacity(ev_vbuff *v, size_t num_bytes)
{
    if( v && num_bytes ) {
        if( v->size < num_bytes ) {
            dispose(v);
        }

        glGenBuffers(1, &v->id);
        if( !v->id )
            return EV_FAIL;

        ev_vbuff_bind(v);

        v->buff = ev_malloc(num_bytes);
        if(!v->buff)
            return EV_NOMEM;

        memset(v->buff, 0, num_bytes);
        glBufferData( GL_ARRAY_BUFFER, num_bytes, v->buff, GL_DYNAMIC_DRAW);
        v->size = num_bytes;
        return EV_OK;
    }
    return EV_FAIL;
}
static void
kqueue_poll (EV_P_ ev_tstamp timeout)
{
  int res, i;
  struct timespec ts;

  /* need to resize so there is enough space for errors */
  if (kqueue_changecnt > kqueue_eventmax)
    {
      ev_free (kqueue_events);
      kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_changecnt);
      kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
    }

  EV_RELEASE_CB;
  EV_TS_SET (ts, timeout);
  res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts);
  EV_ACQUIRE_CB;
  kqueue_changecnt = 0;

  if (expect_false (res < 0))
    {
      if (errno != EINTR)
        ev_syserr ("(libev) kevent");

      return;
    }

  for (i = 0; i < res; ++i)
    {
      int fd = kqueue_events [i].ident;

      if (expect_false (kqueue_events [i].flags & EV_ERROR))
        {
          int err = kqueue_events [i].data;

          /* we are only interested in errors for fds that we are interested in :) */
          if (anfds [fd].events)
            {
              if (err == ENOENT) /* resubmit changes on ENOENT */
                kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
              else if (err == EBADF) /* on EBADF, we re-check the fd */
                {
                  if (fd_valid (fd))
                    kqueue_modify (EV_A_ fd, 0, anfds [fd].events);
                  else
                    fd_kill (EV_A_ fd);
                }
              else /* on all other errors, we error out on the fd */
                fd_kill (EV_A_ fd);
            }
        }
      else
        fd_event (
          EV_A_
          fd,
          kqueue_events [i].filter == EVFILT_READ ? EV_READ
          : kqueue_events [i].filter == EVFILT_WRITE ? EV_WRITE
          : 0
        );
    }

  if (expect_false (res == kqueue_eventmax))
    {
      ev_free (kqueue_events);
      kqueue_eventmax = array_nextsize (sizeof (struct kevent), kqueue_eventmax, kqueue_eventmax + 1);
      kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax);
    }
}