1 2 29 30 package com.jcraft.jsch; 31 32 abstract class Request{ 33 private boolean reply=false; 34 private Session session=null; 35 private Channel channel=null; 36 void request(Session session, Channel channel) throws Exception { 37 this.session=session; 38 this.channel=channel; 39 if(channel.connectTimeout>0){ 40 setReply(true); 41 } 42 } 43 boolean waitForReply(){ return reply; } 44 void setReply(boolean reply){ this.reply=reply; } 45 void write(Packet packet) throws Exception { 46 if(reply){ 47 channel.reply=-1; 48 } 49 session.write(packet); 50 if(reply){ 51 long start=System.currentTimeMillis(); 52 long timeout=channel.connectTimeout; 53 while(channel.isConnected() && channel.reply==-1){ 54 try{Thread.sleep(10);} 55 catch(Exception ee){ 56 } 57 if(timeout>0L && 58 (System.currentTimeMillis()-start)>timeout){ 59 channel.reply=0; 60 throw new JSchException("channel request: timeout"); 61 } 62 } 63 64 if(channel.reply==0){ 65 throw new JSchException("failed to send channel request"); 66 } 67 } 68 } 69 } 70 | Popular Tags |