Use stdio for reading jobs for SCP.
authorCarl Hetherington <cth@carlh.net>
Tue, 24 Jul 2012 19:53:46 +0000 (20:53 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 24 Jul 2012 19:53:46 +0000 (20:53 +0100)
src/lib/exceptions.h
src/lib/scp_dcp_job.cc
wscript

index b66d7baa7593bdab18b60335d7d4d7b54c7afbd3..6b567805b1fcd46ac7d1c78c13423624ef1f5b3d 100644 (file)
@@ -127,7 +127,7 @@ public:
        /** @param f File that we were trying to read from.
         *  @param e errno value, or 0.
         */
-       ReadFileError (std::string f, int e)
+       ReadFileError (std::string f, int e = 0)
                : FileError ("", f)
        {
                std::stringstream s;
index ffa04e0183637a19aea3e6d91a535debef278fc3..760e85bd0bfccce0b45886b20a01c1baba93ce99 100644 (file)
@@ -183,9 +183,9 @@ SCPDCPJob::run ()
                
                int to_do = filesystem::file_size (*i);
                ssh_scp_push_file (sc.scp, leaf.c_str(), to_do, S_IRUSR | S_IWUSR);
-               
-               int fd = open (filesystem::path (*i).string().c_str(), O_RDONLY);
-               if (fd == 0) {
+
+               FILE* f = fopen (filesystem::path (*i).string().c_str(), "rb");
+               if (f == 0) {
                        stringstream s;
                        s << "Could not open " << *i << " to send";
                        throw NetworkError (s.str ());
@@ -193,7 +193,11 @@ SCPDCPJob::run ()
 
                while (to_do > 0) {
                        int const t = min (to_do, buffer_size);
-                       read (fd, buffer, t);
+                       size_t const read = fread (buffer, 1, t, f);
+                       if (read != size_t (t)) {
+                               throw ReadFileError (filesystem::path (*i).string());
+                       }
+                       
                        r = ssh_scp_write (sc.scp, buffer, t);
                        if (r != SSH_OK) {
                                stringstream s;
@@ -205,6 +209,8 @@ SCPDCPJob::run ()
                        
                        set_progress ((double) bytes_transferred / bytes_to_transfer);
                }
+
+               fclose (f);
        }
        
        set_progress (1);
diff --git a/wscript b/wscript
index 531f5ac8e3f8d8869a7d3aa9f2ff149a4f8b70d6..2c310f9d518bf3d316576b3a9fe1a0378451f4a6 100644 (file)
--- a/wscript
+++ b/wscript
@@ -24,7 +24,7 @@ def configure(conf):
 
     if conf.options.target_windows:
         conf.env.append_value('CXXFLAGS', ['-DDVDOMATIC_WINDOWS'])
-        conf.env.append_value('LINKFLAGS', '-mwindows')
+#        conf.env.append_value('LINKFLAGS', '-mwindows')
         conf.options.disable_player = True
         conf.check(lib = 'ws2_32', uselib_store = 'WINSOCK2', msg = "Checking for library winsock2")
         boost_lib_suffix = '-mt'