Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deadline causes instant disconnection #1

Open
matjam opened this issue Feb 19, 2021 · 0 comments
Open

deadline causes instant disconnection #1

matjam opened this issue Feb 19, 2021 · 0 comments

Comments

@matjam
Copy link

matjam commented Feb 19, 2021

Setting the deadline here:

c.SetReadDeadline(time.Now().Add(time.Microsecond))

Seems to cause issues if you try to do something like this:

func telnetHandler(c *telnet.Connection) {
	log.Printf("Connection received: %s", c.RemoteAddr())
	c.Write([]byte("Connected!\r\n"))

	var b []byte = make([]byte, 1)
	for {
		log.Println("reading a byte")
		_, err := c.Read(b)
		if err != nil {
			log.Error("error reading from telnet client: ", err)
			log.Error("closing socket")
			return
		}
		log.Println("character received: ", string(b))
	}
}

For my application, I need to read 1 character at a time and the deadline code seems to time out the Read(). Removing the deadline resolves the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant