In principle the right pattern for this might be two tasks with the same
socket? I don't know if rust's socket abstraction would like that or not.
paul santa clara <[email protected]> wrote:
>Hey Jack,
>Thanks for your response! I actually have a rust task managing the tcp
>socket. Most of the time, this task is content to sit around and read
>from
>the socket but on occassion, it will be prompted by another task to
>also
>write to said socket. The problem is that while the task is blocked
>reading a socket, it will not be able to inspect its port to see if the
>other task would like it write something to the socket.
> I'm viewing the problem as an actor style pattern wherein the socket
>task is instructed on behalf of other tasks to do things with the
>socket.
>Perhaps there is a cleaner way of modeling it? I suppose I could use
>two
>separate sockets - one for reading and one for writing- but this seems
>inefficient.
>
>Thanks,
>-Paul SC
>
>On Wed, Mar 20, 2013 at 12:28 AM, Jack Moffitt <[email protected]>
>wrote:
>
>> > What I am really shooting for a is method to query a socket to
>> > see if there is any data available for reading and if not, go do
>> something
>> > else for awhile.
>>
>> Rust has tasks so you can just spawn a task to handle the socket
>reads
>> and do other stuff while it's blocking in other tasks. The
>> non-blocking stuff happens for you behind the scenes by the task
>> scheduler. In Erlang, you normally just make all your blocking calls
>> in a process (the Erlang version of Rust tasks) and don't worry about
>> it. Erlang's gen_tcp:recv does have a mode where it will return
>> immediately with any available data, but I've never used it, and I
>> don't believe its use is common.
>>
>> jack.
>>
>
>
>!DSPAM:514b396d299105315134984!
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Rust-dev mailing list
>[email protected]
>https://mail.mozilla.org/listinfo/rust-dev
>
>
>!DSPAM:514b396d299105315134984!
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev