Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2497)

Delta Between Two Patch Sets: ssh/example_test.go

Issue 14225043: code review 14225043: go.crypto/ssh: reimplement SSH connection protocol modu... (Closed)
Left Patch Set: diff -r 2cd6b3b93cdb https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Right Patch Set: diff -r cd1eea1eb828 https://code.google.com/p/go.crypto Created 10 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « ssh/client.go ('k') | ssh/messages.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package ssh 5 package ssh
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io/ioutil" 10 "io/ioutil"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 // A ServerConn multiplexes several channels, which must 52 // A ServerConn multiplexes several channels, which must
53 // themselves be Accepted. 53 // themselves be Accepted.
54 for { 54 for {
55 // Accept reads from the connection, demultiplexes packets 55 // Accept reads from the connection, demultiplexes packets
56 // to their corresponding channels and returns when a new 56 // to their corresponding channels and returns when a new
57 // channel request is seen. Some goroutine must always be 57 // channel request is seen. Some goroutine must always be
58 // calling Accept; otherwise no messages will be forwarded 58 // calling Accept; otherwise no messages will be forwarded
59 // to the channels. 59 // to the channels.
60 » » channel, err := sConn.Accept() 60 » » ch, err := sConn.Accept()
61 if err != nil { 61 if err != nil {
62 panic("error from Accept") 62 panic("error from Accept")
63 } 63 }
64 64
65 // Channels have a type, depending on the application level 65 // Channels have a type, depending on the application level
66 // protocol intended. In the case of a shell, the type is 66 // protocol intended. In the case of a shell, the type is
67 // "session" and ServerShell may be used to present a simple 67 // "session" and ServerShell may be used to present a simple
68 // terminal interface. 68 // terminal interface.
69 » » if channel.ChannelType() != "session" { 69 » » if ch.ChannelType() != "session" {
70 » » » channel.Reject(UnknownChannelType, "unknown channel type ") 70 » » » ch.Reject(UnknownChannelType, "unknown channel type")
71 continue 71 continue
72 } 72 }
73 » » channel.Accept() 73 » » if err := ch.Accept(); err != nil {
74 » » » panic("could not accept")
75 » » }
74 76
75 » » term := terminal.NewTerminal(channel, "> ") 77 » » term := terminal.NewTerminal(ch, "> ")
76 serverTerm := &ServerTerminal{ 78 serverTerm := &ServerTerminal{
77 Term: term, 79 Term: term,
78 » » » Channel: channel, 80 » » » Channel: ch,
79 } 81 }
80 go func() { 82 go func() {
81 » » » defer channel.Close() 83 » » » defer ch.Close()
82 for { 84 for {
83 line, err := serverTerm.ReadLine() 85 line, err := serverTerm.ReadLine()
84 if err != nil { 86 if err != nil {
85 break 87 break
86 } 88 }
87 fmt.Println(line) 89 fmt.Println(line)
88 } 90 }
89 }() 91 }()
90 } 92 }
91 } 93 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 184 }
183 // Request pseudo terminal 185 // Request pseudo terminal
184 if err := session.RequestPty("xterm", 80, 40, modes); err != nil { 186 if err := session.RequestPty("xterm", 80, 40, modes); err != nil {
185 log.Fatalf("request for pseudo terminal failed: %s", err) 187 log.Fatalf("request for pseudo terminal failed: %s", err)
186 } 188 }
187 // Start remote shell 189 // Start remote shell
188 if err := session.Shell(); err != nil { 190 if err := session.Shell(); err != nil {
189 log.Fatalf("failed to start shell: %s", err) 191 log.Fatalf("failed to start shell: %s", err)
190 } 192 }
191 } 193 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b