FAQ

Search Discussions

  • Dave Cheney at Nov 10, 2014 at 12:53 am
  • Mikhail Vitsen at Nov 10, 2014 at 12:30 pm
  • Konstantin Khomoutov at Nov 10, 2014 at 12:48 pm
  • Mikhail Vitsen at Nov 10, 2014 at 1:28 pm
  • Konstantin Khomoutov at Nov 10, 2014 at 3:08 pm
  • Mikhail Vitsen at Nov 10, 2014 at 10:06 pm
  • Djadala at Nov 11, 2014 at 12:28 am
  • Konstantin Khomoutov at Nov 13, 2014 at 1:39 pm

    On Mon, 10 Nov 2014 14:06:02 -0800 (PST) Mikhail Vitsen wrote:

    Thanks a lot - your recomenrations are very useful! I've remade some
    thing in my server to make it work as you said.
    Also - i fixed the problem! http://play.golang.org/p/rlR1gmQbIk

    I replaced the strings

    server := &http.Server{Addr: ":8080"}
    go server.ListenAndServe()

    with

    server := &http.Server{}
    listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IPv4(127,
    0, 0, 1), Port: 8080})


    if err != nil {
    log.Fatal("error creating listener")
    }

    go server.Serve(listener)


    and it works fine! But i can't understand what was wrong in the first
    variant! I used code from sources of http (func (srv *Server)
    ListenAndServe(), but without tcpKeepAliveListener structure) - it is
    nearly the same!
    I'm iclined to think that merely replacing for {} with select {} -- as
    djadala showed you -- would fix your case even with the original

       go server.ListenAndServe()

    Please forget about bloody busy loops--the only (somewhat) valid case
    for them is code handling the hardware (i.e. in-kernel drivers) because
    sometimes there's just no way to wait on some signal from that hardware
    for the completion of the command issued to it, so you just have to
    wait (poll) until the state changes. Go is for higher-level concurrent
    programming so all the code which has to wait on some other code to
    complete has to use one or another synchronization mechanism provided
    by Go. Busy loops is not one of them.

    --
    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
postedNov 10, '14 at 12:33a
activeNov 13, '14 at 1:39p
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase