int main() { BPTR fd[2]; const char *strings[] = {"hello\n", "how are you\n", "see you later\n"}; BOOL end = FALSE; int nbytes; char readbuffer[1024]; int flag, i;
When I run it, the writing part is fine, but the reading part just returns an error without reading anything. If I remove the "SetBlockingMode" line, the reading is also fine, but then the program hangs on the next Read() instead of just returning 0 and letting the program finish. This is obviously exactly what I want to avoid...
I have tried many many things to change it: Inserting Delay(), opening with "PIPE:testpipe/NOBLOCK", opening with MODE_READWRITE etc... and nothing seems to change the fact, that the non-blocking functionality just doesn't work...
Please, I need a smart person to tell me, how to solve this!
What exactly are you trying to do ? IMHO reading and writing to the same pipe within the same execution thread has no sense at all (use ?) since at some point the write buffer will be full (and your application will Wait() forever for someone to read it). Here's a link to a thread on utilitybase with a working pipe example.
Edit: AFAIR, the writer must close the pipe for the reader to get an EOF, that's probably why your program hangs (in the version with blocking).
Thanks, but I already read though that file a gazillion times, and as far as I can see, from the description it gives, there is a BIG FAT BUG in queue-handler... or at least what I would call a "discrepancy" btw the documentation and the actual API; namely that the /NOBLOCK clause doesn't work at all when applied to a reading end of the pipe, and that IDOS->SetBlockingMode() also fails to fulfill it's purpose (on the writing end it might work, I don't know)... In both cases IDOS->Read(pipehandle, ...) will return only errors and no data, although the filehandle seems to be fine otherwise.
I would like if anyone could confirm this... Also, if it is really a bug, I would like to send a bug report, but I don't know where to send it.
EDIT: Usually in these kinds of situations, it turns out, that I'm just a big fat pinhead who has overlooked something totally obvious to the person of average intelligence. Hence my need for confirmation
Hmm... I replied to your msg yesterday, but the reply seems to have vanished. I'll retry:
Of course I'm not going to use a pipe for read/write in the same process. This is just a simplified test app to see, if the pipe itself will actually work or not.
The reason it blocks is because that's how it's supposed to do (at least that's how it works on Mac OS X 10.4 with the unix 'pipe()'). But it is ALSO supposed to react to setting a /NOBLOCK flag, that makes this behavior go away (which means, that the subsequent call to Read would return immediately with no data). The last thing is what I cannot get to work. From the documentation it is supposed to work, so I figure there's a bug somewhere (read my other post).
Hmm... What is it returning? True/false or smth else? I can't check right now, I'll look at it this weekend.
Still this doesn't explain why Open("PIPE:testpipe/NOBLOCK", MODE_OLDFILE) doesn't work (it returns a valid filehandle, but when reading from it, it returns only errors).
Yes it should! But this one returns an error even when it is NOT empty, that's the problem...
Again: Where do I go to file a bug report on an Amiga OS component?
EDIT: And also: Could somebody please just copy the code, compile and run it to confirm, that it is not just a local problem on my system? You don't need to know anything about, what the code does, all you need is to have the official OS 4.1 SDK installed, follow the compiling instructions I gave, run with 'apipe', and then if you would post the output you get to this thread. It should take about 2 minutes to do. Please??... Thanks!
Edited by alfkil on 2010/2/24 13:09:27 Edited by alfkil on 2010/2/24 13:09:59 Edited by alfkil on 2010/2/24 13:10:39 Edited by alfkil on 2010/2/24 13:11:33
alfkil wrote: Hmm... What is it returning? True/false or smth else? I can't check right now, I'll look at it this weekend.
Okay took five minutes to read the dos.library/SetBlockingMode() Autodoc so here are two excerpts that seems to be of interest here :
RESULT
old_mode -- This is either the old blocking mode in effect
before you selected the new mode, or 0 or -1 (see notes).
If it is 0, then the new mode could not be selected,
possibly because the handler does not support the
SetBlockingMode() function.
And
If a stream is operating in non-blocking mode and the requested Read()
or Write() action cannot be performed immediately, it will return
with result == -1 and IoErr() == ERROR_WOULD_BLOCK.
I can't test your code I'm not at home and furthermore my A1 has gone for a CPU Module repair :-/
There is also an important note
Not all file systems and handlers will support this functionality.
Always check the return code of this function and IoErr().
Then there is certainly a problem somewhere maybe in the code above, maybe in the system I don't know. Anyway blocking mode or not, reading 32 bytes out of a streraam containing 32 bytes should always work, shouldn't it ?