Pārlūkot izejas kodu

[interface] Provide intf_reinit() to reinitialise nullified interfaces

Provide an abstraction intf_reinit() to restore the descriptor of a
previously nullified interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 gadus atpakaļ
vecāks
revīzija
daa8ed9274
3 mainītis faili ar 20 papildinājumiem un 6 dzēšanām
  1. 1
    2
      src/core/interface.c
  2. 18
    0
      src/include/ipxe/interface.h
  3. 1
    4
      src/net/tcp/httpcore.c

+ 1
- 2
src/core/interface.c Parādīt failu

@@ -295,7 +295,6 @@ void intf_shutdown ( struct interface *intf, int rc ) {
295 295
  * blocked during shutdown.
296 296
  */
297 297
 void intf_restart ( struct interface *intf, int rc ) {
298
-	struct interface_descriptor *desc = intf->desc;
299 298
 
300 299
 	/* Shut down the interface */
301 300
 	intf_shutdown ( intf, rc );
@@ -309,7 +308,7 @@ void intf_restart ( struct interface *intf, int rc ) {
309 308
 	 * infinite loop as the intf_close() operations on each side
310 309
 	 * of the link call each other recursively.
311 310
 	 */
312
-	intf->desc = desc;
311
+	intf_reinit ( intf );
313 312
 }
314 313
 
315 314
 /**

+ 18
- 0
src/include/ipxe/interface.h Parādīt failu

@@ -123,6 +123,11 @@ struct interface {
123 123
 	struct refcnt *refcnt;
124 124
 	/** Interface descriptor */
125 125
 	struct interface_descriptor *desc;
126
+	/** Original interface descriptor
127
+	 *
128
+	 * Used by intf_reinit().
129
+	 */
130
+	struct interface_descriptor *original;
126 131
 };
127 132
 
128 133
 extern void intf_plug ( struct interface *intf, struct interface *dest );
@@ -166,6 +171,7 @@ static inline void intf_init ( struct interface *intf,
166 171
 	intf->dest = &null_intf;
167 172
 	intf->refcnt = refcnt;
168 173
 	intf->desc = desc;
174
+	intf->original = desc;
169 175
 }
170 176
 
171 177
 /**
@@ -177,6 +183,7 @@ static inline void intf_init ( struct interface *intf,
177 183
 		.dest = &null_intf,		\
178 184
 		.refcnt = NULL,			\
179 185
 		.desc = &(descriptor),		\
186
+		.original = &(descriptor),	\
180 187
 	}
181 188
 
182 189
 /**
@@ -236,4 +243,15 @@ static inline void intf_init ( struct interface *intf,
236 243
  */
237 244
 #define INTF_INTF_DBG( intf, dest ) INTF_DBG ( intf ), INTF_DBG ( dest )
238 245
 
246
+/**
247
+ * Reinitialise an object interface
248
+ *
249
+ * @v intf		Object interface
250
+ */
251
+static inline void intf_reinit ( struct interface *intf ) {
252
+
253
+	/* Restore original interface descriptor */
254
+	intf->desc = intf->original;
255
+}
256
+
239 257
 #endif /* _IPXE_INTERFACE_H */

+ 1
- 4
src/net/tcp/httpcore.c Parādīt failu

@@ -787,12 +787,9 @@ static int http_transfer_complete ( struct http_transaction *http ) {
787 787
 	/* Restart content decoding interfaces (which may be attached
788 788
 	 * to the same object).
789 789
 	 */
790
-	intf_nullify ( &http->content );
791
-	intf_nullify ( &http->transfer );
790
+	intf_nullify ( &http->transfer ); /* avoid potential loops */
792 791
 	intf_restart ( &http->content, http->response.rc );
793 792
 	intf_restart ( &http->transfer, http->response.rc );
794
-	http->content.desc = &http_content_desc;
795
-	http->transfer.desc = &http_transfer_desc;
796 793
 	intf_plug_plug ( &http->transfer, &http->content );
797 794
 	http->len = 0;
798 795
 	assert ( http->remaining == 0 );

Notiek ielāde…
Atcelt
Saglabāt