rename some things

This commit is contained in:
AJ ONeal 2018-07-30 00:17:35 -06:00
parent 22f0ea52e2
commit 34ee3924d3
1 changed files with 12 additions and 12 deletions

View File

@ -103,7 +103,7 @@ func genAuthCode() (string, error) {
return base64.URLEncoding.EncodeToString(b), nil return base64.URLEncoding.EncodeToString(b), nil
} }
func handleRaw(conn bufferedConn) { func handleRaw(bufConn bufferedConn) {
// TODO // TODO
// What happens if this is being read from range // What happens if this is being read from range
// when it's being added here (data race)? // when it's being added here (data race)?
@ -118,7 +118,7 @@ func handleRaw(conn bufferedConn) {
buffer := make([]byte, 1024) buffer := make([]byte, 1024)
for { for {
fmt.Fprintf(os.Stdout, "[raw] Waiting for message...\n"); fmt.Fprintf(os.Stdout, "[raw] Waiting for message...\n");
count, err := conn.Read(buffer) count, err := bufConn.Read(buffer)
if nil != err { if nil != err {
if io.EOF != err { if io.EOF != err {
fmt.Fprintf(os.Stderr, "Non-EOF socket error: %s\n", 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") fmt.Fprintf(os.Stdout, "Ending socket\n")
// TODO put this in a channel to prevent data races // TODO put this in a channel to prevent data races
delTcpChat <- conn delTcpChat <- bufConn
break break
} }
buf := buffer[:count] buf := buffer[:count]
@ -145,7 +145,7 @@ func handleRaw(conn bufferedConn) {
email = strings.TrimSpace(string(buf[:count])) email = strings.TrimSpace(string(buf[:count]))
emailParts := strings.Split(email, "@") emailParts := strings.Split(email, "@")
if 2 != len(emailParts) { if 2 != len(emailParts) {
fmt.Fprintf(conn, "Email: ") fmt.Fprintf(bufConn, "Email: ")
continue continue
} }
fmt.Fprintf(os.Stdout, "email: '%v'\n", []byte(email)) fmt.Fprintf(os.Stdout, "email: '%v'\n", []byte(email))
@ -154,17 +154,17 @@ func handleRaw(conn bufferedConn) {
// TODO handle better // TODO handle better
panic(err) panic(err)
} }
fmt.Fprintf(conn, "Auth Code: ") fmt.Fprintf(bufConn, "Auth Code: ")
continue continue
} }
if code != strings.TrimSpace(string(buf[:count])) { if code != strings.TrimSpace(string(buf[:count])) {
fmt.Fprintf(conn, "Incorrect Code\nAuth Code: ") fmt.Fprintf(bufConn, "Incorrect Code\nAuth Code: ")
} else { } else {
authn = true 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 // 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 continue
} }
@ -173,7 +173,7 @@ func handleRaw(conn bufferedConn) {
//myChans["general"] <- myMsg{ //myChans["general"] <- myMsg{
myMsgs <- myMsg{ myMsgs <- myMsg{
receivedAt: time.Now(), receivedAt: time.Now(),
sender: conn, sender: bufConn,
bytes: buf[0:count], bytes: buf[0:count],
channel: "general", channel: "general",
} }
@ -387,11 +387,11 @@ func main() {
case bufConn := <- newTcpChat: case bufConn := <- newTcpChat:
myRawConns[bufConn] = true myRawConns[bufConn] = true
go handleRaw(bufConn) go handleRaw(bufConn)
case bufConn := <- newHttpChat: case bufConn := <- delTcpChat:
go handleSorted(bufConn)
case bufConn := <- delHttpChat:
bufConn.Close(); bufConn.Close();
delete(myRawConns, bufConn) delete(myRawConns, bufConn)
case bufConn := <- newHttpChat:
go handleSorted(bufConn)
//case msg := <- myChans["general"]: //case msg := <- myChans["general"]:
//delete(myChans["general"], bufConn) //delete(myChans["general"], bufConn)
case msg := <- myMsgs: case msg := <- myMsgs: