def run(self): # we will wait on 2 file descriptors fds = [stdin, self.sock_file] # this is the main trick when trying to provide a virtual # terminal remotely: the client should set its own terminal # in 'raw' mode, in order to avoid interpreting any escape # sequence (ctrl-r, etc.). These sequences should just be # forwarded up to the terminal running on the server, and # this remote terminal will interpret them. # Also, echo-ing what is typed should be disabled at the # client side, otherwise it would be echo-ed twice. # It is better to consider that the server terminal will # handle all outputs, otherwise the synchronization between # the output coming from the client (echo) and from the # server (command outputs, prompts) will not be perfect # because of network latency. Thus we let the server terminal # handle the echo. if self.client_tty: self.tty_settings.set_raw_no_echo() try: while True: rlist, wlist, elist = select(fds, [], fds) if len(elist) > 0 and len(rlist) == 0: break fd = rlist[0].fileno() if fd == self.sock_file.fileno(): if read_and_copy(self.sock_file, stdout.buffer) == False: break else: if read_and_copy(self.stdin_reader, self.sock_file) == False: # stdin was probably closed, inform the server input is ending # and continue by reading socket only self.sock_file.shutdown(SHUT_WR) fds = [self.sock_file] finally: if self.client_tty: self.tty_settings.restore()
def handle_event(self, ts): if self.node_ip_and_port == None: # we did not get the parameters yet, let's do it params = read_pickle(self.client_sock_file) if params == None: self.close() # issue return False self.node_ip_and_port = (params['node_ip'], params['node_port']) # we now have all info to connect to the node return self.start() else: # otherwise we are all set. Thus, getting input data means # data was sent on the other end. return read_and_copy(self.client_sock_file, self.node_sock_file)
def handle_event(self, ts): if self.node_ip_and_port == None: # we did not get the parameters yet, let's do it params = read_pickle(self.client_sock_file) if params == None: self.close() # issue return False self.node_ip_and_port = (params['node_ip'], params['node_port']) # we now have all info to connect to the node return self.start() else: # otherwise we are all set. Thus, getting input data means # data was sent on the other end. return read_and_copy( self.client_sock_file, self.node_sock_file)
def run(self): self.local_server_s = server_socket(self.local_port) while True: read_socks = self.associations.keys() + [ self.local_server_s ] select_args = [ read_socks, [], read_socks ] rlist, wlist, elist = select(*select_args) if len(elist) > 0 or len(rlist) == 0: break sock_r = rlist[0] if sock_r == self.local_server_s: if self.event_on_server_s() == False: break else: paired_sock = self.associations[sock_r] if read_and_copy(sock_r, paired_sock) == False: for s in (sock_r, paired_sock): s.close() del self.associations[sock_r] del self.associations[paired_sock]
def handle_event(self, ts): if self.params == None: # we did not get the parameters yet, let's do it self.params = read_pickle(self.client_sock_file) if self.params == None: self.close() # issue return False self.update_params() if self.prepare(**self.params) == False: self.close() # issue return False self.params['cmd'] = self.get_command(**self.params) # we now have all info to start the child process self.start() else: # otherwise we are all set. Thus, getting input data means # the user wrote something on the prompt (i.e. the socket) # we just have to copy this to the slave process input return read_and_copy(self.client_sock_file, self.slave_sock_file)
def run(self): self.local_server_s = server_socket(self.local_port) while True: read_socks = list(self.associations.keys()) + [self.local_server_s] select_args = [read_socks, [], read_socks] rlist, wlist, elist = select(*select_args) if len(elist) > 0 or len(rlist) == 0: break sock_r = rlist[0] if sock_r == self.local_server_s: if self.event_on_server_s() == False: break else: paired_sock = self.associations[sock_r] if read_and_copy(sock_r, paired_sock) == False: for s in (sock_r, paired_sock): s.close() del self.associations[sock_r] del self.associations[paired_sock]
def handle_event(self, ts): return read_and_copy( self.env.node_sock_file, self.env.client_sock_file)