blob: 46ecc01e38303b833fbcceca03080a4d4faaa0ad [file] [log] [blame]
Jean-Paul Calderone897bc252008-02-18 20:50:23 -05001<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<title>4.3 Acessing Socket Methods </title>
5<META NAME="description" CONTENT="4.3 Acessing Socket Methods ">
6<META NAME="keywords" CONTENT="pyOpenSSL">
7<META NAME="resource-type" CONTENT="document">
8<META NAME="distribution" CONTENT="global">
9<link rel="STYLESHEET" href="pyOpenSSL.css">
10<LINK REL="previous" href="callbacks.html">
11<LINK REL="up" href="internals.html">
12<LINK REL="next" href="about.html">
13</head>
14<body>
15<DIV CLASS="navigation">
16<table align="center" width="100%" cellpadding="0" cellspacing="2">
17<tr>
18<td><A href="callbacks.html"><img src="previous.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050019 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050020 alt="Previous Page" width="32"></A></td>
21<td><A href="internals.html"><img src="up.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050022 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050023 alt="Up One Level" width="32"></A></td>
24<td><A href="about.html"><img src="next.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050025 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050026 alt="Next Page" width="32"></A></td>
27<td align="center" width="100%">Python OpenSSL Manual</td>
28<td><A href="contents.html"><img src="contents.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050029 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050030 alt="Contents" width="32"></A></td>
31<td><img src="blank.gif"
32 border="0" height="32"
33 alt="" width="32"></td>
34<td><img src="blank.gif"
35 border="0" height="32"
36 alt="" width="32"></td>
37</tr></table>
38<b class="navlabel">Previous:</b> <a class="sectref" href="callbacks.html">4.2 Callbacks</A>
39<b class="navlabel">Up:</b> <a class="sectref" href="internals.html">4 Internals</A>
40<b class="navlabel">Next:</b> <a class="sectref" href="about.html">About this document ...</A>
41<br><hr>
42</DIV>
43<!--End of Navigation Panel-->
44
45<H2><A NAME="SECTION000530000000000000000">&nbsp;</A>
46<BR>
474.3 Acessing Socket Methods
48</H2>
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050049
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050050<P>
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050051We quickly saw the benefit of wrapping socket methods in the
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050052<tt class="class">SSL.Connection</tt> class, for an easy transition into using SSL. The
53problem here is that the <tt class="module">socket</tt> module lacks a C API, and all the
54methods are declared static. One approach would be to have <tt class="module">OpenSSL</tt> as
55a submodule to the <tt class="module">socket</tt> module, placing all the code in
56<span class="file">socketmodule.c</span>, but this is obviously not a good solution, since you
57might not want to import tonnes of extra stuff you're not going to use when
58importing the <tt class="module">socket</tt> module. The other approach is to somehow get a
59pointer to the method to be called, either the C function, or a callable Python
60object. This is not really a good solution either, since there's a lot of
61lookups involved.
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050062
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050063<P>
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050064The way it works is that you have to supply a ``<tt class="class">socket</tt>-like'' transport
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050065object to the <tt class="class">SSL.Connection</tt>. The only requirement of this object is
66that it has a <tt class="method">fileno()</tt> method that returns a file descriptor that's
67valid at the C level (i.e. you can use the system calls read and write). If you
68want to use the <tt class="method">connect()</tt> or <tt class="method">accept()</tt> methods of the
69<tt class="class">SSL.Connection</tt> object, the transport object has to supply such
70methods too. Apart from them, any method lookups in the <tt class="class">SSL.Connection</tt>
71object that fail are passed on to the underlying transport object.
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050072
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050073<P>
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050074Future changes might be to allow Python-level transport objects, that instead
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050075of having <tt class="method">fileno()</tt> methods, have <tt class="method">read()</tt> and <tt class="method">write()</tt>
76methods, so more advanced features of Python can be used. This would probably
77entail some sort of OpenSSL ``BIOs'', but converting Python strings back and
78forth is expensive, so this shouldn't be used unless necessary. Other nice
79things would be to be able to pass in different transport objects for reading
80and writing, but then the <tt class="method">fileno()</tt> method of <tt class="class">SSL.Connection</tt>
81becomes virtually useless. Also, should the method resolution be used on the
82read-transport or the write-transport?
Jean-Paul Calderone2aa2b332008-03-06 21:43:14 -050083
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050084<P>
85
86<DIV CLASS="navigation">
87<p><hr>
88<table align="center" width="100%" cellpadding="0" cellspacing="2">
89<tr>
90<td><A href="callbacks.html"><img src="previous.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050091 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050092 alt="Previous Page" width="32"></A></td>
93<td><A href="internals.html"><img src="up.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050094 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050095 alt="Up One Level" width="32"></A></td>
96<td><A href="about.html"><img src="next.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -050097 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -050098 alt="Next Page" width="32"></A></td>
99<td align="center" width="100%">Python OpenSSL Manual</td>
100<td><A href="contents.html"><img src="contents.gif"
Jean-Paul Calderone215d51b2009-11-13 09:19:21 -0500101 border="0" height="32"
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500102 alt="Contents" width="32"></A></td>
103<td><img src="blank.gif"
104 border="0" height="32"
105 alt="" width="32"></td>
106<td><img src="blank.gif"
107 border="0" height="32"
108 alt="" width="32"></td>
109</tr></table>
110<b class="navlabel">Previous:</b> <a class="sectref" href="callbacks.html">4.2 Callbacks</A>
111<b class="navlabel">Up:</b> <a class="sectref" href="internals.html">4 Internals</A>
112<b class="navlabel">Next:</b> <a class="sectref" href="about.html">About this document ...</A>
113<hr>
Jean-Paul Calderone26ebc9e2011-04-11 19:57:10 -0400114<span class="release-info">Release 0.12.</span>
Jean-Paul Calderone897bc252008-02-18 20:50:23 -0500115</DIV>
116<!--End of Navigation Panel-->
117
118</BODY>
119</HTML>