OLD | NEW |
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 "crypto/dsa" | 8 "crypto/dsa" |
9 "crypto/ecdsa" | 9 "crypto/ecdsa" |
10 "crypto/rsa" | 10 "crypto/rsa" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 | 323 |
324 func appendU32(buf []byte, n uint32) []byte { | 324 func appendU32(buf []byte, n uint32) []byte { |
325 return append(buf, byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) | 325 return append(buf, byte(n>>24), byte(n>>16), byte(n>>8), byte(n)) |
326 } | 326 } |
327 | 327 |
328 func appendInt(buf []byte, n int) []byte { | 328 func appendInt(buf []byte, n int) []byte { |
329 return appendU32(buf, uint32(n)) | 329 return appendU32(buf, uint32(n)) |
330 } | 330 } |
331 | 331 |
| 332 func appendString(buf []byte, s string) []byte { |
| 333 buf = appendU32(buf, uint32(len(s))) |
| 334 buf = append(buf, s...) |
| 335 return buf |
| 336 } |
| 337 |
| 338 func appendBool(buf []byte, b bool) []byte { |
| 339 if b { |
| 340 buf = append(buf, 1) |
| 341 } else { |
| 342 buf = append(buf, 0) |
| 343 } |
| 344 return buf |
| 345 } |
| 346 |
332 // newCond is a helper to hide the fact that there is no usable zero | 347 // newCond is a helper to hide the fact that there is no usable zero |
333 // value for sync.Cond. | 348 // value for sync.Cond. |
334 func newCond() *sync.Cond { return sync.NewCond(new(sync.Mutex)) } | 349 func newCond() *sync.Cond { return sync.NewCond(new(sync.Mutex)) } |
335 | 350 |
336 // window represents the buffer available to clients | 351 // window represents the buffer available to clients |
337 // wishing to write to a channel. | 352 // wishing to write to a channel. |
338 type window struct { | 353 type window struct { |
339 *sync.Cond | 354 *sync.Cond |
340 win uint32 // RFC 4254 5.2 says the window size can grow to 2^32-1 | 355 win uint32 // RFC 4254 5.2 says the window size can grow to 2^32-1 |
341 } | 356 } |
(...skipping 27 matching lines...) Expand all Loading... |
369 for w.win == 0 { | 384 for w.win == 0 { |
370 w.Wait() | 385 w.Wait() |
371 } | 386 } |
372 if w.win < win { | 387 if w.win < win { |
373 win = w.win | 388 win = w.win |
374 } | 389 } |
375 w.win -= win | 390 w.win -= win |
376 w.L.Unlock() | 391 w.L.Unlock() |
377 return win | 392 return win |
378 } | 393 } |
OLD | NEW |