UPDATED Questions:
Where does the socket object really get created? I found this on line 4188 in socketmodule.c , but it looks like it's called sock_new not socket?
static PyObject *sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Is there any agreement to find out where a module such as socketmodule.c is imported? In other words, when I see "from _socket import", who do I know this imports (without looking at the entire repository)?
ORIGINAL:
sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
I am trying to understand how this code works specifically, how / where Python actually calls the OS function call in socket ():
class _socketobject(object): __doc__ = _realsocket.__doc__ __slots__ = ["_sock", "__weakref__"] + list(_delegate_methods) def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None): if _sock is None: _sock = _realsocket(family, type, proto) self._sock = _sock for method in _delegate_methods: setattr(self, method, getattr(_sock, method))
When I look at BSD sockets on Wikipedia, I see this example, which makes sense because the socket function is defined under types.h. In the above example, I see a realsocket call that looks like an OS function call, but I don't define it anywhere (I donβt see anything about sockets in the Python27 / include headers).
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { struct sockaddr_in stSockAddr; int SocketFD = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
source share