diff options
| author | Michael Brown | 2007-01-18 14:10:26 +0100 |
|---|---|---|
| committer | Michael Brown | 2007-01-18 14:10:26 +0100 |
| commit | 08da93a311261472a6ebd8426ebcd492ca435851 (patch) | |
| tree | ca6e8f549cc6d2ca6a00432e40d137c273606999 /src/core | |
| parent | Don't always zero memory in malloc(). This saves around 2us on a (diff) | |
| download | ipxe-08da93a311261472a6ebd8426ebcd492ca435851.tar.gz ipxe-08da93a311261472a6ebd8426ebcd492ca435851.tar.xz ipxe-08da93a311261472a6ebd8426ebcd492ca435851.zip | |
Reorder functions to more closely reflect the flow of control
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/download.c | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/core/download.c b/src/core/download.c index f748d0233..bc8901272 100644 --- a/src/core/download.c +++ b/src/core/download.c @@ -30,6 +30,8 @@ #include <gpxe/ebuffer.h> #include <gpxe/download.h> +static struct async_operations download_async_operations; + /** Registered download protocols */ static struct download_protocol download_protocols[0] __table_start ( struct download_protocol, download_protocols ); @@ -53,53 +55,6 @@ static struct download_protocol * find_protocol ( const char *name ) { return NULL; } -/** Free download resources */ -static void download_reap ( struct async *async ) { - struct download *download = - container_of ( async, struct download, async ); - - free ( download ); -} - -/** - * Handle download termination - * - * @v async Download asynchronous operation - * @v signal SIGCHLD - */ -static void download_sigchld ( struct async *async, - enum signal signal __unused ) { - struct download *download = - container_of ( async, struct download, async ); - int rc; - - /* Reap child */ - async_wait ( async, &rc, 1 ); - - /* Clean up */ - if ( rc == 0 ) { - /* Transfer ownership of buffer to parent */ - *(download->data) = download->buffer.addr; - *(download->len) = download->buffer.fill; - } else { - /* Discard the buffer */ - ufree ( download->buffer.addr ); - } - free_uri ( download->uri ); - download->uri = NULL; - - /* Terminate ourselves */ - async_done ( async, rc ); -} - -/** Download asynchronous operations */ -static struct async_operations download_async_operations = { - .reap = download_reap, - .signal = { - [SIGCHLD] = download_sigchld, - }, -}; - /** * Start download * @@ -170,3 +125,51 @@ int start_download ( const char *uri_string, struct async *parent, free ( download ); return rc; } + +/** + * Handle download termination + * + * @v async Download asynchronous operation + * @v signal SIGCHLD + */ +static void download_sigchld ( struct async *async, + enum signal signal __unused ) { + struct download *download = + container_of ( async, struct download, async ); + int rc; + + /* Reap child */ + async_wait ( async, &rc, 1 ); + + /* Clean up */ + if ( rc == 0 ) { + /* Transfer ownership of buffer to parent */ + *(download->data) = download->buffer.addr; + *(download->len) = download->buffer.fill; + } else { + /* Discard the buffer */ + ufree ( download->buffer.addr ); + } + free_uri ( download->uri ); + download->uri = NULL; + + /* Terminate ourselves */ + async_done ( async, rc ); +} + +/** + * Free download resources + * + * @v async Download asynchronous operation + */ +static void download_reap ( struct async *async ) { + free ( container_of ( async, struct download, async ) ); +} + +/** Download asynchronous operations */ +static struct async_operations download_async_operations = { + .reap = download_reap, + .signal = { + [SIGCHLD] = download_sigchld, + }, +}; |
