digitalmars.D.learn - how to read some in vibe.d tcpconnection?
- zhmt (7/7) Mar 06 2015 TCPConnecion has a read method, which will block untill the buf
- zhmt (8/8) Mar 06 2015 I am forwarding data from client to another server, if the client
- Rikki Cattermole (3/10) Mar 06 2015 Take a look at empty and leastSize.
- zhmt (8/10) Mar 06 2015 @Rikki Cattermole
- Stefan Koch (3/15) Mar 06 2015 There should be a function called DataAvilable.
- zhmt (4/6) Mar 06 2015 Thanks you!
- Stefan Koch (3/9) Mar 06 2015 you first check dataAvilableForRead
- Kagamin (3/3) Mar 06 2015 I'd say, peek is the right method, it returns what's already in
- zhmt (2/5) Mar 06 2015 The api of vibe.d is too simple to use in real work.
- "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= (3/8) Mar 06 2015 You might want to go lower level:
- zhmt (6/15) Mar 06 2015 no, I just want receive data and forward them in time, but not to
- ketmar (2/8) Mar 07 2015 lol.=
TCPConnecion has a read method, which will block untill the buf is fully filled. This is not what I want. I want a readSome method, which will return if some data comes from remote end, and notify the length of data to me. so I can process data in time. what should I do ?
Mar 06 2015
I am forwarding data from client to another server, if the client send data to server,I want to forward that to another server in time. So, if the server recieves nothing it will wait, if it receive some data , forward them to another server immediately. I dont think the TCPConnecion.read method works in this scene. I have read the document of TCPConnection, found nothing helpful. Will somebody help me?
Mar 06 2015
On 6/03/2015 10:30 p.m., zhmt wrote:I am forwarding data from client to another server, if the client send data to server,I want to forward that to another server in time. So, if the server recieves nothing it will wait, if it receive some data , forward them to another server immediately. I dont think the TCPConnecion.read method works in this scene. I have read the document of TCPConnection, found nothing helpful. Will somebody help me?Take a look at empty and leastSize. https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/stream.d#L33
Mar 06 2015
Take a look at empty and leastSize. https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/stream.d#L33Rikki Cattermole Thanks for your reply, but it is not what I want, and I cant implement my goal with them. in boost::asio, It has a method like this : basic_stream_socket::read_some (1 of 2 overloads) This function is used to read data from the stream socket. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.
Mar 06 2015
On Friday, 6 March 2015 at 10:10:35 UTC, zhmt wrote:There should be a function called DataAvilable. Simply read the data if this function returns trueTake a look at empty and leastSize. https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/stream.d#L33Rikki Cattermole Thanks for your reply, but it is not what I want, and I cant implement my goal with them. in boost::asio, It has a method like this : basic_stream_socket::read_some (1 of 2 overloads) This function is used to read data from the stream socket. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.
Mar 06 2015
There should be a function called DataAvilable. Simply read the data if this function returns trueThanks you! But the DataAvilable just return a bool value, so I dont know the available data size, I cant call the read method simply. Is there more info to solve this problem?
Mar 06 2015
On Friday, 6 March 2015 at 10:16:32 UTC, zhmt wrote:you first check dataAvilableForRead and then leastSizeThere should be a function called DataAvilable. Simply read the data if this function returns trueThanks you! But the DataAvilable just return a bool value, so I dont know the available data size, I cant call the read method simply. Is there more info to solve this problem?
Mar 06 2015
I'd say, peek is the right method, it returns what's already in the buffer (but doesn't read), while leastSize returns full logical size of the stream.
Mar 06 2015
On Friday, 6 March 2015 at 18:40:28 UTC, Kagamin wrote:I'd say, peek is the right method, it returns what's already in the buffer (but doesn't read), while leastSize returns full logical size of the stream.The api of vibe.d is too simple to use in real work.
Mar 06 2015
On Friday, 6 March 2015 at 19:33:56 UTC, zhmt wrote:On Friday, 6 March 2015 at 18:40:28 UTC, Kagamin wrote:You might want to go lower level: http://stackoverflow.com/questions/17590816/kernel-based-linux-data-relay-between-two-tcp-socketsI'd say, peek is the right method, it returns what's already in the buffer (but doesn't read), while leastSize returns full logical size of the stream.The api of vibe.d is too simple to use in real work.
Mar 06 2015
On Friday, 6 March 2015 at 20:03:52 UTC, Ola Fosheim Grøstad wrote:On Friday, 6 March 2015 at 19:33:56 UTC, zhmt wrote:no, I just want receive data and forward them in time, but not to wait unitil the buffer is full. That means if there is data in buffer, the readSome method should return , and let me forward the data.On Friday, 6 March 2015 at 18:40:28 UTC, Kagamin wrote:You might want to go lower level: http://stackoverflow.com/questions/17590816/kernel-based-linux-data-relay-between-two-tcp-socketsI'd say, peek is the right method, it returns what's already in the buffer (but doesn't read), while leastSize returns full logical size of the stream.The api of vibe.d is too simple to use in real work.
Mar 06 2015
Hi,I got the right answer in vibe.d forum,here is the link: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/24403/#post-24416
Mar 06 2015
On Saturday, 7 March 2015 at 02:23:10 UTC, zhmt wrote:Hi,I got the right answer in vibe.d forum,here is the link: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/24403/#post-24416If that's correct, you can write an extension method for InputStream in terms of asio: ubyte[] readSome(InputStream input, ubyte[] buffer) { if(input.empty)return null; const len = min(input.leastSize, buffer.length); ubyte[] chunk = buffer[0 .. len]; input.read(chunk); // guaranteed to not block now return chunk; } And use: InputStream input=...; ubyte[256] buffer; auto chunk = input.readSome(buffer); if(chunk==null)return done();
Mar 07 2015
On Saturday, 7 March 2015 at 09:39:42 UTC, Kagamin wrote:On Saturday, 7 March 2015 at 02:23:10 UTC, zhmt wrote:Yes, this a good idea, if the author of vibe.d do this, will be better, it is used frequently in many scenes.Hi,I got the right answer in vibe.d forum,here is the link: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/24403/#post-24416If that's correct, you can write an extension method for InputStream in terms of asio: ubyte[] readSome(InputStream input, ubyte[] buffer) { if(input.empty)return null; const len = min(input.leastSize, buffer.length); ubyte[] chunk = buffer[0 .. len]; input.read(chunk); // guaranteed to not block now return chunk; } And use: InputStream input=...; ubyte[256] buffer; auto chunk = input.readSome(buffer); if(chunk==null)return done();
Mar 07 2015
On Sunday, 8 March 2015 at 03:09:00 UTC, zhmt wrote:Yes, this a good idea, if the author of vibe.d do this, will be better, it is used frequently in many scenes.You can do it too, unlike in C++, in D you can write extension methods to any type, as long as they are visible, you can call them on the first argument, it's called UFCS: http://dlang.org/function.html#pseudo-member
Mar 08 2015
On Sunday, 8 March 2015 at 13:56:37 UTC, Kagamin wrote:On Sunday, 8 March 2015 at 03:09:00 UTC, zhmt wrote:This is a good idea. I take it. Thank u very much, you are so kind.Yes, this a good idea, if the author of vibe.d do this, will be better, it is used frequently in many scenes.You can do it too, unlike in C++, in D you can write extension methods to any type, as long as they are visible, you can call them on the first argument, it's called UFCS: http://dlang.org/function.html#pseudo-member
Mar 09 2015
On Fri, 06 Mar 2015 19:33:54 +0000, zhmt wrote:On Friday, 6 March 2015 at 18:40:28 UTC, Kagamin wrote:lol.=I'd say, peek is the right method, it returns what's already in the buffer (but doesn't read), while leastSize returns full logical size of the stream.=20 The api of vibe.d is too simple to use in real work.
Mar 07 2015