[Python-Dev] [python 2.7] a question about exporting a new method to socket object (original) (raw)

Gerald Klix python.00 at klix.ch
Fri Jun 21 17:06:25 CEST 2013


Hi Ani,

just a simple question: Are you sure, that you imported the modified socket module and not the original module from the distribution?

HTH,

Gerald

Am 21.06.2013 um 07:18 schrieb Ani Sinha <ani at aristanetworks.com>:

Hi python devs :

As a part of exploring an idea, I am trying to add a new method to the python socket object. Here's what I have been trying to do (the patch may be whitespace damaged so please bear with me) :

Index: Python-2.7/Modules/socketmodule.c =================================================================== --- Python-2.7.orig/Modules/socketmodule.c +++ Python-2.7/Modules/socketmodule.c @@ -126,6 +126,7 @@ makefile([mode, [bufsize]]) -- return a _recv(buflen[, flags]) -- receive data\n_ _recvinto(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n_ _recvfrom(buflen[, flags]) -- receive data and sender's address\n_ _+arecvfrom(buflen[, flags]) -- same as recvfrom \n_ _recvfrominto(buffer[, nbytes, [, flags])\n_ _-- receive data and sender's address (into a buffer)\n_ _sendall(data[, flags]) -- send all data\n_ @@ -468,6 +469,13 @@ static PyTypeObject socktype; _#define ISSELECTABLE(s) ((s)->sockfd < FDSETSIZE || s->socktimeout <=_ _0.0)_ _#endif_ _@@ -2620,6 +2802,58 @@ PyDocSTRVAR(recvfromdoc,_ _\n_ _Like recv(buffersize, flags) but also return the sender's address info.");_ _+static PyObject _ +sockarecvfrom(PySocketSockObject *s, PyObject *args) +{ + return sockrecvfrom(s,args); +} + +PyDocSTRVAR(arecvfromdoc, _+"arecvfrom(buffersize[, flags]) -> (data, address info)\n_ _+\n_ + experimental stuff"); _/ s.recvfrominto(buffer[, nbytes [,flags]]) method */_ @@ -2963,6 +3197,8 @@ static PyMethodDef sockmethods[] = { recvintodoc}, {"recvfrom", (PyCFunction)sockrecvfrom, METHVARARGS, recvfromdoc}, + {"arecvfrom", (PyCFunction)sockarecvfrom, METHVARARGS, + arecvfromdoc}, {"recvfrominto", (PyCFunction)sockrecvfrominto, METHVARARGS | METHKEYWORDS, recvfromintodoc}, {"send", (PyCFunction)socksend, METHVARARGS, When I compile this and run a simple script like the following that uses arecvfrom() : sock = socket.socket( socket.PFPACKET, socket.SOCKRAW ) sock.bind( ( intf, ETHPALL ) ) (pkt,dontcare) = dst.arecvfrom( 500, socket.MSGDONTWAIT ) I get this exception : AttributeError: 'socketobject' object has no attribute 'arecvfrom' So what am I doing wrong? How do I export this new socket method? any help/pointer will be greatly appreciated. cheers, ani -- Ani


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/python.00%40klix.ch



More information about the Python-Dev mailing list