FAQ
Is this thread safe?

func Proxy(r, t *net.TCPConn) {
    go io.Copy(r, t)
    go io.Copy(t, r)
end

--
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/d/optout.

Search Discussions

  • Jesse McNelis at Apr 29, 2014 at 12:11 am

    On Tue, Apr 29, 2014 at 9:26 AM, Kevin P wrote:
    Is this thread safe?

    func Proxy(r, t *net.TCPConn) {
    go io.Copy(r, t)
    go io.Copy(t, r)
    end
    That's safe to do, as long as you don't have other things
    reading/writing to the net.TCPConn.
    But you're ignoring the errors that would be returned from io.Copy,
    you shouldn't ignore those errors.

    --
    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/d/optout.
  • Kevin P at Apr 29, 2014 at 12:13 am
    I do call r.Close()/t.Close() from another goroutine to close the
    connection. Would that cause an issue?
    On Monday, April 28, 2014 8:11:05 PM UTC-4, Jesse McNelis wrote:

    On Tue, Apr 29, 2014 at 9:26 AM, Kevin P <dco...@gmail.com <javascript:>>
    wrote:
    Is this thread safe?

    func Proxy(r, t *net.TCPConn) {
    go io.Copy(r, t)
    go io.Copy(t, r)
    end
    That's safe to do, as long as you don't have other things
    reading/writing to the net.TCPConn.
    But you're ignoring the errors that would be returned from io.Copy,
    you shouldn't ignore those errors.
    --
    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/d/optout.
  • James Bardin at Apr 29, 2014 at 12:27 am
    No. Per the docs:
    "Multiple goroutines may invoke methods on a Conn simultaneously."

    On Monday, April 28, 2014 8:13:09 PM UTC-4, Kevin P wrote:

    I do call r.Close()/t.Close() from another goroutine to close the
    connection. Would that cause an issue?
    On Monday, April 28, 2014 8:11:05 PM UTC-4, Jesse McNelis wrote:
    On Tue, Apr 29, 2014 at 9:26 AM, Kevin P wrote:
    Is this thread safe?

    func Proxy(r, t *net.TCPConn) {
    go io.Copy(r, t)
    go io.Copy(t, r)
    end
    That's safe to do, as long as you don't have other things
    reading/writing to the net.TCPConn.
    But you're ignoring the errors that would be returned from io.Copy,
    you shouldn't ignore those errors.
    --
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 28, '14 at 11:26p
activeApr 29, '14 at 12:27a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase