소스 검색

Reorder functions to more closely reflect the flow of control

tags/v0.9.3
Michael Brown 18 년 전
부모
커밋
08da93a311
2개의 변경된 파일97개의 추가작업 그리고 103개의 파일을 삭제
  1. 50
    47
      src/core/download.c
  2. 47
    56
      src/net/tcp/http.c

+ 50
- 47
src/core/download.c 파일 보기

@@ -30,6 +30,8 @@
30 30
 #include <gpxe/ebuffer.h>
31 31
 #include <gpxe/download.h>
32 32
 
33
+static struct async_operations download_async_operations;
34
+
33 35
 /** Registered download protocols */
34 36
 static struct download_protocol download_protocols[0]
35 37
 	__table_start ( struct download_protocol, download_protocols );
@@ -53,53 +55,6 @@ static struct download_protocol * find_protocol ( const char *name ) {
53 55
 	return NULL;
54 56
 }
55 57
 
56
-/** Free download resources */
57
-static void download_reap ( struct async *async ) {
58
-	struct download *download =
59
-		container_of ( async, struct download, async );
60
-
61
-	free ( download );
62
-}
63
-
64
-/**
65
- * Handle download termination
66
- *
67
- * @v async		Download asynchronous operation
68
- * @v signal		SIGCHLD
69
- */
70
-static void download_sigchld ( struct async *async,
71
-			       enum signal signal __unused ) {
72
-	struct download *download =
73
-		container_of ( async, struct download, async );
74
-	int rc;
75
-
76
-	/* Reap child */
77
-	async_wait ( async, &rc, 1 );
78
-
79
-	/* Clean up */
80
-	if ( rc == 0 ) {
81
-		/* Transfer ownership of buffer to parent */
82
-		*(download->data) = download->buffer.addr;
83
-		*(download->len) = download->buffer.fill;
84
-	} else {
85
-		/* Discard the buffer */
86
-		ufree ( download->buffer.addr );
87
-	}
88
-	free_uri ( download->uri );
89
-	download->uri = NULL;
90
-
91
-	/* Terminate ourselves */
92
-	async_done ( async, rc );
93
-}
94
-
95
-/** Download asynchronous operations */
96
-static struct async_operations download_async_operations = {
97
-	.reap = download_reap,
98
-	.signal = {
99
-		[SIGCHLD] = download_sigchld,
100
-	},
101
-};
102
-
103 58
 /**
104 59
  * Start download
105 60
  *
@@ -170,3 +125,51 @@ int start_download ( const char *uri_string, struct async *parent,
170 125
 	free ( download );
171 126
 	return rc;
172 127
 }
128
+
129
+/**
130
+ * Handle download termination
131
+ *
132
+ * @v async		Download asynchronous operation
133
+ * @v signal		SIGCHLD
134
+ */
135
+static void download_sigchld ( struct async *async,
136
+			       enum signal signal __unused ) {
137
+	struct download *download =
138
+		container_of ( async, struct download, async );
139
+	int rc;
140
+
141
+	/* Reap child */
142
+	async_wait ( async, &rc, 1 );
143
+
144
+	/* Clean up */
145
+	if ( rc == 0 ) {
146
+		/* Transfer ownership of buffer to parent */
147
+		*(download->data) = download->buffer.addr;
148
+		*(download->len) = download->buffer.fill;
149
+	} else {
150
+		/* Discard the buffer */
151
+		ufree ( download->buffer.addr );
152
+	}
153
+	free_uri ( download->uri );
154
+	download->uri = NULL;
155
+
156
+	/* Terminate ourselves */
157
+	async_done ( async, rc );
158
+}
159
+
160
+/**
161
+ * Free download resources
162
+ *
163
+ * @v async		Download asynchronous operation
164
+ */
165
+static void download_reap ( struct async *async ) {
166
+	free ( container_of ( async, struct download, async ) );
167
+}
168
+
169
+/** Download asynchronous operations */
170
+static struct async_operations download_async_operations = {
171
+	.reap = download_reap,
172
+	.signal = {
173
+		[SIGCHLD] = download_sigchld,
174
+	},
175
+};

+ 47
- 56
src/net/tcp/http.c 파일 보기

@@ -37,6 +37,8 @@
37 37
 #include <gpxe/download.h>
38 38
 #include <gpxe/http.h>
39 39
 
40
+static struct async_operations http_async_operations;
41
+
40 42
 static inline struct http_request *
