1 | /******************************************************************************
|
---|
2 | *
|
---|
3 | * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
|
---|
4 | * www.mindbright.se, [email protected]
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | *****************************************************************************
|
---|
17 | * $Author: mats $
|
---|
18 | * $Date: 2000/03/02 19:52:24 $
|
---|
19 | * $Name: rel1-2-1 $
|
---|
20 | *****************************************************************************/
|
---|
21 | package mindbright.ssh;
|
---|
22 |
|
---|
23 | import java.io.*;
|
---|
24 |
|
---|
25 | public class SSHTxChannel extends SSHChannel {
|
---|
26 |
|
---|
27 | protected OutputStream out;
|
---|
28 | protected SSHPduQueue queue;
|
---|
29 |
|
---|
30 | boolean closePending;
|
---|
31 |
|
---|
32 | public SSHTxChannel(OutputStream out, int channelId) {
|
---|
33 | super(channelId);
|
---|
34 | this.out = out;
|
---|
35 | this.closePending = false;
|
---|
36 | queue = new SSHPduQueue();
|
---|
37 | }
|
---|
38 |
|
---|
39 | public SSHPduQueue getQueue() {
|
---|
40 | return queue;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void setClosePending() {
|
---|
44 | closePending = true;
|
---|
45 | queue.release();
|
---|
46 | }
|
---|
47 |
|
---|
48 | public synchronized boolean isClosePending() {
|
---|
49 | return closePending;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void serviceLoop() throws Exception {
|
---|
53 | SSH.logExtra("Starting tx-chan: " + channelId);
|
---|
54 | for(;;) {
|
---|
55 | SSHPdu pdu;
|
---|
56 | // !!! the thread is (hopefully) suspended when we set closePending
|
---|
57 | // so we don't have to access a lock each loop
|
---|
58 | if(closePending && queue.isEmpty()) {
|
---|
59 | throw new Exception("CLOSE");
|
---|
60 | }
|
---|
61 | pdu = queue.getFirst();
|
---|
62 | // pdu = pdu.preProcess();
|
---|
63 | pdu.writeTo(out);
|
---|
64 | // pdu = pdu.postProcess();
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|