From commits-return-8421-apmail-apr-commits-archive=apr.apache.org@apr.apache.org Tue Jul 03 21:37:59 2007 Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 21612 invoked from network); 3 Jul 2007 21:37:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jul 2007 21:37:58 -0000 Received: (qmail 93017 invoked by uid 500); 3 Jul 2007 21:38:01 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 92977 invoked by uid 500); 3 Jul 2007 21:38:01 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 92966 invoked by uid 99); 3 Jul 2007 21:38:01 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 14:38:01 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 14:37:57 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 41ED51A981A; Tue, 3 Jul 2007 14:37:37 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r552989 - /apr/apr/trunk/poll/unix/port.c Date: Tue, 03 Jul 2007 21:37:37 -0000 To: commits@apr.apache.org From: davi@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070703213737.41ED51A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davi Date: Tue Jul 3 14:37:36 2007 New Revision: 552989 URL: http://svn.apache.org/viewvc?view=rev&rev=552989 Log: Solaris Event Ports backend for apr_pollcb. Also fixes the testpoll link errors on Solaris due to undefined symbols (apr_pollcb_* functions). Modified: apr/apr/trunk/poll/unix/port.c Modified: apr/apr/trunk/poll/unix/port.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/port.c?view=diff&rev=552989&r1=552988&r2=552989 ============================================================================== --- apr/apr/trunk/poll/unix/port.c (original) +++ apr/apr/trunk/poll/unix/port.c Tue Jul 3 14:37:36 2007 @@ -340,4 +340,134 @@ return rv; } +struct apr_pollcb_t { + apr_pool_t *pool; + apr_uint32_t nalloc; + port_event_t *port_set; + int port_fd; +}; + +static apr_status_t cb_cleanup(void *p_) +{ + apr_pollcb_t *pollcb = (apr_pollcb_t *) p_; + close(pollcb->port_fd); + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, + apr_uint32_t size, + apr_pool_t *p, + apr_uint32_t flags) +{ + int fd; + + fd = port_create(); + + if (fd < 0) { + *pollcb = NULL; + return apr_get_netos_error(); + } + + *pollcb = apr_palloc(p, sizeof(**pollcb)); + (*pollcb)->nalloc = size; + (*pollcb)->pool = p; + (*pollcb)->port_fd = fd; + (*pollcb)->port_set = apr_palloc(p, size * sizeof(port_event_t)); + apr_pool_cleanup_register(p, *pollcb, cb_cleanup, cb_cleanup); + + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_pollcb_add(apr_pollcb_t *pollcb, + apr_pollfd_t *descriptor) +{ + int ret, fd; + + if (descriptor->desc_type == APR_POLL_SOCKET) { + fd = descriptor->desc.s->socketdes; + } + else { + fd = descriptor->desc.f->filedes; + } + + ret = port_associate(pollcb->port_fd, PORT_SOURCE_FD, fd, + get_event(descriptor->reqevents), descriptor); + + if (ret == -1) { + return apr_get_netos_error(); + } + + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_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->port_fd, PORT_SOURCE_FD, fd); + + if (ret < 0) { + return APR_NOTFOUND; + } + + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_pollcb_poll(apr_pollcb_t *pollcb, + apr_interval_time_t timeout, + apr_pollcb_cb_t func, + void *baton) +{ + int ret; + apr_pollfd_t *pollfd; + struct timespec tv, *tvptr; + apr_status_t rv = APR_SUCCESS; + unsigned int i, nget = pollcb->nalloc; + + if (timeout < 0) { + tvptr = NULL; + } + else { + tv.tv_sec = (long) apr_time_sec(timeout); + tv.tv_nsec = (long) apr_time_usec(timeout) * 1000; + tvptr = &tv; + } + + ret = port_getn(pollcb->port_fd, pollcb->port_set, pollcb->nalloc, + &nget, tvptr); + + if (ret == -1) { + if (errno == ETIME || errno == EINTR) { + rv = APR_TIMEUP; + } + else { + rv = APR_EGENERAL; + } + } + else if (nget == 0) { + rv = APR_TIMEUP; + } + else { + for (i = 0; i < nget; i++) { + pollfd = (apr_pollfd_t *)(pollcb->port_set[i].portev_user); + pollfd->rtnevents = get_revent(pollcb->port_set[i].portev_events); + + rv = func(baton, pollfd); + if (rv) { + return rv; + } + } + } + + return rv; +} + #endif /* POLLSET_USES_PORT */