Re: read till EOF from stdin

2020-12-11 Thread frame via Digitalmars-d-learn
On Friday, 11 December 2020 at 18:18:35 UTC, kdevel wrote: On Friday, 11 December 2020 at 16:49:18 UTC, Adam D. Ruppe wrote: libc-2.30.so The bug was fixed in 2.28 IIRC. so i guess i have the fixed libc. Can you confirm what version you have? Various. I tested the code on a machine

Re: read till EOF from stdin

2020-12-11 Thread kdevel via Digitalmars-d-learn
On Friday, 11 December 2020 at 16:49:18 UTC, Adam D. Ruppe wrote: libc-2.30.so The bug was fixed in 2.28 IIRC. so i guess i have the fixed libc. Can you confirm what version you have? Various. I tested the code on a machine running the yet EOL CENTOS-6 having glibc 2.12.

Re: read till EOF from stdin

2020-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 December 2020 at 16:37:42 UTC, kdevel wrote: expected: program ends found: program still reading works for me looks like i have libc-2.30.so so i guess i have the fixed libc. Can you confirm what version you have? I did `ls /lib/libc*` to pick that out but it might be

Re: read till EOF from stdin

2020-12-11 Thread kdevel via Digitalmars-d-learn
not POSIX compliant [2] https://unix.stackexchange.com/questions/517064/why-does-hexdump-try-to-read-through-eof [3] https://stackoverflow.com/questions/52674057/why-does-an-fread-loop-require-an-extra-ctrld-to-signal-eof-with-glibc

Re: read till EOF from stdin

2020-12-11 Thread frame via Digitalmars-d-learn
On Friday, 11 December 2020 at 12:34:19 UTC, kdevel wrote: My code cannot do that because the function byChunk has control over the file descriptor. What do you mean by control? It just has the file handle, why do you cannot call eof() on the file handle struct? You should not check

Re: read till EOF from stdin

2020-12-11 Thread kdevel via Digitalmars-d-learn
ur here if you use a buffer of length 4. I don't know what you want to achieve here. Read till EOF. If you want to stop reading from stdin, you should check for eof() instead. My code cannot do that because the function byChunk has control over the file descriptor. The OS reports EOF

Re: read till EOF from stdin

2020-12-11 Thread frame via Digitalmars-d-learn
t you want to achieve here. If you want to stop reading from stdin, you should check for eof() instead. You should not check yourself for the character. eof() can be lock in by multiple ways and it is the only correct way to handle all of them.

read till EOF from stdin

