Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 1 | <!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" |
| 19 | border="0" height="32" |
| 20 | alt="Previous Page" width="32"></A></td> |
| 21 | <td><A href="internals.html"><img src="up.gif" |
| 22 | border="0" height="32" |
| 23 | alt="Up One Level" width="32"></A></td> |
| 24 | <td><A href="about.html"><img src="next.gif" |
| 25 | border="0" height="32" |
| 26 | 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" |
| 29 | border="0" height="32" |
| 30 | 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"> </A> |
| 46 | <BR> |
| 47 | 4.3 Acessing Socket Methods |
| 48 | </H2> |
| 49 | <P> |
| 50 | <EM><EM><EM>We quickly saw the benefit of wrapping socket methods in the |
| 51 | <tt class="class">SSL.Connection</tt> class, for an easy transition into using SSL. The |
| 52 | problem here is that the <tt class="module">socket</tt> module lacks a C API, and all the |
| 53 | methods are declared static. One approach would be to have <tt class="module">OpenSSL</tt> as |
| 54 | a submodule to the <tt class="module">socket</tt> module, placing all the code in |
| 55 | <span class="file">socketmodule.c</span>, but this is obviously not a good solution, since you |
| 56 | might not want to import tonnes of extra stuff you're not going to use when |
| 57 | importing the <tt class="module">socket</tt> module. The other approach is to somehow get a |
| 58 | pointer to the method to be called, either the C function, or a callable Python |
| 59 | object. This is not really a good solution either, since there's a lot of |
| 60 | lookups involved. |
| 61 | </EM></EM></EM> |
| 62 | <P> |
| 63 | <EM><EM><EM>The way it works is that you have to supply a ``<tt class="class">socket</tt>-like'' transport |
| 64 | object to the <tt class="class">SSL.Connection</tt>. The only requirement of this object is |
| 65 | that it has a <tt class="method">fileno()</tt> method that returns a file descriptor that's |
| 66 | valid at the C level (i.e. you can use the system calls read and write). If you |
| 67 | want to use the <tt class="method">connect()</tt> or <tt class="method">accept()</tt> methods of the |
| 68 | <tt class="class">SSL.Connection</tt> object, the transport object has to supply such |
| 69 | methods too. Apart from them, any method lookups in the <tt class="class">SSL.Connection</tt> |
| 70 | object that fail are passed on to the underlying transport object. |
| 71 | </EM></EM></EM> |
| 72 | <P> |
| 73 | <EM><EM><EM>Future changes might be to allow Python-level transport objects, that instead |
| 74 | of having <tt class="method">fileno()</tt> methods, have <tt class="method">read()</tt> and <tt class="method">write()</tt> |
| 75 | methods, so more advanced features of Python can be used. This would probably |
| 76 | entail some sort of OpenSSL ``BIOs'', but converting Python strings back and |
| 77 | forth is expensive, so this shouldn't be used unless necessary. Other nice |
| 78 | things would be to be able to pass in different transport objects for reading |
| 79 | and writing, but then the <tt class="method">fileno()</tt> method of <tt class="class">SSL.Connection</tt> |
| 80 | becomes virtually useless. Also, should the method resolution be used on the |
| 81 | read-transport or the write-transport? |
| 82 | </EM></EM></EM> |
| 83 | <P> |
| 84 | |
| 85 | <DIV CLASS="navigation"> |
| 86 | <p><hr> |
| 87 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 88 | <tr> |
| 89 | <td><A href="callbacks.html"><img src="previous.gif" |
| 90 | border="0" height="32" |
| 91 | alt="Previous Page" width="32"></A></td> |
| 92 | <td><A href="internals.html"><img src="up.gif" |
| 93 | border="0" height="32" |
| 94 | alt="Up One Level" width="32"></A></td> |
| 95 | <td><A href="about.html"><img src="next.gif" |
| 96 | border="0" height="32" |
| 97 | alt="Next Page" width="32"></A></td> |
| 98 | <td align="center" width="100%">Python OpenSSL Manual</td> |
| 99 | <td><A href="contents.html"><img src="contents.gif" |
| 100 | border="0" height="32" |
| 101 | alt="Contents" width="32"></A></td> |
| 102 | <td><img src="blank.gif" |
| 103 | border="0" height="32" |
| 104 | alt="" width="32"></td> |
| 105 | <td><img src="blank.gif" |
| 106 | border="0" height="32" |
| 107 | alt="" width="32"></td> |
| 108 | </tr></table> |
| 109 | <b class="navlabel">Previous:</b> <a class="sectref" href="callbacks.html">4.2 Callbacks</A> |
| 110 | <b class="navlabel">Up:</b> <a class="sectref" href="internals.html">4 Internals</A> |
| 111 | <b class="navlabel">Next:</b> <a class="sectref" href="about.html">About this document ...</A> |
| 112 | <hr> |
| 113 | <span class="release-info">Release 0.6.</span> |
| 114 | </DIV> |
| 115 | <!--End of Navigation Panel--> |
| 116 | |
| 117 | </BODY> |
| 118 | </HTML> |