summaryrefslogtreecommitdiffstats
path: root/src/core/hw.c
diff options
context:
space:
mode:
authorMichael Brown2007-05-15 18:53:46 +0200
committerMichael Brown2007-05-15 18:53:46 +0200
commitb1755462ab344ff758c3a1e6ae0d10a729d96d1b (patch)
tree858bb7ba3d439be957f6b9530a0040b26c49f3f2 /src/core/hw.c
parentData-transfer interface should now be functionally complete. (diff)
downloadipxe-b1755462ab344ff758c3a1e6ae0d10a729d96d1b.tar.gz
ipxe-b1755462ab344ff758c3a1e6ae0d10a729d96d1b.tar.xz
ipxe-b1755462ab344ff758c3a1e6ae0d10a729d96d1b.zip
Do not hold self-references. This then avoids the problem of having to
ensure that we only drop our self-reference exactly once. To maintain the guarantee that an object won't go out of scope unexpectedly while one of its event handlers is being called, the event-calling functions now automatically obtain and drop extra references.
Diffstat (limited to 'src/core/hw.c')
-rw-r--r--src/core/hw.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/core/hw.c b/src/core/hw.c
index 80cac99c..460ec583 100644
--- a/src/core/hw.c
+++ b/src/core/hw.c
@@ -22,7 +22,6 @@ static const char hw_msg[] = "Hello world!\n";
static void hw_finished ( struct hw *hw, int rc ) {
xfer_nullify ( &hw->xfer );
xfer_close ( &hw->xfer, rc );
- ref_put ( &hw->refcnt );
}
static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
@@ -31,13 +30,14 @@ static void hw_xfer_close ( struct xfer_interface *xfer, int rc ) {
hw_finished ( hw, rc );
}
-static int hw_xfer_request ( struct xfer_interface *xfer, off_t start __unused,
- int whence __unused, size_t len __unused ) {
+static void hw_xfer_request ( struct xfer_interface *xfer,
+ off_t start __unused, int whence __unused,
+ size_t len __unused ) {
struct hw *hw = container_of ( xfer, struct hw, xfer );
+ int rc;
- xfer_deliver_raw ( xfer, hw_msg, sizeof ( hw_msg ) );
- hw_finished ( hw, 0 );
- return 0;
+ rc = xfer_deliver_raw ( xfer, hw_msg, sizeof ( hw_msg ) );
+ hw_finished ( hw, rc );
}
static struct xfer_interface_operations hw_xfer_operations = {
@@ -52,13 +52,16 @@ static struct xfer_interface_operations hw_xfer_operations = {
static int hw_open ( struct xfer_interface *xfer, struct uri *uri __unused ) {
struct hw *hw;
+ /* Allocate and initialise structure */
hw = malloc ( sizeof ( *hw ) );
if ( ! hw )
return -ENOMEM;
memset ( hw, 0, sizeof ( *hw ) );
xfer_init ( &hw->xfer, &hw_xfer_operations, &hw->refcnt );
+ /* Attach parent interface, mortalise self, and return */
xfer_plug_plug ( &hw->xfer, xfer );
+ ref_put ( &hw->refcnt );
return 0;
}