| <!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"> </A> |
| <BR> |
| 4.3 Acessing Socket Methods |
| </H2> |
| <P> |
| <EM><EM><EM>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. |
| </EM></EM></EM> |
| <P> |
| <EM><EM><EM>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. |
| </EM></EM></EM> |
| <P> |
| <EM><EM><EM>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? |
| </EM></EM></EM> |
| <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.6.</span> |
| </DIV> |
| <!--End of Navigation Panel--> |
| |
| </BODY> |
| </HTML> |