File: Session.html

package info (click to toggle)
libnet-ssh-ruby 1.0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,180 kB
  • ctags: 2,327
  • sloc: ruby: 10,321; makefile: 52
file content (594 lines) | stat: -rw-r--r-- 30,923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Net::SSH::Transport::Session</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Net::SSH::Transport::Session</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/lib/net/ssh/transport/session_rb.html">
                lib/net/ssh/transport/session.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Represents a low-level <a href="../../SSH.html">SSH</a> session, at the
transport protocol level. This handles the algorithm negotiation and key
exchange for any <a href="../../SSH.html">SSH</a> connection.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000073">client_name</a>&nbsp;&nbsp;
      <a href="#M000074">close</a>&nbsp;&nbsp;
      <a href="#M000072">new</a>&nbsp;&nbsp;
      <a href="#M000078">ping!</a>&nbsp;&nbsp;
      <a href="#M000077">reader_ready?</a>&nbsp;&nbsp;
      <a href="#M000076">send_message</a>&nbsp;&nbsp;
      <a href="#M000071">version</a>&nbsp;&nbsp;
      <a href="#M000075">wait_for_message</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Constants.html">Constants</a></span>
      </div>
    </div>

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">NAME</td>
          <td>=</td>
          <td class="context-item-value">&quot;Ruby/Net::SSH&quot;</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
The name that <a href="../../SSH.html">Net::SSH</a> reports for itself

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PROTOCOL</td>
          <td>=</td>
          <td class="context-item-value">&quot;SSH-2.0&quot;</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
The <a href="../../SSH.html">SSH</a> protocol supported by <a
href="../../SSH.html">Net::SSH</a>.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">VALID_OPTIONS</td>
          <td>=</td>
          <td class="context-item-value">[ :port, :host_key, :kex, :encryption, :hmac,                           :compression, :languages, :compression_level, :proxy,                           :timeout ]</td>
        </tr>
        </table>
      </div>
    </div>



    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">algorithm_negotiator</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">algorithms</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
