changeset 123:6b11ca6bb0a3

Binary modes
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 27 Oct 2016 16:13:57 +0100
parents 2380d5865355
children 4ff643c1eccc
files vamp-server/convert.cpp vamp-server/server.cpp
diffstat 2 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/vamp-server/convert.cpp	Thu Oct 27 14:52:30 2016 +0100
+++ b/vamp-server/convert.cpp	Thu Oct 27 16:13:57 2016 +0100
@@ -44,6 +44,12 @@
 
 #include <capnp/serialize.h>
 
+// for _setmode stuff
+#ifdef _WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+
 using namespace std;
 using namespace json11;
 using namespace piper_vamp;
@@ -622,6 +628,23 @@
         usage();
     }
 
+#ifdef _WIN32
+    if (informat == "capnp") {
+        int result = _setmode(_fileno(stdin), _O_BINARY);
+        if (result == -1) {
+            cerr << "Failed to set binary mode on stdin, necessary for capnp format" << endl;
+            exit(1);
+        }
+    }
+    if (outformat == "capnp") {
+        int result = _setmode(_fileno(stdout), _O_BINARY);
+        if (result == -1) {
+            cerr << "Failed to set binary mode on stdout, necessary for capnp format" << endl;
+            exit(1);
+        }
+    }
+#endif
+
     while (true) {
 
         try {
--- a/vamp-server/server.cpp	Thu Oct 27 14:52:30 2016 +0100
+++ b/vamp-server/server.cpp	Thu Oct 27 16:13:57 2016 +0100
@@ -57,6 +57,12 @@
 static int pid = getpid();
 #endif
 
+// for _setmode stuff
+#ifdef _WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+
 using namespace std;
 using namespace json11;
 using namespace piper_vamp;
@@ -549,6 +555,21 @@
         usage();
     }
 
+#ifdef _WIN32
+    if (format == "capnp") {
+        int result = _setmode(_fileno(stdin), _O_BINARY);
+        if (result == -1) {
+            cerr << "Failed to set binary mode on stdin, necessary for capnp format" << endl;
+            exit(1);
+        }
+        result = _setmode(_fileno(stdout), _O_BINARY);
+        if (result == -1) {
+            cerr << "Failed to set binary mode on stdout, necessary for capnp format" << endl;
+            exit(1);
+        }
+    }
+#endif
+
     if (debug) {
         cerr << myname << " " << pid << ": waiting for format: " << format << endl;
     }