update usage
This commit is contained in:
parent
bfdabd1228
commit
db15b22e40
|
@ -92,7 +92,7 @@ var broadcastMsg chan chatMsg
|
||||||
// Telnet
|
// Telnet
|
||||||
var wantsServerHello chan bufferedConn
|
var wantsServerHello chan bufferedConn
|
||||||
var authTelnet chan telnetUser
|
var authTelnet chan telnetUser
|
||||||
var cleanTelnet chan telnetUser
|
var cleanTelnet chan telnetUser // intentionally blocking
|
||||||
|
|
||||||
// HTTP
|
// HTTP
|
||||||
var demuxHttpClient chan bufferedConn
|
var demuxHttpClient chan bufferedConn
|
||||||
|
@ -101,7 +101,7 @@ var valAuthReqs chan authReq
|
||||||
var delAuthReqs chan authReq
|
var delAuthReqs chan authReq
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprintf(os.Stderr, "\nusage: go run chatserver.go\n")
|
fmt.Fprintf(os.Stderr, "\nusage: go run chatserver*.go\n")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ func main() {
|
||||||
virginConns = make(chan net.Conn, 128)
|
virginConns = make(chan net.Conn, 128)
|
||||||
|
|
||||||
// TCP & Authentication
|
// TCP & Authentication
|
||||||
telnetConns := make(map[bufferedConn]telnetUser)
|
telnetConns := make(map[string]telnetUser)
|
||||||
wantsServerHello = make(chan bufferedConn, 128)
|
wantsServerHello = make(chan bufferedConn, 128)
|
||||||
authTelnet = make(chan telnetUser, 128)
|
authTelnet = make(chan telnetUser, 128)
|
||||||
|
|
||||||
|
@ -389,7 +389,12 @@ func main() {
|
||||||
case u := <-authTelnet:
|
case u := <-authTelnet:
|
||||||
// allow to receive messages
|
// allow to receive messages
|
||||||
// (and be counted among the users)
|
// (and be counted among the users)
|
||||||
telnetConns[u.bufConn] = u
|
_, ok := telnetConns[u.email]
|
||||||
|
if ok {
|
||||||
|
// this is a blocking channel, and that's important
|
||||||
|
cleanTelnet <- telnetConns[u.email]
|
||||||
|
}
|
||||||
|
telnetConns[u.email] = u
|
||||||
// is chan chan the right way to handle this?
|
// is chan chan the right way to handle this?
|
||||||
u.userCount <- len(telnetConns)
|
u.userCount <- len(telnetConns)
|
||||||
broadcastMsg <- chatMsg{
|
broadcastMsg <- chatMsg{
|
||||||
|
@ -422,7 +427,7 @@ func main() {
|
||||||
close(u.newMsg)
|
close(u.newMsg)
|
||||||
// we can safely ignore this error, if any
|
// we can safely ignore this error, if any
|
||||||
u.bufConn.Close()
|
u.bufConn.Close()
|
||||||
delete(telnetConns, u.bufConn)
|
delete(telnetConns, u.email)
|
||||||
case bufConn := <-gotClientHello:
|
case bufConn := <-gotClientHello:
|
||||||
go muxTcp(bufConn)
|
go muxTcp(bufConn)
|
||||||
case bufConn := <-demuxHttpClient:
|
case bufConn := <-demuxHttpClient:
|
||||||
|
|
Loading…
Reference in New Issue