Created
September 12, 2014 21:16
-
-
Save rafrombrc/a8bdf4fc3f47e77fde9e to your computer and use it in GitHub Desktop.
listen testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net" | |
"time" | |
) | |
func accept(l net.Listener, sigBack chan struct{}) { | |
conn, err := l.Accept() | |
log.Println("past accept: ", conn) | |
if err != nil { | |
log.Println("accept error: ", err) | |
} | |
close(sigBack) | |
} | |
func main() { | |
l, err := net.Listen("tcp", "127.0.0.1:44444") | |
if err != nil { | |
log.Fatalln("listen error: ", err) | |
} | |
sigBack := make(chan struct{}) | |
go accept(l, sigBack) | |
time.Sleep(2 * time.Second) | |
l.Close() | |
<-sigBack | |
log.Println("clean exit") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment