pxe: disentangle the legacy and lwip stacks without #ifdef
[syslinux/sherbszt.git] / core / fs / pxe / tcp.c
blob90761978388c173811e4f2a564a8cc77b04bdf9f
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 Intel Corporation; author: H. Peter Anvin
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
14 * tcp.c
16 * Common operations for TCP-based network protocols
19 #include <lwip/api.h>
20 #include "pxe.h"
21 #include "../../../version.h"
22 #include "url.h"
24 void tcp_close_file(struct inode *inode)
26 struct pxe_pvt_inode *socket = PVT(inode);
28 if (socket->net.lwip.conn) {
29 netconn_delete(socket->net.lwip.conn);
30 socket->net.lwip.conn = NULL;
32 if (socket->net.lwip.buf) {
33 netbuf_delete(socket->net.lwip.buf);
34 socket->net.lwip.buf = NULL;
38 void tcp_fill_buffer(struct inode *inode)
40 struct pxe_pvt_inode *socket = PVT(inode);
41 void *data;
42 u16_t len;
43 err_t err;
45 /* Clean up or advance an inuse netbuf */
46 if (socket->net.lwip.buf) {
47 if (netbuf_next(socket->net.lwip.buf) < 0) {
48 netbuf_delete(socket->net.lwip.buf);
49 socket->net.lwip.buf = NULL;
52 /* If needed get a new netbuf */
53 if (!socket->net.lwip.buf) {
54 err = netconn_recv(socket->net.lwip.conn, &(socket->net.lwip.buf));
55 if (!socket->net.lwip.buf || err) {
56 socket->tftp_goteof = 1;
57 if (inode->size == -1)
58 inode->size = socket->tftp_filepos;
59 socket->ops->close(inode);
60 return;
63 /* Report the current fragment of the netbuf */
64 err = netbuf_data(socket->net.lwip.buf, &data, &len);
65 if (err) {
66 printf("netbuf_data err: %d\n", err);
67 kaboom();
69 socket->tftp_dataptr = data;
70 socket->tftp_filepos += len;
71 socket->tftp_bytesleft = len;
72 return;
75 const struct pxe_conn_ops tcp_conn_ops = {
76 .fill_buffer = tcp_fill_buffer,
77 .close = tcp_close_file,