aboutsummaryrefslogtreecommitdiffstats
path: root/core/fs/pxe/tcp.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2011-04-23 20:48:42 -0700
committerH. Peter Anvin <hpa@zytor.com>2011-04-23 20:50:00 -0700
commit6c5e4a4bcfc991a6e578f65976891bcde31d0c56 (patch)
treed8e2e29e59705ed4bfe8651a3c85b193e2007452 /core/fs/pxe/tcp.c
parent0eefacc5fd49dae600ab86b14557578efd6a2508 (diff)
downloadsyslinux-6c5e4a4bcfc991a6e578f65976891bcde31d0c56.tar.gz
syslinux-6c5e4a4bcfc991a6e578f65976891bcde31d0c56.tar.xz
syslinux-6c5e4a4bcfc991a6e578f65976891bcde31d0c56.zip
pxe: move operations common to TCP-based protocols to a common file
Move operations that are common to all TCP-based protocols into a common file, tcp.c. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'core/fs/pxe/tcp.c')
-rw-r--r--core/fs/pxe/tcp.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/core/fs/pxe/tcp.c b/core/fs/pxe/tcp.c
new file mode 100644
index 00000000..af0cffcb
--- /dev/null
+++ b/core/fs/pxe/tcp.c
@@ -0,0 +1,72 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2011 Intel Corporation; author: H. Peter Anvin
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston MA 02110-1301, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * tcp.c
+ *
+ * Common operations for TCP-based network protocols
+ */
+
+#include <lwip/api.h>
+#include "pxe.h"
+#include "../../../version.h"
+#include "url.h"
+
+void tcp_close_file(struct inode *inode)
+{
+ struct pxe_pvt_inode *socket = PVT(inode);
+ if (socket->buf) {
+ netbuf_delete(socket->buf);
+ socket->buf = NULL;
+ }
+ if (socket->conn) {
+ netconn_delete(socket->conn);
+ socket->conn = NULL;
+ }
+}
+
+void tcp_fill_buffer(struct inode *inode)
+{
+ struct pxe_pvt_inode *socket = PVT(inode);
+ void *data;
+ u16_t len;
+ err_t err;
+
+ /* Clean up or advance an inuse netbuf */
+ if (socket->buf) {
+ if (netbuf_next(socket->buf) < 0) {
+ netbuf_delete(socket->buf);
+ socket->buf = NULL;
+ }
+ }
+ /* If needed get a new netbuf */
+ if (!socket->buf) {
+ socket->buf = netconn_recv(socket->conn);
+ if (!socket->buf) {
+ socket->tftp_goteof = 1;
+ if (inode->size == -1)
+ inode->size = socket->tftp_filepos;
+ tcp_close_file(inode);
+ return;
+ }
+ }
+ /* Report the current fragment of the netbuf */
+ err = netbuf_data(socket->buf, &data, &len);
+ if (err) {
+ printf("netbuf_data err: %d\n", err);
+ kaboom();
+ }
+ socket->tftp_dataptr = data;
+ socket->tftp_filepos += len;
+ socket->tftp_bytesleft = len;
+ return;
+}