the collection of algorithms currently being used

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ciphers</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">compressors</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">decompressors</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">default_port</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">hmacs</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">kexs</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">logger</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">packet_receiver</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">packet_sender</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">session_id</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
the unique session identifier

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">socket_factory</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">version_negotiator</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000072" class="method-detail">
        <a name="M000072"></a>

        <div class="method-heading">
          <a href="#M000072" class="method-signature">
          <span class="method-name">new</span><span class="method-args">( host, options={} ) {|self| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a new connection to the given host. This will negotiate the
algorithms to use and exchange the keys. A block must be given. The
uninitialized <tt>self</tt> will be passed to the block, so that
dependencies may be injected.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000072-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000072-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 71</span>
 71:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-identifier">host</span>, <span class="ruby-identifier">options</span>={} )
 72:           <span class="ruby-ivar">@saved_message</span> = <span class="ruby-keyword kw">nil</span>
 73:           <span class="ruby-ivar">@session_id</span> = <span class="ruby-keyword kw">nil</span>
 74: 
 75:           <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
 76: 
 77:           <span class="ruby-identifier">invalid_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">keys</span> <span class="ruby-operator">-</span> <span class="ruby-constant">VALID_OPTIONS</span>
 78: 
 79:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">invalid_options</span>.<span class="ruby-identifier">empty?</span>
 80:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
 81:               <span class="ruby-node">&quot;invalid option(s) to #{self.class}: #{invalid_options.inspect}&quot;</span>
 82:           <span class="ruby-keyword kw">end</span>
 83: 
 84:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-value str">&quot;connecting&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
 85: 
 86:           <span class="ruby-ivar">@port</span> = <span class="ruby-identifier">options</span>[ <span class="ruby-identifier">:port</span> ] <span class="ruby-operator">||</span> <span class="ruby-ivar">@default_port</span>
 87:           <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">timeout</span>( <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-value">0</span> ) <span class="ruby-keyword kw">do</span>
 88:             ( <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:proxy</span>] <span class="ruby-operator">||</span> <span class="ruby-ivar">@socket_factory</span> ).<span class="ruby-identifier">open</span>( <span class="ruby-identifier">host</span>, <span class="ruby-ivar">@port</span> )
 89:           <span class="ruby-keyword kw">end</span>
 90: 
 91:           <span class="ruby-ivar">@packet_sender</span>.<span class="ruby-identifier">socket</span> = <span class="ruby-ivar">@socket</span>
 92:           <span class="ruby-ivar">@packet_receiver</span>.<span class="ruby-identifier">socket</span> = <span class="ruby-ivar">@socket</span>
 93: 
 94:           <span class="ruby-ivar">@kex_info</span> = {
 95:             <span class="ruby-identifier">:client_version_string</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">version</span>,
 96:             <span class="ruby-identifier">:server_version_string</span> =<span class="ruby-operator">&gt;</span>
 97:               <span class="ruby-ivar">@version_negotiator</span>.<span class="ruby-identifier">negotiate</span>( <span class="ruby-ivar">@socket</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">version</span> ) }
 98: 
 99:           <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">options</span>
100:           <span class="ruby-identifier">kexinit</span>
101:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000071" class="method-detail">
        <a name="M000071"></a>

        <div class="method-heading">
          <a href="#M000071" class="method-signature">
          <span class="method-name">version</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the version string of this client.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000071-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000071-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 59</span>
59:         <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">version</span>
60:           <span class="ruby-node">&quot;#{PROTOCOL}-#{NAME}_#{Net::SSH::Version::STRING}&quot;</span>
61:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000073" class="method-detail">
        <a name="M000073"></a>

        <div class="method-heading">
          <a href="#M000073" class="method-signature">
          <span class="method-name">client_name</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the name of the client&#8217;s host, as reported by the socket.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000073-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000073-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 104</span>
104:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">client_name</span>
105:           <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@hostname</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@hostname</span>
106: 
107:           <span class="ruby-identifier">sockaddr</span> = <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">getsockname</span>
108:           <span class="ruby-keyword kw">begin</span>
109:             <span class="ruby-ivar">@hostname</span> =
110:               <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">getnameinfo</span>( <span class="ruby-identifier">sockaddr</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">NI_NAMEREQD</span> ).<span class="ruby-identifier">first</span>
111:           <span class="ruby-keyword kw">rescue</span>
112:             <span class="ruby-keyword kw">begin</span>
113:               <span class="ruby-ivar">@hostname</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">getnameinfo</span>( <span class="ruby-identifier">sockaddr</span> ).<span class="ruby-identifier">first</span>
114:             <span class="ruby-keyword kw">rescue</span>
115:               <span class="ruby-keyword kw">begin</span>
116:                 <span class="ruby-ivar">@hostname</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">gethostbyname</span>( <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">gethostname</span> ).<span class="ruby-identifier">first</span>
117:               <span class="ruby-keyword kw">rescue</span>
118:                 <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-value str">&quot;the client ipaddr/name could not be determined&quot;</span>
119:               <span class="ruby-keyword kw">end</span>
120:             <span class="ruby-keyword kw">end</span>
121:           <span class="ruby-keyword kw">end</span>
122: 
123:           <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@hostname</span>
124:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000074" class="method-detail">
        <a name="M000074"></a>

        <div class="method-heading">
          <a href="#M000074" class="method-signature">
          <span class="method-name">close</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Closes the connection.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000074-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000074-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 139</span>
139:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close</span>
140:           <span class="ruby-comment cmt"># TODO: send a DISCONNECT message to the server to close gracefully</span>
141:           <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
142:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000078" class="method-detail">
        <a name="M000078"></a>

        <div class="method-heading">
          <a href="#M000078" class="method-signature">
          <span class="method-name">ping!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sends an IGNORE packet to the server, as a way to ping the connection and
make sure the server knows the client is still active.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000078-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000078-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 317</span>
317:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ping!</span>
318:           <span class="ruby-identifier">send_message</span> [<span class="ruby-constant">IGNORE</span>, <span class="ruby-value">4</span>, <span class="ruby-value str">&quot;ping&quot;</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;cNA4&quot;</span>)
319:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000077" class="method-detail">
        <a name="M000077"></a>

        <div class="method-heading">
          <a href="#M000077" class="method-signature">
          <span class="method-name">reader_ready?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if there are bytes to be read on the socket. Note that this
only means there is an encrypted packet ready to be read, not that there is
data available to any particular <a href="../../SSH.html">SSH</a> channel.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000077-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000077-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 311</span>
311:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reader_ready?</span>
312:           <span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span>([<span class="ruby-ivar">@socket</span>],<span class="ruby-keyword kw">nil</span>,<span class="ruby-keyword kw">nil</span>,<span class="ruby-value">0</span>) <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">nil</span>
313:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000076" class="method-detail">
        <a name="M000076"></a>

        <div class="method-heading">
          <a href="#M000076" class="method-signature">
          <span class="method-name">send_message</span><span class="method-args">( message )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sends the given payload, using the currently configured <a
