示例#1
0
int ioevent_detach(IOEventPoller *ioevent, const int fd)
{
#if IOEVENT_USE_EPOLL
  return epoll_ctl(ioevent->poll_fd, EPOLL_CTL_DEL, fd, NULL);
#elif IOEVENT_USE_KQUEUE
  struct kevent ev[2];
  int n = 0;
  if ((ioevent->care_events & IOEVENT_READ)) {
    EV_SET(&ev[n++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
  }
  if ((ioevent->care_events & IOEVENT_WRITE)) {
    EV_SET(&ev[n++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
  }

  ioevent->care_events = 0;
  if (n > 0) {
      return kevent(ioevent->poll_fd, ev, n, NULL, 0, NULL);
  }
  else {
      return 0;
  }
#elif IOEVENT_USE_PORT
  return port_dissociate(ioevent->poll_fd, PORT_SOURCE_FD, fd);
#endif
}
示例#2
0
/**
 * port_remove
 *
 * < private >
 * Unsafe, need lock fen_lock.
 */
void
port_remove (gpointer f)
{
    _f* fo = NULL;

    FK_W ("%s\n", __func__);
    if ((fo = g_hash_table_lookup (_obj_fen_hash, f)) != NULL) {
        /* Marked */
        fo->user_data = NULL;
        g_hash_table_remove (_obj_fen_hash, f);
        
        if (port_dissociate (F_PORT(fo),
              PORT_SOURCE_FILE,
              (uintptr_t)fo->fobj) == 0) {
            /*
             * Note, we can run foode_delete if dissociating is failed,
             * because there may be some pending events (mostly like
             * FILE_DELETE) in the port_get. If we delete the foode
             * the fnode may be deleted, then port_get will run on an invalid
             * address.
             */
            FK_W ("[ FREE_FO ] [0x%p]\n", fo);
            pnode_delete (fo->port);
            g_free (fo);
        } else {
            FK_W ("PORT_DISSOCIATE [%-20s] %s\n", F_NAME(fo), g_strerror (errno));
        }
    }
}
示例#3
0
文件: nc_evport.c 项目: idning/ndb
int
event_del_conn(struct event_base *evb, struct conn *c)
{
    int status;
    int evp = evb->evp;

    ASSERT(evp > 0);
    ASSERT(c != NULL);
    ASSERT(c->sd > 0);

    if (!c->send_active && !c->recv_active) {
        return 0;
    }

    /*
     * Removes the association of an object with a port. The association
     * is also removed if the port gets closed.
     *
     * On failure, we check for ENOENT errno because it is likely that we
     * are deleting this connection after it was returned from the event
     * loop and before we had a chance of reactivating it by calling
     * port_associate() on it.
     */
    status = port_dissociate(evp, PORT_SOURCE_FD, c->sd);
    if (status < 0 && errno != ENOENT) {
        log_error("port dissociate evp %d sd %d failed: %s", evp, c->sd,
                  strerror(errno));
        return status;
    }

    c->recv_active = 0;
    c->send_active = 0;

    return 0;
}
示例#4
0
/*
 * Associate or dissociate this file descriptor with the event port, using the
 * specified event mask.
 */
static inline void evports_resync_fd(int fd, int events)
{
	if (events == 0)
		port_dissociate(evports_fd[tid], PORT_SOURCE_FD, fd);
	else
		port_associate(evports_fd[tid], PORT_SOURCE_FD, fd, events, NULL);
}
示例#5
0
/*
 * port_remove
 *
 * < private >
 * Unsafe, need lock fen_lock.
 */
void
port_remove (node_t *f)
{
    /* g_assert(f->source); */

    if (NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED)) {
        /* Mark unregisted. */
        if (port_dissociate(PGPFD(f->source)->fd, PORT_SOURCE_FILE, (uintptr_t)FILE_OBJECT(f)) == 0) {
            /*
             * Note, we can run foode_delete if dissociating is failed,
             * because there may be some pending events (mostly like
             * FILE_DELETE) in the port_get. If we delete the foode
             * the fnode may be deleted, then port_get will run on an invalid
             * address.
             */
            NODE_CLE_STATE(f, NODE_STATE_ASSOCIATED);
            FK_W ("PORT_DISSOCIATE 0x%p OK\n", f);
        } else if (errno == ENOENT) {
            /* The file has been removed from port, after port_get or before
             * port_get but DELETED event has been generated.
             * Ignored. */
        } else {
            FK_W ("PORT_DISSOCIATE 0x%p %s\n", f, g_strerror (errno));
            g_return_if_reached();
        }
    }
}
示例#6
0
ACP_EXPORT acp_rc_t acpPollRemoveSock(acp_poll_set_t *aPollSet,
                                      acp_sock_t     *aSock)
{
    acp_sint32_t sRet;

    if (aPollSet->mEventHandle == aSock->mHandle)
    {
        acpPollRemoveObj(aPollSet, aSock);

        aPollSet->mEventHandle = -1;
    }
    else
    {
        sRet = port_dissociate(aPollSet->mHandle,
                               PORT_SOURCE_FD,
                               (uintptr_t)aSock->mHandle);

        /* Handle error code */
        if (sRet == -1)
        {
            return ACP_RC_GET_NET_ERROR();
        }
        else
        {
            acpPollRemoveObj(aPollSet, aSock);
        }
    }

    return ACP_RC_SUCCESS;
}
示例#7
0
文件: ports.c 项目: dwfreed/charybdis
/*
 * rb_setselect
 *
 * This is a needed exported function which will be called to register
 * and deregister interest in a pending IO state for a given FD.
 */
void
rb_setselect_ports(rb_fde_t *F, unsigned int type, PF * handler, void *client_data)
{
	lrb_assert(IsFDOpen(F));
	int old_flags = F->pflags;

	if(type & RB_SELECT_READ)
	{
		F->read_handler = handler;
		F->read_data = client_data;
	}
	if(type & RB_SELECT_WRITE)
	{
		F->write_handler = handler;
		F->write_data = client_data;
	}
	F->pflags = 0;

	if(F->read_handler != NULL)
		F->pflags = POLLIN;
	if(F->write_handler != NULL)
		F->pflags |= POLLOUT;

	if(old_flags == 0 && F->pflags == 0)
		return;
	else if(F->pflags <= 0)
	{
		port_dissociate(pe, PORT_SOURCE_FD, F->fd);
		return;
	}

	port_associate(pe, PORT_SOURCE_FD, F->fd, F->pflags, F);

}
static void aeApiDelEvent(aeEventLoop *eventLoop, int fd, int mask) {
    aeApiState *state = eventLoop->apidata;
    int fullmask, pfd;

    if (evport_debug)
        fprintf(stderr, "del fd %d mask 0x%x\n", fd, mask);

    pfd = aeApiLookupPending(state, fd);

    if (pfd != -1) {
        if (evport_debug)
            fprintf(stderr, "deleting event from pending fd %d\n", fd);

        /*
         * This fd was just returned from aeApiPoll, so it's not currently
         * associated with the port.  All we need to do is update
         * pending_mask appropriately.
         */
        state->pending_masks[pfd] &= ~mask;

        if (state->pending_masks[pfd] == AE_NONE)
            state->pending_fds[pfd] = -1;

        return;
    }

    /*
     * The fd is currently associated with the port.  Like with the add case
     * above, we must look at the full mask for the file descriptor before
     * updating that association.  We don't have a good way of knowing what the
     * events are without looking into the eventLoop state directly.  We rely on
     * the fact that our caller has already updated the mask in the eventLoop.
     */

    fullmask = eventLoop->events[fd].mask;
    if (fullmask == AE_NONE) {
        /*
         * We're removing *all* events, so use port_dissociate to remove the
         * association completely.  Failure here indicates a bug.
         */
        if (evport_debug)
            fprintf(stderr, "aeApiDelEvent: port_dissociate(%d)\n", fd);

        if (port_dissociate(state->portfd, PORT_SOURCE_FD, fd) != 0) {
            perror("aeApiDelEvent: port_dissociate");
            abort(); /* will not return */
        }
    } else if (aeApiAssociate("aeApiDelEvent", state->portfd, fd,
        fullmask) != 0) {
        /*
         * ENOMEM is a potentially transient condition, but the kernel won't
         * generally return it unless things are really bad.  EAGAIN indicates
         * we've reached an resource limit, for which it doesn't make sense to
         * retry (counter-intuitively).  All other errors indicate a bug.  In any
         * of these cases, the best we can do is to abort.
         */
        abort(); /* will not return */
    }
}
示例#9
0
static void portfs_root_stop_watch_dir(watchman_global_watcher_t watcher,
      w_root_t *root, struct watchman_dir *dir) {
  struct portfs_root_state *state = root->watch;
  unused_parameter(watcher);

  port_dissociate(state->port_fd, PORT_SOURCE_FILE,
      (uintptr_t)&dir->port_file);
}
static ngx_int_t
ngx_eventport_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags)
{
    ngx_event_t       *e;
    ngx_connection_t  *c;

    /*
     * when the file descriptor is closed, the event port automatically
     * dissociates it from the port, so we do not need to dissociate explicity
     * the event before the closing the file descriptor
     */

    if (flags & NGX_CLOSE_EVENT) {
        ev->active = 0;
        ev->oneshot = 0;
        return NGX_OK;
    }

    c = ev->data;

    if (event == NGX_READ_EVENT) {
        e = c->write;
        event = POLLOUT;

    } else {
        e = c->read;
        event = POLLIN;
    }

    if (e->oneshot) {
        ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                       "eventport change event: fd:%d ev:%04Xi", c->fd, event);

        if (port_associate(ep, PORT_SOURCE_FD, c->fd, event,
                           (void *) ((uintptr_t) ev | ev->instance))
            == -1)
        {
            ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                          "port_associate() failed");
            return NGX_ERROR;
        }

    } else {
        ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
                       "eventport del event: fd:%d", c->fd);

        if (port_dissociate(ep, PORT_SOURCE_FD, c->fd) == -1) {
            ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno,
                          "port_dissociate() failed");
            return NGX_ERROR;
        }
    }

    ev->active = 0;
    ev->oneshot = 0;

    return NGX_OK;
}
示例#11
0
void uv__fs_event_close(uv_fs_event_t* handle) {
  if (handle->fd == PORT_FIRED) {
    port_dissociate(handle->loop->fs_fd, PORT_SOURCE_FILE, (uintptr_t)&handle->fo);
  }
  handle->fd = PORT_DELETED;
  free(handle->filename);
  handle->filename = NULL;
  handle->fo.fo_name = NULL;
}
示例#12
0
文件: port.c 项目: AxiosCros/php-src
/*
 * Remove a FD from the fd set
 */
