]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/serial.cpp
Add FILE_FLAG_OVERLAPPED in a couple of places
[libs/core.git] / source / io / serial.cpp
index 74af366856cd6ceaf99866e00d977e2108c1803c..2ed11ae9fddd900b4ab695a2acc05770deaf5e18 100644 (file)
@@ -149,7 +149,8 @@ void set_stop_bits(DeviceState &state, unsigned bits)
 namespace Msp {
 namespace IO {
 
-Serial::Serial(const string &descr)
+Serial::Serial(const string &descr):
+       reader(handle, 1024)
 {
        string::size_type comma = descr.find(',');
        string port = descr.substr(0, comma);
@@ -157,7 +158,7 @@ Serial::Serial(const string &descr)
 #ifdef WIN32
        port = "\\\\.\\"+port;
 
-       *handle = CreateFile(port.c_str(), GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+       *handle = CreateFile(port.c_str(), GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, 0);
        if(!handle)
                throw system_error(format("CreateFile(%s)", port));
        mode = M_READ|M_WRITE;
@@ -291,16 +292,11 @@ unsigned Serial::do_read(char *buf, unsigned size)
        if(size==0)
                return 0;
 
-       return sys_read(handle, buf, size);
-}
+       unsigned ret = reader.read(buf, size);
+       if(ret==0)
+               set_eof();
 
-const Handle &Serial::get_event_handle()
-{
-#ifdef WIN32
-       throw logic_error("Serial port events not supported on win32 yet");
-#else
-       return handle;
-#endif
+       return ret;
 }
 
 } // namespace IO