2020-12-10 Thread kdevel via Digitalmars-d-learn
Currently as a workaround I read all the chars from stdin with import std.file; auto s = cast (string) read("/dev/fd/0"); after I found that you can't read from stdin. This is of course non-portable Linux only code. In perl I frequently use the idiom $s = join ('', <>); that

Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/16/2017 05:21 PM, Unazed Spectaculum wrote: > 1) Starting program > unazed@unazed  /home/d/storage-server  dmd -debug -run app.d Although I don't normally use the -run switch, as expected, it works with -run as well. (More below.) > Listening: 0.0.0.0:6969 > > 2) telnet to the server

Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-16 Thread Unazed Spectaculum via Digitalmars-d-learn
On Thursday, 14 December 2017 at 20:27:36 UTC, Ali Çehreli wrote: On 12/14/2017 11:55 AM, Unazed Spectaculum wrote: This is the only function which has a call to `receiveAll` I marked my changes with [Ali]: import std.stdio; import std.socket; import std.conv; import std.json; ubyte[]

Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-14 Thread Ali Çehreli via Digitalmars-d-learn
On 12/14/2017 11:55 AM, Unazed Spectaculum wrote: This is the only function which has a call to `receiveAll` I marked my changes with [Ali]: import std.stdio; import std.socket; import std.conv; import std.json; ubyte[] receiveBytes(T)(T socket, size_t receiveCount) { ubyte[] buffer =

Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-14 Thread Unazed Spectaculum via Digitalmars-d-learn
On Thursday, 14 December 2017 at 00:09:39 UTC, Ali Çehreli wrote: On 12/13/2017 11:39 AM, Unazed Spectaculum wrote: > ubyte[] receiveBytes(T)(T socket, size_t receiveCount) > { > ubyte[] buffer = new ubyte[receiveCount]; > size_t count = socket.receive(buffer); Don't trust code you

Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-13 Thread Ali Çehreli via Digitalmars-d-learn
On 12/13/2017 11:39 AM, Unazed Spectaculum wrote: > ubyte[] receiveBytes(T)(T socket, size_t receiveCount) > { > ubyte[] buffer = new ubyte[receiveCount]; > size_t count = socket.receive(buffer); Don't trust code you find on newsgroups. :o) You have to check the returned value first.

`Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-13 Thread Unazed Spectaculum via Digitalmars-d-learn
ubyte[] receiveBytes(T)(T socket, size_t receiveCount) { ubyte[] buffer = new ubyte[receiveCount]; size_t count = socket.receive(buffer); return buffer[0 .. count]; } string receiveAll(T)(T socket, size_t segmentSize = 1024) { ubyte[][] data; size_t count

Re: eof

2013-06-26 Thread lx
On Wednesday, 26 June 2013 at 04:46:32 UTC, Ali Çehreli wrote: On 06/25/2013 09:26 PM, lx wrote: Ctrl+z seems close the stream.So,if I want to input another batch of data,it became impossilbe.So,how to reopen the stream again to allow me to input another batch of data? Making a copy of

Re: eof

2013-06-26 Thread lx
On Wednesday, 26 June 2013 at 13:45:41 UTC, lx wrote: On Wednesday, 26 June 2013 at 04:46:32 UTC, Ali Çehreli wrote: On 06/25/2013 09:26 PM, lx wrote: Ctrl+z seems close the stream.So,if I want to input another batch of data,it became impossilbe.So,how to reopen the stream again to allow me

Re: eof

2013-06-25 Thread lx
On Monday, 24 June 2013 at 21:13:31 UTC, bearophile wrote: I am very confused that ctrl+z didn't teminate the input of console,it result in a dead loop. I think this is a library bug, I noticed it some times, but I didn't file it. Maybe it's worth filing in Bugzilla. I have added this bug

Re: eof

2013-06-25 Thread Ali Çehreli
On 06/25/2013 09:26 PM, lx wrote: Ctrl+z seems close the stream.So,if I want to input another batch of data,it became impossilbe.So,how to reopen the stream again to allow me to input another batch of data? Making a copy of stdin works on Linux (where the stream is terminated by Ctrl-D in

Re: eof

2013-06-25 Thread Ali Çehreli
On 06/25/2013 09:26 PM, lx wrote: I input ctrl+c,the code will terminate abnormally.Why this happened? Ctrl-C appears as SIGINT under POSIX systems. You need to register a handler for that signal: import std.stdio; import std.string; import core.sys.posix.signal; bool isDone = false;

eof

2013-06-24 Thread lx
Hi,everyone, I am learning D.I installed a plugin-visusl D to visual studio 2008.I am very confused that ctrl+z didn't teminate the input of console,it result in a dead loop.When reading from a txt file,a extra line will be read and usually it result in a wrong result.Is there anyone who has

Re: eof

2013-06-24 Thread bearophile
lx: I am very confused that ctrl+z didn't teminate the input of console,it result in a dead loop. I think this is a library bug, I noticed it some times, but I didn't file it. Maybe it's worth filing in Bugzilla. When reading from a txt file,a extra line will be read and usually it

Re: eof

2013-06-24 Thread bearophile
I am very confused that ctrl+z didn't teminate the input of console,it result in a dead loop. I think this is a library bug, I noticed it some times, but I didn't file it. Maybe it's worth filing in Bugzilla. I have added this bug report, is this the issue you are seeing/having?

Re: eof

2013-06-24 Thread monarch_dodra
/eof/error'd stdin, it will just loop... This FAQ link explains it pretty well for C++, which is pretty much the same thing as in D: http://www.parashift.com/c++-faq/stream-input-failure.html (the next few points are relevant too). We could argue the design isn't optimal, yes, but it's

Re: eof

2013-06-24 Thread bearophile
monarch_dodra: I don't think this is a bug I see. Then lx will have to explain the problem better. (I replied on the bug report): I have given an answer, comparing to Python. I think the current Phobos behavour is bad. Bye, bearophile

problems countered after while(read()){} terminated with ^D or EOF

2012-03-22 Thread Tyro[17]
I'm using the following to read arrays from the command line (or redirected file) but am having some issues that I have not been able to solve on my own. Would appreciate if a little guidance. void f(T)(ref T a)if(isArray!T) { a.length = 100; int i; while(readf( %s, a[i++])) // #1

Re: problems countered after while(read()){} terminated with ^D or EOF

2012-03-22 Thread Andrej Mitrovic
On 3/22/12, Tyro[17] nos...@home.com wrote: issue #2 how do i read a string[] such that whitespace (all or one of my choosing) delineate the string boundary? Jesse Phillips has a cmdln.interact library that I think would work by using: string[] result = userInput!(string[])(Enter

Re: eof of socketstream?

2012-01-25 Thread useo6
Nobody knows how to solve that problem? I tried some other solutions where I ran into the same problem: /* Works as long as bytes available and the length of my buffer is 1 - doesn't work if the file-size (which is unknown) has a size which is a multiple of the buffer size... for ex. if the

eof of socketstream?

2012-01-22 Thread useo6
Hey guys, is there any way to find the end a socketstream? When I use: MemoryStream ms = new MemoryStream(); while (s.socket().isAlive()) ms.write(s.getc()); I run into an endless loop. The socket doesn't send the size of the data, so I need to know when I received all the data. How can I