Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

fix closing of streams in example #221

Merged
merged 1 commit into from
Aug 5, 2021
Merged

fix closing of streams in example #221

merged 1 commit into from
Aug 5, 2021

Conversation

marten-seemann
Copy link
Collaborator

Fixes #220.

@@ -58,7 +58,7 @@ func run(raddr string, p string) error {
if _, err := str.Write([]byte(msg)); err != nil {
return err
}
if err := str.Close(); err != nil {
if err := str.CloseWrite(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to call close eventually (e.g., in a defer).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but streams are automatically closed when the connection is closed, so this is not necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, this is an example, and we should probably do things the clean way. Will add the defers.

@@ -75,5 +75,5 @@ func handleConn(conn tpt.CapableConn) error {
if _, err := str.Write([]byte(data)); err != nil {
return err
}
return str.Close()
return str.CloseWrite()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto (that or reset)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Actually, in this case, shouldn't it just be a close? I mean, we've already read everything we want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works as well. And it's easier.

@@ -75,5 +75,5 @@ func handleConn(conn tpt.CapableConn) error {
if _, err := str.Write([]byte(data)); err != nil {
return err
}
return str.Close()
return str.CloseWrite()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Actually, in this case, shouldn't it just be a close? I mean, we've already read everything we want.

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

Successfully merging this pull request may close these issues.

cmd examples do not work
2 participants