static int fpm_event_port_remove(struct fpm_event_s *ev) /* {{{ */
{
	/* remove the event from port */
	if (port_dissociate(pfd, PORT_SOURCE_FD, ev->fd) < 0) {
		zlog(ZLOG_ERROR, "port: unable to add the event");
		return -1;
	}
	return 0;
}
示例#13
0
APR_DECLARE(apr_status_t) apr_pollset_remove(apr_pollset_t *pollset,
                                             const apr_pollfd_t *descriptor)
{
    apr_os_sock_t fd;
    pfd_elem_t *ep;
    apr_status_t rv = APR_SUCCESS;
    int res;

    pollset_lock_rings();

    if (descriptor->desc_type == APR_POLL_SOCKET) {
        fd = descriptor->desc.s->socketdes;
    }
    else {
        fd = descriptor->desc.f->filedes;
    }

    res = port_dissociate(pollset->port_fd, PORT_SOURCE_FD, fd);

    if (res < 0) {
        rv = APR_NOTFOUND;
    }

    if (!APR_RING_EMPTY(&(pollset->query_ring), pfd_elem_t, link)) {
        for (ep = APR_RING_FIRST(&(pollset->query_ring));
             ep != APR_RING_SENTINEL(&(pollset->query_ring),
                                     pfd_elem_t, link);
             ep = APR_RING_NEXT(ep, link)) {

            if (descriptor->desc.s == ep->pfd.desc.s) {
                APR_RING_REMOVE(ep, link);
                APR_RING_INSERT_TAIL(&(pollset->dead_ring),
                                     ep, pfd_elem_t, link);
                break;
            }
        }
    }

    if (!APR_RING_EMPTY(&(pollset->add_ring), pfd_elem_t, link)) {
        for (ep = APR_RING_FIRST(&(pollset->add_ring));
             ep != APR_RING_SENTINEL(&(pollset->add_ring),
                                     pfd_elem_t, link);
             ep = APR_RING_NEXT(ep, link)) {

            if (descriptor->desc.s == ep->pfd.desc.s) {
                APR_RING_REMOVE(ep, link);
                APR_RING_INSERT_TAIL(&(pollset->dead_ring),
                                     ep, pfd_elem_t, link);
                break;
            }
        }
    }

    pollset_unlock_rings();

    return rv;
}
示例#14
0
文件: sunos.c 项目: 0-wiz-0/libuv
int uv__io_check_fd(uv_loop_t* loop, int fd) {
  if (port_associate(loop->backend_fd, PORT_SOURCE_FD, fd, POLLIN, 0))
    return -errno;

  if (port_dissociate(loop->backend_fd, PORT_SOURCE_FD, fd))
    abort();

  return 0;
}
示例#15
0
文件: event.c 项目: sashka/uwsgi
int event_queue_del_fd(int eq, int fd, int event) {

        if (port_dissociate(eq, PORT_SOURCE_FD, fd)) {
                uwsgi_error("port_disassociate");
                return -1;
        }

        return fd;
}
示例#16
0
文件: portfs.c 项目: alemic/libphenom
ph_result_t ph_nbio_emitter_apply_io_mask(struct ph_nbio_emitter *emitter,
    ph_job_t *job, ph_iomask_t mask)
{
  int res;
  int want_mask = 0;

  if (job->fd == -1) {
    return PH_OK;
  }

  switch (mask & (PH_IOMASK_READ|PH_IOMASK_WRITE)) {
    case PH_IOMASK_READ:
      want_mask = POLLIN|DEFAULT_POLL_MASK;
      break;
    case PH_IOMASK_WRITE:
      want_mask = POLLOUT|DEFAULT_POLL_MASK;
      break;
    case PH_IOMASK_READ|PH_IOMASK_WRITE:
      want_mask = POLLIN|POLLOUT|DEFAULT_POLL_MASK;
      break;
    case 0:
    default:
      want_mask = 0;
  }

  if (want_mask == job->kmask) {
    return PH_OK;
  }

  switch (want_mask) {
    case 0:
      res = port_dissociate(emitter->io_fd, PORT_SOURCE_FD, job->fd);
      if (res != 0 && errno == ENOENT) {
        res = 0;
      }
      if (res != 0) {
        ph_panic("port_dissociate: setting mask to %02x on fd %d -> `Pe%d",
            mask, job->fd, errno);
      }
      job->kmask = 0;
      job->mask = 0;
      break;

    default:
      job->mask = mask;
      job->kmask = want_mask;
      res = port_associate(emitter->io_fd, PORT_SOURCE_FD, job->fd,
          want_mask, job);
      if (res != 0) {
        ph_panic("port_associate: setting mask to %02x on fd %d -> `Pe%d",
            mask, job->fd, errno);
        return PH_ERR;
      }
  }
  return PH_OK;
}
示例#17
0
文件: sunos.c 项目: Andrepuel/jxcore
void uv__fs_event_close(uv_fs_event_t* handle) {
  if (handle->fd == PORT_FIRED || handle->fd == PORT_LOADED) {
    port_dissociate(handle->loop->fs_fd, PORT_SOURCE_FILE,
                    (uintptr_t) & handle->fo);
  }
  handle->fd = PORT_DELETED;
  JX_FREE(sunos, handle->filename);
  handle->filename = NULL;
  handle->fo.fo_name = NULL;
  uv__handle_stop(handle);
}
示例#18
0
static void alter_fd_dissociate(eventer_t e, int mask, struct ports_spec *spec) {
  int s_errno = 0, ret;
  errno = 0;
  ret = port_dissociate(spec->port_fd, PORT_SOURCE_FD, e->fd);
  s_errno = errno;
  if (ret == -1) {
    if(s_errno == ENOENT) return; /* Fine */
    if(s_errno == EBADFD) return; /* Fine */
    mtevFatal(mtev_error,
          "eventer port_dissociate failed(%d-%d): %d/%s\n", e->fd, spec->port_fd, s_errno, strerror(s_errno));
  }
}
示例#19
0
static void portfs_root_stop_watch_file(watchman_global_watcher_t watcher,
      w_root_t *root, struct watchman_file *file) {
  struct portfs_root_state *state = root->watch;
  unused_parameter(watcher);

  port_dissociate(state->port_fd, PORT_SOURCE_FILE,
      (uintptr_t)&file->port_file);
  if (file->port_file.fo_name) {
    free(file->port_file.fo_name);
    file->port_file.fo_name = NULL;
  }
}
示例#20
0
void PortsEngine::DelFd(EventHandler* eh)
{
	int fd = eh->GetFd();
	if ((fd < 0) || (fd > GetMaxFds() - 1))
		return;

	port_dissociate(EngineHandle, PORT_SOURCE_FD, fd);

	CurrentSetSize--;
	ref[fd] = NULL;

	ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
}
示例#21
0
文件: evport.c 项目: boivie/Libevent
static int
evport_del(struct event_base *base, int fd, short old, short events, void *p)
{
	struct evport_data *evpd = base->evbase;
	struct fd_info *fdi;
	int i;
	int associated = 1;
	(void)p;

	check_evportop(evpd);

	if (evpd->ed_nevents < fd) {
		return (-1);
	}

	for (i = 0; i < EVENTS_PER_GETN; ++i) {
		if (evpd->ed_pending[i] == fd) {
			associated = 0;
			break;
		}
	}

	fdi = &evpd->ed_fds[fd];
	if (events & EV_READ)
		fdi->fdi_what &= ~EV_READ;
	if (events & EV_WRITE)
		fdi->fdi_what &= ~EV_WRITE;

	if (associated) {
		if (!FDI_HAS_EVENTS(fdi) &&
		    port_dissociate(evpd->ed_port, PORT_SOURCE_FD, fd) == -1) {
			/*
			 * Ignore EBADFD error the fd could have been closed
			 * before event_del() was called.
			 */
			if (errno != EBADFD) {
				event_warn("port_dissociate");
				return (-1);
			}
		} else {
			if (FDI_HAS_EVENTS(fdi)) {
				return (reassociate(evpd, fdi, fd));
			}
		}
	} else {
		if ((fdi->fdi_what & (EV_READ|EV_WRITE)) == 0) {
			evpd->ed_pending[i] = -1;
		}
	}
	return 0;
}
示例#22
0
static void
port_modify (EV_P_ int fd, int oev, int nev)
{
  /* we need to reassociate no matter what, as closes are
   * once more silently being discarded.
   */
  if (!nev)
    {
      if (oev)
        port_dissociate (backend_fd, PORT_SOURCE_FD, fd);
    }
  else
    port_associate_and_check (EV_A_ fd, nev);
}
示例#23
0
void
pe_update_events(fde_t * F, short filter, PF * handler)
{
	PF *cur_handler = NULL;

	if (filter == POLLRDNORM)
		cur_handler = F->read_handler;
	else if (filter == POLLWRNORM)
		cur_handler = F->write_handler;

	if (!cur_handler && handler)
		port_associate(pe, PORT_SOURCE_FD, F->fd, filter, F);
	else if (cur_handler && !handler)
		port_dissociate(pe, PORT_SOURCE_FD, F->fd);
}
示例#24
0
static void delete_port_association(struct port_event_context *port_ev,
				struct tevent_fd *fde)
{
	struct port_associate_vals *val;

