X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fserial.cpp;h=5d335b6faa82e0226c043d14ba3a158e8a84d8ae;hp=9df797109d840cc3554136035410977926bc802e;hb=d85465dd66a6fc80a9fb7868d1193a86abfe5b7c;hpb=31e72f50fbb34d86877e5110401c49ce3fefd4bb diff --git a/source/io/serial.cpp b/source/io/serial.cpp index 9df7971..5d335b6 100644 --- a/source/io/serial.cpp +++ b/source/io/serial.cpp @@ -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); @@ -208,11 +209,7 @@ Serial::~Serial() void Serial::close() { -#ifdef WIN32 - CloseHandle(*handle); -#else - ::close(*handle); -#endif + sys_close(handle); } void Serial::set_block(bool b) @@ -287,22 +284,7 @@ unsigned Serial::do_write(const char *buf, unsigned size) if(size==0) return 0; -#ifdef WIN32 - DWORD ret; - if(WriteFile(*handle, buf, size, &ret, 0)==0) - throw system_error("WriteFile"); -#else - int ret = ::write(*handle, buf, size); - if(ret==-1) - { - if(errno==EAGAIN) - return 0; - else - throw system_error("write"); - } -#endif - - return ret; + return sys_write(handle, buf, size); } unsigned Serial::do_read(char *buf, unsigned size) @@ -310,31 +292,7 @@ unsigned Serial::do_read(char *buf, unsigned size) if(size==0) return 0; -#ifdef WIN32 - DWORD ret; - if(ReadFile(*handle, buf, size, &ret, 0)==0) - throw system_error("ReadFile"); -#else - int ret = ::read(*handle, buf, size); - if(ret==-1) - { - if(errno==EAGAIN) - return 0; - else - throw system_error("read"); - } -#endif - - return ret; -} - -const Handle &Serial::get_event_handle() -{ -#ifdef WIN32 - throw logic_error("Serial port events not supported on win32 yet"); -#else - return handle; -#endif + return reader.read(buf, size); } } // namespace IO