mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
"Cancel" Implementation(windows only): Cancels all pending read and write operation from an other thread.
Unix also need add something like this.
This commit is contained in:
parent
33e5a31ab7
commit
b520457b14
@ -66,6 +66,9 @@ public:
|
||||
void
|
||||
open ();
|
||||
|
||||
void
|
||||
cancel();
|
||||
|
||||
void
|
||||
close ();
|
||||
|
||||
|
||||
@ -211,6 +211,10 @@ public:
|
||||
bool
|
||||
isOpen () const;
|
||||
|
||||
/*! Cancels all pending read and write operation. */
|
||||
void
|
||||
cancel();
|
||||
|
||||
/*! Closes the serial port. */
|
||||
void
|
||||
close ();
|
||||
|
||||
@ -274,9 +274,27 @@ Serial::SerialImpl::reconfigurePort ()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Serial::SerialImpl::cancel()
|
||||
{
|
||||
if (is_open_ == true) {
|
||||
if (fd_ != INVALID_HANDLE_VALUE) {
|
||||
int ret;
|
||||
ret = CancelIoEx(fd_, NULL);
|
||||
DWORD last_error = GetLastError();
|
||||
if (ret == 0 && last_error != ERROR_NOT_FOUND) {
|
||||
stringstream ss;
|
||||
ss << "Error while canceling serial port: " << last_error;
|
||||
THROW(IOException, ss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Serial::SerialImpl::close ()
|
||||
{
|
||||
this->cancel();
|
||||
if (is_open_ == true) {
|
||||
if (fd_ != INVALID_HANDLE_VALUE) {
|
||||
int ret;
|
||||
|
||||
@ -83,6 +83,12 @@ Serial::open ()
|
||||
pimpl_->open ();
|
||||
}
|
||||
|
||||
void
|
||||
Serial::cancel()
|
||||
{
|
||||
pimpl_->cancel();
|
||||
}
|
||||
|
||||
void
|
||||
Serial::close ()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user