1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
diff -r 16a4000624a7 stomp/connect.py
--- a/stomp/connect.py Sun May 02 18:15:34 2010 +0100
+++ b/stomp/connect.py Fri Aug 26 15:35:33 2011 +0100
@@ -88,7 +88,10 @@
ssl_key_file = None,
ssl_cert_file = None,
ssl_ca_certs = None,
- ssl_cert_validator = None):
+ ssl_cert_validator = None,
+ version = None,
+ heartbeat = None,
+ virtual_host = None):
"""
Initialize and start this connection.
@@ -159,6 +162,16 @@
where OK is a boolean, and cert is a certificate structure
as returned by ssl.SSLSocket.getpeercert()
+
+ \param version
+ (optional) stomp version header to send (comma separated)
+
+ \param heartbeat
+ (optional) heartbeat header to send (STOMP 1.1)
+
+ \param virtual_host
+ (optional) virtual_host header to send (STOMP 1.1)
+
"""
sorted_host_and_ports = []
@@ -205,6 +218,15 @@
self.__connect_headers['login'] = user
self.__connect_headers['passcode'] = passcode
+ if version is not None:
+ self.__connect_headers['accept-version'] = version
+
+ if heartbeat is not None:
+ self.__connect_headers['heart-beat'] = heartbeat
+
+ if virtual_host is not None:
+ self.__connect_headers['host'] = virtual_host
+
self.__socket = None
self.__socket_semaphore = threading.BoundedSemaphore(1)
self.__current_host_and_port = None
@@ -383,6 +405,10 @@
"""
self.__send_frame_helper('DISCONNECT', '', utils.merge_headers([self.__connect_headers, headers, keyword_headers]), [ ])
self.__running = False
+ self.close_socket()
+ self.__current_host_and_port = None
+
+ def close_socket(self):
if self.__socket is not None:
if self.__ssl:
#
@@ -390,20 +416,23 @@
#
try:
self.__socket = self.__socket.unwrap()
- except Exception:
+ except Exception as e:
#
# unwrap seems flaky on Win with the backported ssl mod, so catch any exception and log it
#
- _, e, _ = sys.exc_info()
- log.warn(e)
+ log.warning("socket unwrap() threw exception: %s" % e)
elif hasattr(socket, 'SHUT_RDWR'):
- self.__socket.shutdown(socket.SHUT_RDWR)
+ try:
+ self.__socket.shutdown(socket.SHUT_RDWR)
+ except Exception as e:
+ log.warning("socket shutdown() threw exception: %s" % e)
#
- # split this into a separate check, because sometimes the socket is nulled between shutdown and this call
+ # caution, because sometimes the socket is nulled between shutdown and this call
#
- if self.__socket is not None:
+ try:
self.__socket.close()
- self.__current_host_and_port = None
+ except Exception as e:
+ log.warning("socket close() threw exception: %s" % e)
def __convert_dict(self, payload):
"""
@@ -449,6 +478,9 @@
raise KeyError("Command %s requires header %r" % (command, required_header_key))
self.__send_frame(command, headers, payload)
+ def send_frame(self, command, headers={}, payload=''):
+ self.__send_frame(command, headers, payload)
+
def __send_frame(self, command, headers={}, payload=''):
"""
Send a STOMP frame.
@@ -680,4 +712,4 @@
sleep_exp += 1
if not self.__socket:
- raise exception.ReconnectFailedException
\ No newline at end of file
+ raise exception.ReconnectFailedException
|