| Home | Trees | Indices | Help |
|---|
|
|
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 import socket
21 from qpid.util import connect
22
23 TRANSPORTS = {}
24
26
28 self.socket = connect(host, port)
29 if conn.tcp_nodelay:
30 self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
31
33 return self.socket.fileno()
34
36
38 return reading
39
41 return writing
42
44 return self.socket.send(bytes)
45
47 return self.socket.recv(n)
48
50 self.socket.close()
51
52 TRANSPORTS["tcp"] = tcp
53
54 try:
55 from ssl import wrap_socket, SSLError, SSL_ERROR_WANT_READ, \
56 SSL_ERROR_WANT_WRITE
57 except ImportError:
58 pass
59 else:
61
63 SocketTransport.__init__(self, conn, host, port)
64 self.tls = wrap_socket(self.socket, keyfile=conn.ssl_keyfile, certfile=conn.ssl_certfile, ca_certs=conn.ssl_trustfile)
65 self.socket.setblocking(0)
66 self.state = None
67
73
79
81 self._clear_state()
82 try:
83 return self.tls.write(bytes)
84 except SSLError, e:
85 if self._update_state(e.args[0]):
86 return 0
87 else:
88 raise
89
91 self._clear_state()
92 try:
93 return self.tls.read(n)
94 except SSLError, e:
95 if self._update_state(e.args[0]):
96 return None
97 else:
98 raise
99
102
104 if code in (SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE):
105 self.state = code
106 return True
107 else:
108 return False
109
114
115 TRANSPORTS["ssl"] = tls
116 TRANSPORTS["tcp+tls"] = tls
117
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Mar 15 14:54:53 2012 | http://epydoc.sourceforge.net |