From patchwork Thu Feb 21 12:54:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 222277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2A552C0086 for ; Thu, 21 Feb 2013 23:55:51 +1100 (EST) Received: from localhost ([::1]:34053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Vgk-00089J-2r for incoming@patchwork.ozlabs.org; Thu, 21 Feb 2013 07:55:50 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8VgX-0007zC-2p for qemu-devel@nongnu.org; Thu, 21 Feb 2013 07:55:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8VgU-0002JS-PO for qemu-devel@nongnu.org; Thu, 21 Feb 2013 07:55:36 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:46297) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8VgU-0002JM-Jb for qemu-devel@nongnu.org; Thu, 21 Feb 2013 07:55:34 -0500 Received: by mail-pa0-f48.google.com with SMTP id hz10so4712517pad.21 for ; Thu, 21 Feb 2013 04:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=sp2OSKiUbUBV2XNbAbUMogQg6TDDXjhP5nRj34uzFHE=; b=WO0/4RXF7PcigTGFjZsH3stm8Vl1lfDkm7oe+F6P7GryMYAZwCv1kDoi9hpE/+tYew LwjM0II6AAXkZwbNQuRXTshdoGdMgWMha8GGcSOMG2mFn0eBdyuo1nsXS5pqKFVemkeJ V4KXFiD3POTUf4mgG8OENE+eenIOORtGJlUMlPpXImMu2gkpDa0u7hpjNwtksDYrYtSA 6JFv5aaxwLNL9xFYTvTvzK4sPbSWfCI1phRQXGkbGfyQjX0Is76iZqzoighmFIeWuIGK IGRQJf5GwfJtarYdaEo+Mm/g5S4176PVdp+oj1HS35UnFvXCFJAwHutx0S5Xwnl43aRu 9ebA== X-Received: by 10.66.232.130 with SMTP id to2mr7988390pac.161.1361451333744; Thu, 21 Feb 2013 04:55:33 -0800 (PST) Received: from localhost ([222.128.155.155]) by mx.google.com with ESMTPS id ww9sm25279979pbc.41.2013.02.21.04.55.29 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 21 Feb 2013 04:55:32 -0800 (PST) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Thu, 21 Feb 2013 20:54:47 +0800 Message-Id: <1361451293-5181-4-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1361451293-5181-1-git-send-email-qemulist@gmail.com> References: <1361451293-5181-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.220.48 Cc: Stefan Hajnoczi , Anthony Liguori Subject: [Qemu-devel] [PATCH 3/9] event poll: make epoll work for normal fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Liu Ping Fan When event poll can work with normal fd, we can port them onto the event loop. Signed-off-by: Liu Ping Fan --- hw/dataplane/event-poll.c | 36 ++++++++++++++++++++++++++++++++++++ hw/dataplane/event-poll.h | 8 ++++++++ 2 files changed, 44 insertions(+), 0 deletions(-) diff --git a/hw/dataplane/event-poll.c b/hw/dataplane/event-poll.c index 2b55c6e..b7dea53 100644 --- a/hw/dataplane/event-poll.c +++ b/hw/dataplane/event-poll.c @@ -32,6 +32,42 @@ void event_poll_add(EventPoll *poll, EventHandler *handler, } } +void event_poll_add_fd(EventPoll *poll, int fd, uint32_t type, + EventHandler *handler) +{ + struct epoll_event event = { + .events = type, + .data.ptr = handler, + }; + + if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_ADD, fd, &event) != 0) { + fprintf(stderr, "failed to add event fd handler to epoll: %m\n"); + exit(1); + } + +} +void event_poll_del_fd(EventPoll *poll, int fd) +{ + if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_DEL, fd, NULL) != 0) { + fprintf(stderr, "failed to del event handler to epoll: %m\n"); + exit(1); + } +} + + +void event_poll_modify_fd(EventPoll *poll, int fd, uint32_t type, + EventHandler *handler) +{ + struct epoll_event event = { + .events = type, + .data.ptr = handler, + }; + if (epoll_ctl(poll->epoll_fd, EPOLL_CTL_MOD, fd, &event) != 0) { + fprintf(stderr, "failed to modify event handler to epoll: %m\n"); + exit(1); + } +} + /* Event callback for stopping event_poll() */ static void handle_stop(EventHandler *handler) { diff --git a/hw/dataplane/event-poll.h b/hw/dataplane/event-poll.h index 3e8d3ec..606138c 100644 --- a/hw/dataplane/event-poll.h +++ b/hw/dataplane/event-poll.h @@ -22,6 +22,8 @@ typedef void EventCallback(EventHandler *handler); struct EventHandler { EventNotifier *notifier; /* eventfd */ EventCallback *callback; /* callback function */ + void *opaque; + int fd; /* normal fd*/ }; typedef struct { @@ -32,6 +34,12 @@ typedef struct { void event_poll_add(EventPoll *poll, EventHandler *handler, EventNotifier *notifier, EventCallback *callback); +void event_poll_add_fd(EventPoll *poll, int fd, uint32_t type, + EventHandler *handler); +void event_poll_del_fd(EventPoll *poll, int fd); +void event_poll_modify_fd(EventPoll *poll, int fd, uint32_t type, + EventHandler *handler); + void event_poll_init(EventPoll *poll); void event_poll_cleanup(EventPoll *poll); void event_poll(EventPoll *poll);