41 43
 tcp_to_http ( struct tcp_application *app ) {
42 44
 	return container_of ( app, struct http_request, tcp );
@@ -357,15 +359,45 @@ static struct tcp_operations http_tcp_operations = {
357 359
 };
358 360
 
359 361
 /**
360
- * Reap asynchronous operation
362
+ * Initiate a HTTP connection
361 363
  *
362
- * @v async		Asynchronous operation
364
+ * @v uri		Uniform Resource Identifier
365
+ * @v buffer		Buffer into which to download file
366
+ * @v parent		Parent asynchronous operation
367
+ * @ret rc		Return status code
363 368
  */
364
-static void http_reap ( struct async *async ) {
365
-	struct http_request *http =
366
-		container_of ( async, struct http_request, async );
369
+int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
370
+	struct http_request *http = NULL;
371
+	int rc;
372
+
373
+	/* Allocate and populate HTTP structure */
374
+	http = malloc ( sizeof ( *http ) );
375
+	if ( ! http )
376
+		return -ENOMEM;
377
+	memset ( http, 0, sizeof ( *http ) );
378
+	http->uri = uri;
379
+	http->buffer = buffer;
380
+	async_init ( &http->async, &http_async_operations, parent );
381
+
382
+
383
+#warning "Quick name resolution hack"
384
+	extern int dns_resolv ( const char *name,
385
+				struct sockaddr *sa,
386
+				struct async *parent );
387
+		
388
+	if ( ( rc = dns_resolv ( uri->host, &http->server,
389
+				 &http->async ) ) != 0 )
390
+		goto err;
391
+
367 392
 
393
+	return 0;
394
+
395
+ err:
396
+	DBGC ( http, "HTTP %p could not create request: %s\n", 
397
+	       http, strerror ( rc ) );
398
+	async_uninit ( &http->async );
368 399
 	free ( http );
400
+	return rc;
369 401
 }
370 402
 
371 403
 /**
@@ -380,10 +412,8 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
380 412
 	struct sockaddr_tcpip *st = ( struct sockaddr_tcpip * ) &http->server;
381 413
 	int rc;
382 414
 
383
-	/* Reap child */
384
-	async_wait ( async, &rc, 1 );
385
-
386 415
 	/* If name resolution failed, abort now */
416
+	async_wait ( async, &rc, 1 );
387 417
 	if ( rc != 0 ) {
388 418
 		http_done ( http, rc );
389 419
 		return;
@@ -400,6 +430,15 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
400 430
 	}
401 431
 }
402 432
 
433
+/**
434
+ * Free HTTP connection
435
+ *
436
+ * @v async		Asynchronous operation
437
+ */
438
+static void http_reap ( struct async *async ) {
439
+	free ( container_of ( async, struct http_request, async ) );
440
+}
441
+
403 442
 /** HTTP asynchronous operations */
404 443
 static struct async_operations http_async_operations = {
405 444
 	.reap = http_reap,
@@ -408,54 +447,6 @@ static struct async_operations http_async_operations = {
408 447
 	},
409 448
 };
410 449
 
411
-/**
412
- * Initiate a HTTP connection
413
- *
414
- * @v uri		Uniform Resource Identifier
415
- * @v buffer		Buffer into which to download file
416
- * @v parent		Parent asynchronous operation
417
- * @ret rc		Return status code
418
- */
419
-int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
420
-	struct http_request *http = NULL;
421
-	int rc;
422
-
423
-	/* Sanity check */
424
-	if ( ! uri->host ) {
425
-		rc = -EINVAL;
426
-		goto err;
427
-	}
428
-
429
-	/* Allocate and populate HTTP structure */
430
-	http = malloc ( sizeof ( *http ) );
431
-	if ( ! http )
432
-		return -ENOMEM;
433
-	memset ( http, 0, sizeof ( *http ) );
434
-	http->uri = uri;
435
-	http->buffer = buffer;
436
-	async_init ( &http->async, &http_async_operations, parent );
437
-
438
-
439
-#warning "Quick name resolution hack"
440
-	extern int dns_resolv ( const char *name,
441
-				struct sockaddr *sa,
442
-				struct async *parent );
443
-		
444
-	if ( ( rc = dns_resolv ( uri->host, &http->server,
445
-				 &http->async ) ) != 0 )
446
-		goto err;
447
-
448
-
449
-	return 0;
450
-
451
- err:
452
-	DBGC ( http, "HTTP %p could not create request: %s\n", 
453
-	       http, strerror ( rc ) );
454
-	async_uninit ( &http->async );
455
-	free ( http );
456
-	return rc;
457
-}
458
-
459 450
 /** HTTP download protocol */
460 451
 struct download_protocol http_download_protocol __download_protocol = {
461 452
 	.name = "http",

Loading…
취소
저장