	for (val = port_ev->po_vals; val; val = val->next) {
		if (val->fde == fde) {
			if (val->associated_event) {
				(void)port_dissociate(port_ev->port_fd,
							PORT_SOURCE_FD,
							fde->fd);
			}
			talloc_free(val);
			return;
		}
	}
}
示例#25
0
void mowgli_ioevent_dissociate(mowgli_ioevent_handle_t *self, mowgli_ioevent_source_t source, int object)
{
	if (source != MOWGLI_SOURCE_FD)
		return;

#ifdef HAVE_EPOLL_CTL
	{
		struct epoll_event ep_event = {};

		epoll_ctl(self->impldata, EPOLL_CTL_DEL, object, &ep_event);
	}
#endif

#ifdef HAVE_PORT_CREATE
	port_dissociate(self->impldata, PORT_SOURCE_FD, object);
#endif
}
示例#26
0
文件: sunos.c 项目: 0x20c24/cjdns
int uv_fs_event_stop(uv_fs_event_t* handle) {
  if (!uv__is_active(handle))
    return -EINVAL;

  if (handle->fd == PORT_FIRED || handle->fd == PORT_LOADED) {
    port_dissociate(handle->loop->fs_fd,
                    PORT_SOURCE_FILE,
                    (uintptr_t) &handle->fo);
  }

  handle->fd = PORT_DELETED;
  free(handle->filename);
  handle->filename = NULL;
  handle->fo.fo_name = NULL;
  uv__handle_stop(handle);

  return 0;
}
示例#27
0
static int __iv_fd_port_upload_one(struct iv_state *st, struct iv_fd_ *fd)
{
    int ret;

    iv_list_del_init(&fd->list_notify);

    if (fd->wanted_bands) {
        ret = port_associate(st->u.port.port_fd, PORT_SOURCE_FD, fd->fd,
                             bits_to_poll_mask(fd->wanted_bands), fd);
    } else {
        ret = port_dissociate(st->u.port.port_fd, PORT_SOURCE_FD,
                              fd->fd);
    }

    if (ret == 0)
        fd->registered_bands = fd->wanted_bands;

    return ret;
}
示例#28
0
文件: port.c 项目: Ga-vin/apache
static apr_status_t impl_pollcb_remove(apr_pollcb_t *pollcb,
                                       apr_pollfd_t *descriptor)
{
    int fd, ret;

    if (descriptor->desc_type == APR_POLL_SOCKET) {
        fd = descriptor->desc.s->socketdes;
    }
    else {
        fd = descriptor->desc.f->filedes;
    }

    ret = port_dissociate(pollcb->fd, PORT_SOURCE_FD, fd);

    if (ret < 0) {
        return APR_NOTFOUND;
    }

    return APR_SUCCESS;
}
示例#29
0
static ret_t
_del (cherokee_fdpoll_port_t *fdp, int fd)
{
	int rc;

	rc = port_dissociate( fdp->port,      /* port */
	                      PORT_SOURCE_FD, /* source */
	                      fd);            /* object */
	if ( rc == -1 ) {
		LOG_ERRNO (errno, cherokee_err_error,
			   CHEROKEE_ERROR_FDPOLL_PORTS_ASSOCIATE, fd);
		return ret_error;
	}

	FDPOLL(fdp)->npollfds--;

	/* remote fd from the active fd list
	 */
	fdp->port_activefd[fd] = -1;

	return ret_ok;
}
示例#30
0
static void alter_fd(eventer_t e, int mask) {
  if(mask & (EVENTER_READ | EVENTER_WRITE | EVENTER_EXCEPTION)) {
    int events = 0;
    if(mask & EVENTER_READ) events |= POLLIN;
    if(mask & EVENTER_WRITE) events |= POLLOUT;
    if(mask & EVENTER_EXCEPTION) events |= POLLERR;
    if(port_associate(port_fd, PORT_SOURCE_FD, e->fd, events, (void *)e->fd) == -1) {
      noitL(eventer_err,
            "eventer port_associate failed: %s\n", strerror(errno));
      abort();
    }
  }
  else {
    if(port_dissociate(port_fd, PORT_SOURCE_FD, e->fd) == -1) {
      if(errno == ENOENT) return; /* Fine */
      if(errno == EBADFD) return; /* Fine */
      noitL(eventer_err,
            "eventer port_dissociate failed: %s\n", strerror(errno));
      abort();
    }
  }
}