FAQ
Hi all,

I have a goroutine that calls Read() on a socket and blocks until data is
available. Is there a way for a different goroutine to trigger this Read()
call to return? The only techniques I can think of is either polling a flag
via the timeout mechanisms or by closing the socket -- neither option being
very attractive.

Thanks!

David

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Péter Szilágyi at May 12, 2013 at 6:15 pm
    Hi,

       I'd say no. Them main issue is that when you block on a socket, the
    thread is essentially in the hands of the OS, which you cannot force to
    give back to you.

       Nonetheless, why would you want to break a blocking read? Maybe if you'd
    share the use case we could come up with a better solution :)

    Cheers,
       Peter

    On Sun, May 12, 2013 at 3:57 PM, wrote:

    Hi all,

    I have a goroutine that calls Read() on a socket and blocks until data is
    available. Is there a way for a different goroutine to trigger this Read()
    call to return? The only techniques I can think of is either polling a flag
    via the timeout mechanisms or by closing the socket -- neither option being
    very attractive.

    Thanks!

    David

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Davekeck at May 12, 2013 at 9:24 pm

    Nonetheless, why would you want to break a blocking read? Maybe if you'd
    share the use case we could come up with a better solution :)
    I'm just attempting to implement a clean tear-down of a multiplexer, and
    preferred that it doesn't take ownership of the socket (hence the aversion
    to closing the socket.)

    Thanks Peter,

    David

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dave Cheney at May 13, 2013 at 5:01 am

    I'd say no. Them main issue is that when you block on a socket, the thread
    is essentially in the hands of the OS, which you cannot force to give back
    to you.
    This is not true in Go.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Taru Karttunen at May 13, 2013 at 4:58 am

    On 12.05 06:57, davekeck@gmail.com wrote:
    I have a goroutine that calls Read() on a socket and blocks until data is
    available. Is there a way for a different goroutine to trigger this Read()
    call to return? The only techniques I can think of is either polling a flag
    via the timeout mechanisms or by closing the socket -- neither option being
    very attractive.
    Both work. Typically I end up closing the sockets.

    An additional exercise:

    When Accept returns an error how do we distinguish it errors from the
    new socket (continue accepting) from errors on the actual accepting
    socket (break and return an error).

    - Taru Karttunen

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 12, '13 at 5:23p
activeMay 13, '13 at 5:01a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase