* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
- * Copyright (c) 2006 Sun Microsystems. All rights reserved.
+ * Copyright (c) 2007 Sun Microsystems. All rights reserved.
* Use is subject to license terms.
*/
#include "config.h"
#endif
-#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
-#else
-#include <sys/_time.h>
-#endif
#include <assert.h>
#include <sys/queue.h>
#include <sys/tree.h>
int ed_nevents; /* number of allocated fdi's */
struct fd_info *ed_fds; /* allocated fdi table */
/* fdi's that we need to reassoc */
- struct fd_info *ed_pending[EVENTS_PER_GETN];
+ int ed_pending[EVENTS_PER_GETN]; /* fd's with pending events */
};
static void* evport_init (struct event_base *);
evport_init(struct event_base *base)
{
struct evport_data *evpd;
+ int i;
/*
* Disable event ports when this environment variable is set
*/
return (NULL);
}
evpd->ed_nevents = DEFAULT_NFDS;
- memset(&evpd->ed_pending, 0, EVENTS_PER_GETN * sizeof(struct fd_info*));
+ for (i = 0; i < EVENTS_PER_GETN; i++)
+ evpd->ed_pending[i] = -1;
evsignal_init(base);
epdp->ed_fds = tmp;
memset((char*) (epdp->ed_fds + oldsize), 0,
(newsize - oldsize)*sizeof(struct fd_info));
-
- /* The ev_pending array contains pointers into the released array. */
- for (ii = 0; ii < EVENTS_PER_GETN; ++ii) {
- if (epdp->ed_pending[ii] != 0) {
- int offset = epdp->ed_pending[ii] - old;
- epdp->ed_pending[ii] = epdp->ed_fds + offset;
- }
- }
-
epdp->ed_nevents = newsize;
check_evportop(epdp);
int sysevents = FDI_TO_SYSEVENTS(fdip);
if (sysevents != 0) {
- if ((-1 == port_associate(epdp->ed_port, PORT_SOURCE_FD,
- fd, sysevents, NULL))) {
- perror("port_associate");
- return (-1);
- }
- } else {
- if (-1 == port_dissociate(epdp->ed_port, PORT_SOURCE_FD, fd)) {
- perror("port_dissociate");
+ if (port_associate(epdp->ed_port, PORT_SOURCE_FD,
+ fd, sysevents, NULL) == -1) {
+ event_warn("port_associate");
return (-1);
}
}
* loop below.
*/
for (i = 0; i < EVENTS_PER_GETN; ++i) {
- struct fd_info *fdi = epdp->ed_pending[i];
+ struct fd_info *fdi = NULL;
+ if (epdp->ed_pending[i] != -1) {
+ fdi = &(epdp->ed_fds[epdp->ed_pending[i]]);
+ }
if (fdi != NULL && FDI_HAS_EVENTS(fdi)) {
int fd = FDI_HAS_READ(fdi) ? fdi->fdi_revt->ev_fd :
fdi->fdi_wevt->ev_fd;
reassociate(epdp, fdi, fd);
- epdp->ed_pending[i] = NULL;
+ epdp->ed_pending[i] = -1;
}
}
if (nevents == 0)
return (0);
} else {
- perror("port_getn");
+ event_warn("port_getn");
return (-1);
}
} else if (base->sig.evsignal_caught) {
check_evportop(epdp);
check_event(pevt);
+ epdp->ed_pending[i] = fd;
/*
* Figure out what kind of event it was
event_del(ev);
event_active(ev, res, 1);
}
-
- /*
- * If there are still events (they haven't been deleted), then
- * we must reassociate the port, since the event port interface
- * dissociates them automatically.
- *
- * But we can't do it right away, because the event hasn't
- * handled this event yet, so of course there's still data
- * waiting!
- */
- if(FDI_HAS_EVENTS(fdi)) {
- epdp->ed_pending[i] = fdi;
- }
} /* end of all events gotten */
check_evportop(epdp);
{
struct evport_data *evpd = arg;
struct fd_info *fdi;
+ int i;
+ int associated = 1;
check_evportop(evpd);
return (-1);
}
+ for (i = 0; i < EVENTS_PER_GETN; ++i) {
+ if (evpd->ed_pending[i] == ev->ev_fd) {
+ associated = 0;
+ break;
+ }
+ }
fdi = &evpd->ed_fds[ev->ev_fd];
if (ev->ev_events & EV_READ)
if (ev->ev_events & EV_WRITE)
fdi->fdi_wevt = NULL;
- return reassociate(evpd, fdi, ev->ev_fd);
+ if (associated) {
+ if (!FDI_HAS_EVENTS(fdi) &&
+ port_dissociate(evpd->ed_port, PORT_SOURCE_FD,
+ ev->ev_fd) == -1) {
+ /*
+ * Ignre 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, ev->ev_fd));
+ }
+ }
+ } else {
+ if (fdi->fdi_revt == NULL && fdi->fdi_wevt == NULL) {
+ evpd->ed_pending[i] = -1;
+ }
+ }
+ return 0;
}