summaryrefslogtreecommitdiff
path: root/doc/html/socket-methods.html
blob: 07a081f04997aacfb9b79e5cf4c44f2013c21ebd (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.3 Acessing Socket Methods </title>
<META NAME="description" CONTENT="4.3 Acessing Socket Methods ">
<META NAME="keywords" CONTENT="pyOpenSSL">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<link rel="STYLESHEET" href="pyOpenSSL.css">
<LINK REL="previous" href="callbacks.html">
<LINK REL="up" href="internals.html">
<LINK REL="next" href="about.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="callbacks.html"><img src="previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="internals.html"><img src="up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="about.html"><img src="next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python OpenSSL Manual</td>
<td><A href="contents.html"><img src="contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="callbacks.html">4.2 Callbacks</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internals.html">4 Internals</A>
<b class="navlabel">Next:</b> <a class="sectref" href="about.html">About this document ...</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION000530000000000000000">&nbsp;</A>
<BR>
4.3 Acessing Socket Methods 
</H2>

<P>
We quickly saw the benefit of wrapping socket methods in the
<tt class="class">SSL.Connection</tt> class, for an easy transition into using SSL. The
problem here is that the <tt class="module">socket</tt> module lacks a C API, and all the
methods are declared static. One approach would be to have <tt class="module">OpenSSL</tt> as
a submodule to the <tt class="module">socket</tt> module, placing all the code in
<span class="file">socketmodule.c</span>, but this is obviously not a good solution, since you
might not want to import tonnes of extra stuff you're not going to use when
importing the <tt class="module">socket</tt> module. The other approach is to somehow get a
pointer to the method to be called, either the C function, or a callable Python
object. This is not really a good solution either, since there's a lot of
lookups involved.

<P>
The way it works is that you have to supply a ``<tt class="class">socket</tt>-like'' transport
object to the <tt class="class">SSL.Connection</tt>. The only requirement of this object is
that it has a <tt class="method">fileno()</tt> method that returns a file descriptor that's
valid at the C level (i.e. you can use the system calls read and write). If you
want to use the <tt class="method">connect()</tt> or <tt class="method">accept()</tt> methods of the
<tt class="class">SSL.Connection</tt> object, the transport object has to supply such
methods too. Apart from them, any method lookups in the <tt class="class">SSL.Connection</tt>
object that fail are passed on to the underlying transport object.

<P>
Future changes might be to allow Python-level transport objects, that instead
of having <tt class="method">fileno()</tt> methods, have <tt class="method">read()</tt> and <tt class="method">write()</tt>
methods, so more advanced features of Python can be used. This would probably
entail some sort of OpenSSL ``BIOs'', but converting Python strings back and
forth is expensive, so this shouldn't be used unless necessary. Other nice
things would be to be able to pass in different transport objects for reading
and writing, but then the <tt class="method">fileno()</tt> method of <tt class="class">SSL.Connection</tt>
becomes virtually useless. Also, should the method resolution be used on the
read-transport or the write-transport?

<P>

<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="callbacks.html"><img src="previous.gif"
  border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="internals.html"><img src="up.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="about.html"><img src="next.gif"
  border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python OpenSSL Manual</td>
<td><A href="contents.html"><img src="contents.gif"
  border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="callbacks.html">4.2 Callbacks</A>
<b class="navlabel">Up:</b> <a class="sectref" href="internals.html">4 Internals</A>
<b class="navlabel">Next:</b> <a class="sectref" href="about.html">About this document ...</A>
<hr>
<span class="release-info">Release 0.13.</span>
</DIV>
<!--End of Navigation Panel-->

</BODY>
</HTML>