# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # import optparse, sys, time, uuid import re, socket, select, errno from proton import Message # @todo stop the madness: import container as fusion_container import connection as fusion_connection import link as fusion_link """ This module implements a simple RPC client. The client sends a 'method call' to a server, and waits for a response. The method call is a map of the form: {'method': '', 'args': { 0: readfd = [my_socket] if connection.has_output > 0: writefd = [my_socket] timeout = None deadline = connection.next_tick if deadline: now = time.time() timeout = 0 if deadline <= now else deadline - now print("select start (t=%s)" % str(timeout)) readable,writable,ignore = select.select(readfd,writefd,[],timeout) print("select return") if readable: count = connection.needs_input if count > 0: try: sock_data = my_socket.recv(count) if sock_data: connection.process_input( sock_data ) else: # closed? connection.close_input() except socket.timeout, e: raise # I don't expect this except socket.error, e: err = e.args[0] # ignore non-fatal errors if (err != errno.EAGAIN and err != errno.EWOULDBLOCK and err != errno.EINTR): # otherwise, unrecoverable: connection.close_input() raise except: # beats me... connection.close_input() raise if writable: data = connection.output_data() if data: try: rc = my_socket.send(data) if rc > 0: connection.output_written(rc) else: # else socket closed connection.close_output() except socket.timeout, e: raise # I don't expect this except socket.error, e: err = e.args[0] # ignore non-fatal errors if (err != errno.EAGAIN and err != errno.EWOULDBLOCK and err != errno.EINTR): # otherwise, unrecoverable connection.close_output() raise except: # beats me... connection.close_output() raise connection.process(time.time()) print "DONE" return 0 if __name__ == "__main__": sys.exit(main())