March 06, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | 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:
>> 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.
>
> You might want to go lower level:
>
> http://stackoverflow.com/questions/17590816/kernel-based-linux-data-relay-between-two-tcp-sockets
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.
|
March 07, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | 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 |
March 07, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt Attachments: | On Fri, 06 Mar 2015 19:33:54 +0000, zhmt wrote:
> 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.
lol.
|
March 07, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | 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-24416
If 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();
|
March 08, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Saturday, 7 March 2015 at 09:39:42 UTC, Kagamin wrote:
> 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-24416
>
> If 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();
Yes, this a good idea, if the author of vibe.d do this, will be better, it is used frequently in many scenes.
|
March 08, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | 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 |
March 09, 2015 Re: how to read some in vibe.d tcpconnection? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | On Sunday, 8 March 2015 at 13:56:37 UTC, Kagamin wrote:
> 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
This is a good idea. I take it.
Thank u very much, you are so kind.
|
Copyright © 1999-2021 by the D Language Foundation