href="OutgoingPacketStream.html">OutgoingPacketStream</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000076-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000076-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 300</span>
300:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_message</span>( <span class="ruby-identifier">message</span> )
301:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
302:             <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;sending message &gt;&gt;#{message.to_s.inspect}&lt;&lt;&quot;</span>
303:           <span class="ruby-keyword kw">end</span>
304: 
305:           <span class="ruby-ivar">@packet_sender</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">message</span>
306:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000075" class="method-detail">
        <a name="M000075"></a>

        <div class="method-heading">
          <a href="#M000075" class="method-signature">
          <span class="method-name">wait_for_message</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Waits for the next message from the server, handling common requests like
DISCONNECT, IGNORE, DEBUG, and KEXINIT in the background. The next message
is returned as a [ type, buffer ] tuple, where the buffer is a <a
href="../Util/ReaderBuffer.html">Net::SSH::Util::ReaderBuffer</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000075-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000075-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/transport/session.rb, line 234</span>
234:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_for_message</span>
235:           <span class="ruby-identifier">buffer</span> = <span class="ruby-identifier">type</span> = <span class="ruby-keyword kw">nil</span>
236: 
237:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@saved_message</span>
238:             <span class="ruby-identifier">type</span>, <span class="ruby-identifier">buffer</span> = <span class="ruby-ivar">@saved_message</span>
239:             <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;returning saved message: #{type}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
240:             <span class="ruby-ivar">@saved_message</span> = <span class="ruby-keyword kw">nil</span>
241:           <span class="ruby-keyword kw">else</span>
242:             <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
243:               <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
244:                 <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-value str">&quot;waiting for packet from server...&quot;</span>
245:               <span class="ruby-keyword kw">end</span>
246: 
247:               <span class="ruby-identifier">buffer</span> = <span class="ruby-ivar">@packet_receiver</span>.<span class="ruby-identifier">get</span>
248:               <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">buffer</span>
249: 
250:               <span class="ruby-identifier">type</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_byte</span>
251:               <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;got packet of type #{type}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
252: 
253:               <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>
254:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">DISCONNECT</span>
255:                   <span class="ruby-identifier">reason_code</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_long</span>
256:                   <span class="ruby-identifier">description</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_string</span>
257:                   <span class="ruby-identifier">language</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_string</span>
258:                   <span class="ruby-identifier">raise</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SSH</span><span class="ruby-operator">::</span><span class="ruby-constant">Transport</span><span class="ruby-operator">::</span><span class="ruby-constant">Disconnect</span>,
259:                     <span class="ruby-node">&quot;disconnected: #{description} (#{reason_code})&quot;</span>
260: 
261:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">IGNORE</span>
262:                   <span class="ruby-comment cmt"># do nothing</span>
263:                   <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;received IGNORE message &quot;</span> <span class="ruby-operator">+</span>
264:                     <span class="ruby-node">&quot;(#{buffer.read_string.inspect})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
265: 
266:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">DEBUG</span>
267:                   <span class="ruby-comment cmt"># do nothing</span>
268:                   <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;received DEBUG message&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
269:                   <span class="ruby-identifier">always_display</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_bool</span>
270:                   <span class="ruby-identifier">message</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_string</span>
271:                   <span class="ruby-identifier">language</span> = <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">read_string</span>
272:                   <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">always_display</span>
273:                     <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;#{message} (#{language})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">warn?</span>
274:                   <span class="ruby-keyword kw">else</span>
275:                     <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;#{message} (#{language})&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug?</span>
276:                   <span class="ruby-keyword kw">end</span>
277: 
278:                 <span class="ruby-keyword kw">when</span> <span class="ruby-constant">KEXINIT</span>
279:                   <span class="ruby-comment cmt"># unless we're already doing a key-exchange, do key</span>
280:                   <span class="ruby-comment cmt"># re-exchange</span>
281:                   <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@doing_kexinit</span>
282:                     <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-value str">&quot;re-key requested&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info?</span>
283:                     <span class="ruby-ivar">@saved_message</span> = [ <span class="ruby-identifier">type</span>, <span class="ruby-identifier">buffer</span> ]
284:                     <span class="ruby-identifier">kexinit</span>
285:                   <span class="ruby-keyword kw">else</span>
286:                     <span class="ruby-keyword kw">break</span>
287:                   <span class="ruby-keyword kw">end</span>
288: 
289:                 <span class="ruby-keyword kw">else</span>
290:                   <span class="ruby-keyword kw">break</span>
291:               <span class="ruby-keyword kw">end</span>
292:             <span class="ruby-keyword kw">end</span>
293:           <span class="ruby-keyword kw">end</span>
294: 
295:           <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">type</span>, <span class="ruby-identifier">buffer</span>
296:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>