1 From c1b408d0c9d836e0a95d1e0695c0c6c605ceb368 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= <hpoussin@reactos.org>
3 Date: Mon, 10 Sep 2012 20:52:25 +0200
4 Subject: [PATCH] slirp: improve TFTP performance
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 When transferring a file, keep it open during the whole transfer,
10 instead of opening/closing it for each block.
12 Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
13 Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
14 Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
15 (cherry picked from commit 78be056628c76ff73eedeade86fde44b97343c79)
17 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
19 slirp/tftp.c | 32 ++++++++++++++++++--------------
21 2 files changed, 19 insertions(+), 14 deletions(-)
23 diff --git a/slirp/tftp.c b/slirp/tftp.c
24 index b78765f..520dbd6 100644
27 @@ -37,6 +37,10 @@ static inline void tftp_session_update(struct tftp_session *spt)
29 static void tftp_session_terminate(struct tftp_session *spt)
35 g_free(spt->filename);
38 @@ -54,7 +58,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
40 /* sessions time out after 5 inactive seconds */
41 if ((int)(curtime - spt->timestamp) > 5000) {
42 - g_free(spt->filename);
43 + tftp_session_terminate(spt);
47 @@ -64,6 +68,7 @@ static int tftp_session_allocate(Slirp *slirp, struct tftp_t *tp)
49 memset(spt, 0, sizeof(*spt));
50 memcpy(&spt->client_ip, &tp->ip.ip_src, sizeof(spt->client_ip));
52 spt->client_port = tp->udp.uh_sport;
55 @@ -95,24 +100,23 @@ static int tftp_session_find(Slirp *slirp, struct tftp_t *tp)
56 static int tftp_read_data(struct tftp_session *spt, uint16_t block_nr,
57 uint8_t *buf, int len)
62 - fd = open(spt->filename, O_RDONLY | O_BINARY);
69 + spt->fd = open(spt->filename, O_RDONLY | O_BINARY);
73 - lseek(fd, block_nr * 512, SEEK_SET);
78 - bytes_read = read(fd, buf, len);
81 + lseek(spt->fd, block_nr * 512, SEEK_SET);
84 + bytes_read = read(spt->fd, buf, len);
91 static int tftp_send_oack(struct tftp_session *spt,
92 diff --git a/slirp/tftp.h b/slirp/tftp.h
93 index 72e5e91..9c364ea 100644
96 @@ -33,6 +33,7 @@ struct tftp_t {
102 struct in_addr client_ip;
103 uint16_t client_port;