Hi Guido : Thanks a lot. That helped.
I will try StackOverflow next time. cheers, ani On Fri, Jun 21, 2013 at 8:07 AM, Guido van Rossum <gu...@python.org> wrote: > Technically this list isn't the right place, but you probably are > bitten by the duplication of functionality in Lib/socket.py. There's a > list of methods at the top of that file, _socketmethods. > > But you really shouldn't be asking here -- this list is for changes to > Python, not using or hacking it. (Try StackOverflow for that.) > > --Guido > > On Thu, Jun 20, 2013 at 10:18 PM, Ani Sinha <a...@aristanetworks.com> > wrote: > > 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\ > > recv_into(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\ > > recvfrom_into(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 sock_type; > > #define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout > <= > > 0.0) > > #endif > > > > @@ -2620,6 +2802,58 @@ PyDoc_STRVAR(recvfrom_doc, > > \n\ > > Like recv(buffersize, flags) but also return the sender's address > info."); > > > > +static PyObject * > > +sock_arecvfrom(PySocketSockObject *s, PyObject *args) > > +{ > > + return sock_recvfrom(s,args); > > +} > > + > > +PyDoc_STRVAR(arecvfrom_doc, > > +"arecvfrom(buffersize[, flags]) -> (data, address info)\n\ > > +\n\ > > + experimental stuff"); > > > > /* s.recvfrom_into(buffer[, nbytes [,flags]]) method */ > > > > @@ -2963,6 +3197,8 @@ static PyMethodDef sock_methods[] = { > > recv_into_doc}, > > {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS, > > recvfrom_doc}, > > + {"arecvfrom", (PyCFunction)sock_arecvfrom, METH_VARARGS, > > + arecvfrom_doc}, > > {"recvfrom_into", (PyCFunction)sock_recvfrom_into, METH_VARARGS | > > METH_KEYWORDS, > > recvfrom_into_doc}, > > {"send", (PyCFunction)sock_send, METH_VARARGS, > > > > > > When I compile this and run a simple script like the following that uses > > arecvfrom() : > > > > sock = socket.socket( socket.PF_PACKET, socket.SOCK_RAW ) > > sock.bind( ( intf, ETH_P_ALL ) ) > > > > (pkt,dontcare) = dst.arecvfrom( 500, socket.MSG_DONTWAIT ) > > > > 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@python.org > > http://mail.python.org/mailman/listinfo/python-dev > > Unsubscribe: > > http://mail.python.org/mailman/options/python-dev/guido%40python.org > > > > > > -- > --Guido van Rossum (python.org/~guido) > -- Ani
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com