rename some things
This commit is contained in:
parent
22f0ea52e2
commit
34ee3924d3
|
@ -103,7 +103,7 @@ func genAuthCode() (string, error) {
|
|||
return base64.URLEncoding.EncodeToString(b), nil
|
||||
}
|
||||
|
||||
func handleRaw(conn bufferedConn) {
|
||||
func handleRaw(bufConn bufferedConn) {
|
||||
// TODO
|
||||
// What happens if this is being read from range
|
||||
// when it's being added here (data race)?
|
||||
|
@ -118,7 +118,7 @@ func handleRaw(conn bufferedConn) {
|
|||
buffer := make([]byte, 1024)
|
||||
for {
|
||||
fmt.Fprintf(os.Stdout, "[raw] Waiting for message...\n");
|
||||
count, err := conn.Read(buffer)
|
||||
count, err := bufConn.Read(buffer)
|
||||
if nil != err {
|
||||
if io.EOF != err {
|
||||
fmt.Fprintf(os.Stderr, "Non-EOF socket error: %s\n", err)
|
||||
|
@ -126,7 +126,7 @@ func handleRaw(conn bufferedConn) {
|
|||
fmt.Fprintf(os.Stdout, "Ending socket\n")
|
||||
|
||||
// TODO put this in a channel to prevent data races
|
||||
delTcpChat <- conn
|
||||
delTcpChat <- bufConn
|
||||
break
|
||||
}
|
||||
buf := buffer[:count]
|
||||
|
@ -145,7 +145,7 @@ func handleRaw(conn bufferedConn) {
|
|||
email = strings.TrimSpace(string(buf[:count]))
|
||||
emailParts := strings.Split(email, "@")
|
||||
if 2 != len(emailParts) {
|
||||
fmt.Fprintf(conn, "Email: ")
|
||||
fmt.Fprintf(bufConn, "Email: ")
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(os.Stdout, "email: '%v'\n", []byte(email))
|
||||
|
@ -154,17 +154,17 @@ func handleRaw(conn bufferedConn) {
|
|||
// TODO handle better
|
||||
panic(err)
|
||||
}
|
||||
fmt.Fprintf(conn, "Auth Code: ")
|
||||
fmt.Fprintf(bufConn, "Auth Code: ")
|
||||
continue
|
||||
}
|
||||
|
||||
if code != strings.TrimSpace(string(buf[:count])) {
|
||||
fmt.Fprintf(conn, "Incorrect Code\nAuth Code: ")
|
||||
fmt.Fprintf(bufConn, "Incorrect Code\nAuth Code: ")
|
||||
} else {
|
||||
authn = true
|
||||
fmt.Fprintf(conn, "Welcome to #general! (TODO `/help' for list of commands)\n")
|
||||
fmt.Fprintf(bufConn, "Welcome to #general! (TODO `/help' for list of commands)\n")
|
||||
// TODO number of users
|
||||
//fmt.Fprintf(conn, "Welcome to #general! TODO `/list' to see channels. `/join chname' to switch.\n")
|
||||
//fmt.Fprintf(bufConn, "Welcome to #general! TODO `/list' to see channels. `/join chname' to switch.\n")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func handleRaw(conn bufferedConn) {
|
|||
//myChans["general"] <- myMsg{
|
||||
myMsgs <- myMsg{
|
||||
receivedAt: time.Now(),
|
||||
sender: conn,
|
||||
sender: bufConn,
|
||||
bytes: buf[0:count],
|
||||
channel: "general",
|
||||
}
|
||||
|
@ -387,11 +387,11 @@ func main() {
|
|||
case bufConn := <- newTcpChat:
|
||||
myRawConns[bufConn] = true
|
||||
go handleRaw(bufConn)
|
||||
case bufConn := <- newHttpChat:
|
||||
go handleSorted(bufConn)
|
||||
case bufConn := <- delHttpChat:
|
||||
case bufConn := <- delTcpChat:
|
||||
bufConn.Close();
|
||||
delete(myRawConns, bufConn)
|
||||
case bufConn := <- newHttpChat:
|
||||
go handleSorted(bufConn)
|
||||
//case msg := <- myChans["general"]:
|
||||
//delete(myChans["general"], bufConn)
|
||||
case msg := <- myMsgs:
|
||||
|
|
Loading…
Reference in New Issue