Removed non portable -v flag for rm command.
[uftps.git] / send_file-splice.c
blob347c0a121e7bedfa40211e65a29c3302f6f4575d
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "uftps.h"
21 #include <unistd.h>
22 #define __USE_GNU
23 #include <fcntl.h>
27 * RETR command implementation using Linux new splice() system call to minimize
28 * memory copies. Due to the nature of the system call, it is not even
29 * necessary to perform the initial seek in case a REST command was issued.
31 void send_file (void)
33 int f;
34 long e;
35 off_t size, completed;
37 completed = SS.file_offset;
38 SS.file_offset = 0;
40 f = open_file(&size);
41 if (f == -1)
42 return;
44 e = open_data_channel();
45 if (e == -1)
47 close(f);
48 return;
51 reply_c("150 Sending file content.\r\n");
53 /* Main transfer loop */
54 while (completed < size && e != -1)
56 debug("Offset is %lld", (long long) completed);
57 e = splice(f, &completed, SS.data_sk, NULL, INT_MAX,
58 SPLICE_F_MOVE);
61 if (e != -1)
62 reply_c("226 File content sent.\r\n");
63 else
65 error("Sending file %s", SS.arg);
66 reply_c("426 Connection closed, transfer aborted.\r\n");
69 close(f);
70 closesocket(SS.data_sk);
71 SS.data_sk = -1;