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/rlR1gmQbIkI 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.