Comments (12)
Sorry if I haven't answered you for a few days, but I'm very busy these days.
Well, I'm not sure at 100% it works like that, but from the termiwin documentation:
"tcdrain() waits until all output written to the object referred to by fd has been transmitted."
So, isn't it supposed to be blocking?
from termiwin.
Yes, But you initialize the "CreateFile" in a way (as I understand it) that a Write-call only returns after write is complete ... you use it "non-overlapping" = "Synchron".
On Linux it seems to be "overlapping = asynchronous" by default (?) and so in Linus you do the write call and then wait using "drain" till it was written.
But on windows the Write returnsonly after the write ewas complete, so a drain wait forever because No other write can happen ...
from termiwin.
Ok, understood.
Have you tried to replace the last NULL argument with FILE_FLAG_OVERLAPPED ?
I can't try by myself at the moment.
from termiwin.
Yes, got an compile error then for some other code part, but not started to look deeper into it :-)
So it seems that you also need to consider other things when using overlapping mode.
If you want I can try to reproduce?!
from termiwin.
Hm ... tried it (it is the parameter after "OPEN_EXISTING") ... no compile error anymore ... hm ...
Will try later if it still works
from termiwin.
yeah sorry, was the 6th argument, not the 7th
from termiwin.
test bresults:
with
com.hComm = CreateFile(com.port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
I get Error 87 on write to that serial socket.
According to https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx it is:
ERROR_INVALID_PARAMETER
87 (0x57)
The parameter is incorrect.
Also tried "FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED" as in one Windows example from https://msdn.microsoft.com/de-de/library/windows/desktop/bb540534(v=vs.85).aspx
More infos an overlapping I found on https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx ...
for now I remove tcdrain usage with ifndef _WIN32 ... :-(
from termiwin.
Ok, digged deeper :-)
When you do Overlapping communication then you also need to provide an OVERLAPPED struct to Read/Write operations and they become Really async. means: Directly after write you only get an info back but no info on bytes written. This you need to query with other commands and such.
But I had an other idea: When I use this:
int tcdrain(int fd) {
if(fd != com.fd) return -1;
return FlushFileBuffers(com.hComm);
}
it works as expected or ?!
See also: https://www.winehq.org/pipermail/wine-patches/2013-August/126115.html
what you think ?!
from termiwin.
PS: I already use it that way in my version and it works :-)
from termiwin.
Ok, so it's enough to add FILE_FLAG_OVERLAPPED to createFile and change tcdrain in the way you did, right?
Does FILE_FLAG_OVERLAPPED have any effect if I use it but I don't need an asynchronous communication (I mean, should it be used only if someone needs an asynchronous communication, or it can be used everytime?)
from termiwin.
NO!
FILE_FLAG_OVERLAPPED at all means higher effort. So leave all as is and only use FlushFileBuffers in the drain method.
Normally all data are alreyd written when Write returns, and if there are some left then FlushFileBuffers will block until they are written (as drain means) ... if everything is already written FlushFileBuffers simply does nothing. :-)
from termiwin.
Ok, thank you
from termiwin.
Related Issues (10)
- hard defines for read/write/select/open/close also affects other files HOT 4
- How to Cross-compile it with mingw-w64 from Linux system HOT 3
- Missing defines CREAD, CLOCAL and B600 HOT 4
- Returned handle cannot be used with "isatty" HOT 6
- Control/Charset option handling is not working HOT 3
- Serial port name init seems wrong/strange HOT 1
- Any way to use with a Python packages?
- Function openSerial() changes the portname parameter
- Tons of Errors HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from termiwin.