瀏覽代碼

[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 年之前
父節點
當前提交
daa8ed9274
共有 3 個文件被更改,包括 20 次插入6 次删除
  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 查看文件

295
  * blocked during shutdown.
295
  * blocked during shutdown.
296
  */
296
  */
297
 void intf_restart ( struct interface *intf, int rc ) {
297
 void intf_restart ( struct interface *intf, int rc ) {
298
-	struct interface_descriptor *desc = intf->desc;
299
 
298
 
300
 	/* Shut down the interface */
299
 	/* Shut down the interface */
301
 	intf_shutdown ( intf, rc );
300
 	intf_shutdown ( intf, rc );
309
 	 * infinite loop as the intf_close() operations on each side
308
 	 * infinite loop as the intf_close() operations on each side
310
 	 * of the link call each other recursively.
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 查看文件

123
 	struct refcnt *refcnt;
123
 	struct refcnt *refcnt;
124
 	/** Interface descriptor */
124
 	/** Interface descriptor */
125
 	struct interface_descriptor *desc;
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
 extern void intf_plug ( struct interface *intf, struct interface *dest );
133
 extern void intf_plug ( struct interface *intf, struct interface *dest );
166
 	intf->dest = &null_intf;
171
 	intf->dest = &null_intf;
167
 	intf->refcnt = refcnt;
172
 	intf->refcnt = refcnt;
168
 	intf->desc = desc;
173
 	intf->desc = desc;
174
+	intf->original = desc;
169
 }
175
 }
170
 
176
 
171
 /**
177
 /**
177
 		.dest = &null_intf,		\
183
 		.dest = &null_intf,		\
178
 		.refcnt = NULL,			\
184
 		.refcnt = NULL,			\
179
 		.desc = &(descriptor),		\
185
 		.desc = &(descriptor),		\
186
+		.original = &(descriptor),	\
180
 	}
187
 	}
181
 
188
 
182
 /**
189
 /**
236
  */
243
  */
237
 #define INTF_INTF_DBG( intf, dest ) INTF_DBG ( intf ), INTF_DBG ( dest )
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
 #endif /* _IPXE_INTERFACE_H */
257
 #endif /* _IPXE_INTERFACE_H */

+ 1
- 4
src/net/tcp/httpcore.c 查看文件

787
 	/* Restart content decoding interfaces (which may be attached
787
 	/* Restart content decoding interfaces (which may be attached
788
 	 * to the same object).
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
 	intf_restart ( &http->content, http->response.rc );
791
 	intf_restart ( &http->content, http->response.rc );
793
 	intf_restart ( &http->transfer, http->response.rc );
792
 	intf_restart ( &http->transfer, http->response.rc );
794
-	http->content.desc = &http_content_desc;
795
-	http->transfer.desc = &http_transfer_desc;
796
 	intf_plug_plug ( &http->transfer, &http->content );
793
 	intf_plug_plug ( &http->transfer, &http->content );
797
 	http->len = 0;
794
 	http->len = 0;
798
 	assert ( http->remaining == 0 );
795
 	assert ( http->remaining == 0 );

Loading…
取消
儲存