[Python-Dev] Getting socket information from socket objects
Guido van Rossum
guido at python.org
Fri Nov 14 13:14:01 EST 2003
> It appears that the easiest way to retrieve family/type/protocol
> fields from socket objects is this:
> def getsockinfo(sock):
> s = `sock._sock`
> sp = s[1:-1].split(",")[1:]
> g = {}
> d = {}
> for i in sp:
> exec i.strip() in g, d
> return (d["family"], d["type"], d["protocol"])
> Wouldn't it be nice to have accessors for these fields? My
> particular use-case is Windows-specific (IO completion port
> proactor), so winsock API provides this, but I'd rather avoid that
> crud.
Sounds like a good idea. Upload your patches to SF!
> Also, exporting getsockaddrarg in socketmodule.c CAPI would be
> useful, although the only use I can think of is implementing
> Windows' ConnectEx (which I am doing)
I'm unclear on what you propose here; again, a working patch on SF
showing what you propose would help.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list