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

Cannot use bufio.Scanner for conn #431

Open
sago35 opened this issue Jul 19, 2022 · 0 comments
Open

Cannot use bufio.Scanner for conn #431

sago35 opened this issue Jul 19, 2022 · 0 comments

Comments

@sago35
Copy link
Member

sago35 commented Jul 19, 2022

For now, conn.Read may return a length of 0, so bufio.NewScanner() cannot be used.
Similarly, fmt.Fscanf() cannot be used.

Similar to the following
tinygo-org/tinygo#2739

What works now is the following code.

	buf := [1024]byte{}
	for {
		n := int(0)
		for {
			n, err = conn.Read(buf[:])
			if err != nil {
				failMessage(err.Error())
			}
			if n > 0 {
				break
			}
			time.Sleep(5 * time.Millisecond)
		}
		fmt.Printf("recv: %q\r\n", string(buf[:n]))
	}

I would like the following to work also
Because I think that is Go-way code.
Of course, we can check for errors by using conn.Read.

	scanner := bufio.NewScanner(conn)
	for scanner.Scan() {
		fmt.Printf("recv: %q\r\n", scanner.Text())
	}
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