144 |
144 |
145 # Give time to process latest response on server side |
145 # Give time to process latest response on server side |
146 self.__connection.shutdown(socket.SHUT_RDWR) |
146 self.__connection.shutdown(socket.SHUT_RDWR) |
147 self.__connection.close() |
147 self.__connection.close() |
148 |
148 |
149 def poll(self, wait=False): |
149 def poll(self, waitMethod=""): |
150 """ |
150 """ |
151 Public method to check and receive one message (if available). |
151 Public method to check and receive one message (if available). |
152 |
152 |
153 @param wait flag indicating to wait until something has been received |
153 @param waitMethod name of a method to wait for |
|
154 @type str |
154 @type bool |
155 @type bool |
155 @return tuple containing the received command and a dictionary |
156 @return dictionary containing the data of the waited for method |
156 containing the associated data |
157 @rtype dict |
157 @rtype tuple of (str, dict) |
|
158 """ |
158 """ |
159 try: |
159 try: |
160 if wait: |
160 if waitMethod: |
161 rrdy, wrdy, xrdy = select.select( |
161 rrdy, wrdy, xrdy = select.select( |
162 [self.__connection], [], []) |
162 [self.__connection], [], []) |
163 else: |
163 else: |
164 rrdy, wrdy, xrdy = select.select( |
164 rrdy, wrdy, xrdy = select.select( |
165 [self.__connection], [], [], 0) |
165 [self.__connection], [], [], 0) |
167 if self.__connection in rrdy: |
167 if self.__connection in rrdy: |
168 method, params = self.__receiveJson() |
168 method, params = self.__receiveJson() |
169 if method is not None: |
169 if method is not None: |
170 if method == "Exit": |
170 if method == "Exit": |
171 self.__exitClient = True |
171 self.__exitClient = True |
|
172 elif method == waitMethod: |
|
173 return params |
172 else: |
174 else: |
173 if wait: |
175 self.handleCall(method, params) |
174 # wait means to return the data to the caller |
|
175 return method, params |
|
176 else: |
|
177 # no wait means to pass on to the handler method |
|
178 self.handleCall(method, params) |
|
179 |
176 |
180 except (select.error, KeyboardInterrupt, socket.error): |
177 except (select.error, KeyboardInterrupt, socket.error): |
181 # just ignore these |
178 # just ignore these |
182 pass |
179 pass |
183 |
180 |