mirror of
https://github.com/python/cpython.git
synced 2025-10-26 16:27:06 +00:00
Added copious docstrings, plus two minor layout tweaks.
This commit is contained in:
parent
a4289a79f8
commit
82a5c66a51
1 changed files with 307 additions and 37 deletions
|
|
@ -580,6 +580,13 @@ BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char accept_doc[] =
|
||||||
|
"accept() -> (socket object, address info)\n\
|
||||||
|
\n\
|
||||||
|
Wait for an incoming connection. Return a new socket representing the\n\
|
||||||
|
connection, and the address of the client. For IP sockets, the address\n\
|
||||||
|
info is a pair (hostaddr, port).";
|
||||||
|
|
||||||
|
|
||||||
/* s.setblocking(1 | 0) method */
|
/* s.setblocking(1 | 0) method */
|
||||||
|
|
||||||
|
|
@ -615,6 +622,12 @@ BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char setblocking_doc[] =
|
||||||
|
"setblocking(flag)\n\
|
||||||
|
\n\
|
||||||
|
Set the socket to blocking (flag is true) or non-blocking (false).\n\
|
||||||
|
This uses the FIONBIO ioctl with the O_NDELAY flag.";
|
||||||
|
|
||||||
|
|
||||||
/* s.setsockopt() method.
|
/* s.setsockopt() method.
|
||||||
With an integer third argument, sets an integer option.
|
With an integer third argument, sets an integer option.
|
||||||
|
|
@ -648,6 +661,12 @@ BUILD_FUNC_DEF_2(PySocketSock_setsockopt,PySocketSockObject *,s, PyObject *,args
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char setsockopt_doc[] =
|
||||||
|
"setsockopt(level, option, value)\n\
|
||||||
|
\n\
|
||||||
|
Set a socket option. See the Unix manual for level and option.\n\
|
||||||
|
The value argument can either be an integer or a string.";
|
||||||
|
|
||||||
|
|
||||||
/* s.getsockopt() method.
|
/* s.getsockopt() method.
|
||||||
With two arguments, retrieves an integer option.
|
With two arguments, retrieves an integer option.
|
||||||
|
|
@ -693,6 +712,13 @@ BUILD_FUNC_DEF_2(PySocketSock_getsockopt,PySocketSockObject *,s, PyObject *,args
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char getsockopt_doc[] =
|
||||||
|
"getsockopt(level, option[, buffersize]) -> value\n\
|
||||||
|
\n\
|
||||||
|
Get a socket option. See the Unix manual for level and option.\n\
|
||||||
|
If a nonzero buffersize argument is given, the return value is a\n\
|
||||||
|
string of that length; otherwise it is an integer.";
|
||||||
|
|
||||||
|
|
||||||
/* s.bind(sockaddr) method */
|
/* s.bind(sockaddr) method */
|
||||||
|
|
||||||
|
|
@ -713,6 +739,12 @@ BUILD_FUNC_DEF_2(PySocketSock_bind,PySocketSockObject *,s, PyObject *,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char bind_doc[] =
|
||||||
|
"bind(address)\n\
|
||||||
|
\n\
|
||||||
|
Bind the socket to a local address. For IP sockets, the address is a\n\
|
||||||
|
pair (host, port); the host must refer to the local host.";
|
||||||
|
|
||||||
|
|
||||||
/* s.close() method.
|
/* s.close() method.
|
||||||
Set the file descriptor to -1 so operations tried subsequently
|
Set the file descriptor to -1 so operations tried subsequently
|
||||||
|
|
@ -733,6 +765,11 @@ BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char close_doc[] =
|
||||||
|
"close()\n\
|
||||||
|
\n\
|
||||||
|
Close the socket. It cannot be used after this call.";
|
||||||
|
|
||||||
|
|
||||||
/* s.connect(sockaddr) method */
|
/* s.connect(sockaddr) method */
|
||||||
|
|
||||||
|
|
@ -753,6 +790,12 @@ BUILD_FUNC_DEF_2(PySocketSock_connect,PySocketSockObject *,s, PyObject *,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char connect_doc[] =
|
||||||
|
"connect(address)\n\
|
||||||
|
\n\
|
||||||
|
Connect the socket to a remote address. For IP sockets, the address\n\
|
||||||
|
is a pair (host, port).";
|
||||||
|
|
||||||
|
|
||||||
/* s.connect_ex(sockaddr) method */
|
/* s.connect_ex(sockaddr) method */
|
||||||
|
|
||||||
|
|
@ -772,6 +815,12 @@ BUILD_FUNC_DEF_2(PySocketSock_connect_ex,PySocketSockObject *,s, PyObject *,args
|
||||||
return PyInt_FromLong((long) res);
|
return PyInt_FromLong((long) res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char connect_ex_doc[] =
|
||||||
|
"connect_ex(address)\n\
|
||||||
|
\n\
|
||||||
|
This is like connect(address), but returns an error code (the errno value)\n\
|
||||||
|
instead of raising an exception when an error occurs.";
|
||||||
|
|
||||||
|
|
||||||
/* s.fileno() method */
|
/* s.fileno() method */
|
||||||
|
|
||||||
|
|
@ -783,6 +832,11 @@ BUILD_FUNC_DEF_2(PySocketSock_fileno,PySocketSockObject *,s, PyObject *,args)
|
||||||
return PyInt_FromLong((long) s->sock_fd);
|
return PyInt_FromLong((long) s->sock_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char fileno_doc[] =
|
||||||
|
"fileno() -> integer\n\
|
||||||
|
\n\
|
||||||
|
Return the integer file descriptor of the socket.";
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
/* s.dup() method */
|
/* s.dup() method */
|
||||||
|
|
@ -805,6 +859,12 @@ BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args)
|
||||||
close(newfd);
|
close(newfd);
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char dup_doc[] =
|
||||||
|
"dup() -> socket object\n\
|
||||||
|
\n\
|
||||||
|
Return a new socket object connected to the same system resource.";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -828,6 +888,12 @@ BUILD_FUNC_DEF_2(PySocketSock_getsockname,PySocketSockObject *,s, PyObject *,arg
|
||||||
return makesockaddr((struct sockaddr *) addrbuf, addrlen);
|
return makesockaddr((struct sockaddr *) addrbuf, addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char getsockname_doc[] =
|
||||||
|
"getsockname() -> address info\n\
|
||||||
|
\n\
|
||||||
|
Return the address of the local endpoint. For IP sockets, the address\n\
|
||||||
|
info is a pair (hostaddr, port).";
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */
|
#ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */
|
||||||
/* s.getpeername() method */
|
/* s.getpeername() method */
|
||||||
|
|
@ -848,6 +914,13 @@ BUILD_FUNC_DEF_2(PySocketSock_getpeername,PySocketSockObject *,s, PyObject *,arg
|
||||||
return PySocket_Err();
|
return PySocket_Err();
|
||||||
return makesockaddr((struct sockaddr *) addrbuf, addrlen);
|
return makesockaddr((struct sockaddr *) addrbuf, addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char getpeername_doc[] =
|
||||||
|
"getpeername() -> address info\n\
|
||||||
|
\n\
|
||||||
|
Return the address of the remote endpoint. For IP sockets, the address\n\
|
||||||
|
info is a pair (hostaddr, port).";
|
||||||
|
|
||||||
#endif /* HAVE_GETPEERNAME */
|
#endif /* HAVE_GETPEERNAME */
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -871,6 +944,14 @@ BUILD_FUNC_DEF_2(PySocketSock_listen,PySocketSockObject *,s, PyObject *,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char listen_doc[] =
|
||||||
|
"listen(backlog)\n\
|
||||||
|
\n\
|
||||||
|
Enable a server to accept connections. The backlog argument must be at\n\
|
||||||
|
least 1; it specifies the number of unaccepted connection that the system\n\
|
||||||
|
will allow before refusing new connections.";
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
/* s.makefile(mode) method.
|
/* s.makefile(mode) method.
|
||||||
Create a new open file object referring to a dupped version of
|
Create a new open file object referring to a dupped version of
|
||||||
|
|
@ -892,12 +973,12 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
|
||||||
if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
|
if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
|
||||||
return NULL;
|
return NULL;
|
||||||
#ifdef MS_WIN32
|
#ifdef MS_WIN32
|
||||||
if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) ||
|
if (((fd = _open_osfhandle(s->sock_fd, _O_BINARY)) < 0) ||
|
||||||
((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) {
|
((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL))
|
||||||
#else
|
#else
|
||||||
if ((fd = dup(s->sock_fd)) < 0 ||
|
if ((fd = dup(s->sock_fd)) < 0 || (fp = fdopen(fd, mode)) == NULL)
|
||||||
(fp = fdopen(fd, mode)) == NULL) {
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
close(fd);
|
||||||
return PySocket_Err();
|
return PySocket_Err();
|
||||||
|
|
@ -907,8 +988,16 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
|
||||||
PyFile_SetBufSize(f, bufsize);
|
PyFile_SetBufSize(f, bufsize);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char makefile_doc[] =
|
||||||
|
"makefile([mode[, buffersize]]) -> file object\n\
|
||||||
|
\n\
|
||||||
|
Return a regular file object corresponding to the socket.\n\
|
||||||
|
The mode and buffersize arguments are as for the built-in open() function.";
|
||||||
|
|
||||||
#endif /* NO_DUP */
|
#endif /* NO_DUP */
|
||||||
|
|
||||||
|
|
||||||
/* s.recv(nbytes [,flags]) method */
|
/* s.recv(nbytes [,flags]) method */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
@ -933,6 +1022,14 @@ BUILD_FUNC_DEF_2(PySocketSock_recv,PySocketSockObject *,s, PyObject *,args)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char recv_doc[] =
|
||||||
|
"recv(buffersize[, flags]) -> data\n\
|
||||||
|
\n\
|
||||||
|
Receive up to buffersize bytes from the socket. For the optional flags\n\
|
||||||
|
argument, see the Unix manual. When no data is available, block until\n\
|
||||||
|
at least one byte is available or until the remote end is closed. When\n\
|
||||||
|
the remote end is closed and all data is read, return the empty string.";
|
||||||
|
|
||||||
|
|
||||||
/* s.recvfrom(nbytes [,flags]) method */
|
/* s.recvfrom(nbytes [,flags]) method */
|
||||||
|
|
||||||
|
|
@ -982,6 +1079,11 @@ BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char recvfrom_doc[] =
|
||||||
|
"recvfrom(buffersize[, flags]) -> (data, address info)\n\
|
||||||
|
\n\
|
||||||
|
Like recv(buffersize, flags) but also return the sender's address info.";
|
||||||
|
|
||||||
|
|
||||||
/* s.send(data [,flags]) method */
|
/* s.send(data [,flags]) method */
|
||||||
|
|
||||||
|
|
@ -1000,6 +1102,12 @@ BUILD_FUNC_DEF_2(PySocketSock_send,PySocketSockObject *,s, PyObject *,args)
|
||||||
return PyInt_FromLong((long)n);
|
return PyInt_FromLong((long)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char send_doc[] =
|
||||||
|
"send(data[, flags])\n\
|
||||||
|
\n\
|
||||||
|
Send a data string to the socket. For the optional flags\n\
|
||||||
|
argument, see the Unix manual.";
|
||||||
|
|
||||||
|
|
||||||
/* s.sendto(data, [flags,] sockaddr) method */
|
/* s.sendto(data, [flags,] sockaddr) method */
|
||||||
|
|
||||||
|
|
@ -1026,6 +1134,12 @@ BUILD_FUNC_DEF_2(PySocketSock_sendto,PySocketSockObject *,s, PyObject *,args)
|
||||||
return PyInt_FromLong((long)n);
|
return PyInt_FromLong((long)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char sendto_doc[] =
|
||||||
|
"sendto(data[, flags], address)\n\
|
||||||
|
\n\
|
||||||
|
Like send(data, flags) but allows specifying the destination address.\n\
|
||||||
|
For IP sockets, the address is a pair (hostaddr, port).";
|
||||||
|
|
||||||
|
|
||||||
/* s.shutdown(how) method */
|
/* s.shutdown(how) method */
|
||||||
|
|
||||||
|
|
@ -1045,35 +1159,60 @@ BUILD_FUNC_DEF_2(PySocketSock_shutdown,PySocketSockObject *,s, PyObject *,args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char shutdown_doc[] =
|
||||||
|
"shutdown(flag)\n\
|
||||||
|
\n\
|
||||||
|
Shut down the reading side of the socket (flag == 0), the writing side\n\
|
||||||
|
of the socket (flag == 1), or both ends (flag == 2).";
|
||||||
|
|
||||||
|
|
||||||
/* List of methods for socket objects */
|
/* List of methods for socket objects */
|
||||||
|
|
||||||
static PyMethodDef PySocketSock_methods[] = {
|
static PyMethodDef PySocketSock_methods[] = {
|
||||||
{"accept", (PyCFunction)PySocketSock_accept},
|
{"accept", (PyCFunction)PySocketSock_accept, 0,
|
||||||
{"setblocking", (PyCFunction)PySocketSock_setblocking},
|
accept_doc},
|
||||||
{"setsockopt", (PyCFunction)PySocketSock_setsockopt},
|
{"bind", (PyCFunction)PySocketSock_bind, 0,
|
||||||
{"getsockopt", (PyCFunction)PySocketSock_getsockopt, 1},
|
bind_doc},
|
||||||
{"bind", (PyCFunction)PySocketSock_bind},
|
{"close", (PyCFunction)PySocketSock_close, 0,
|
||||||
{"close", (PyCFunction)PySocketSock_close},
|
close_doc},
|
||||||
{"connect", (PyCFunction)PySocketSock_connect},
|
{"connect", (PyCFunction)PySocketSock_connect, 0,
|
||||||
{"connect_ex", (PyCFunction)PySocketSock_connect_ex},
|
connect_doc},
|
||||||
{"fileno", (PyCFunction)PySocketSock_fileno},
|
{"connect_ex", (PyCFunction)PySocketSock_connect_ex, 0,
|
||||||
|
connect_ex_doc},
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
{"dup", (PyCFunction)PySocketSock_dup},
|
{"dup", (PyCFunction)PySocketSock_dup, 0,
|
||||||
|
dup_doc},
|
||||||
#endif
|
#endif
|
||||||
{"getsockname", (PyCFunction)PySocketSock_getsockname},
|
{"fileno", (PyCFunction)PySocketSock_fileno, 0,
|
||||||
|
fileno_doc},
|
||||||
#ifdef HAVE_GETPEERNAME
|
#ifdef HAVE_GETPEERNAME
|
||||||
{"getpeername", (PyCFunction)PySocketSock_getpeername},
|
{"getpeername", (PyCFunction)PySocketSock_getpeername, 0,
|
||||||
|
getpeername_doc},
|
||||||
#endif
|
#endif
|
||||||
{"listen", (PyCFunction)PySocketSock_listen},
|
{"getsockname", (PyCFunction)PySocketSock_getsockname, 0,
|
||||||
|
getsockname_doc},
|
||||||
|
{"getsockopt", (PyCFunction)PySocketSock_getsockopt, 1,
|
||||||
|
getsockopt_doc},
|
||||||
|
{"listen", (PyCFunction)PySocketSock_listen, 0,
|
||||||
|
listen_doc},
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
{"makefile", (PyCFunction)PySocketSock_makefile, 1},
|
{"makefile", (PyCFunction)PySocketSock_makefile, 1,
|
||||||
|
makefile_doc},
|
||||||
#endif
|
#endif
|
||||||
{"recv", (PyCFunction)PySocketSock_recv, 1},
|
{"recv", (PyCFunction)PySocketSock_recv, 1,
|
||||||
{"recvfrom", (PyCFunction)PySocketSock_recvfrom, 1},
|
recv_doc},
|
||||||
{"send", (PyCFunction)PySocketSock_send, 1},
|
{"recvfrom", (PyCFunction)PySocketSock_recvfrom, 1,
|
||||||
{"sendto", (PyCFunction)PySocketSock_sendto},
|
recvfrom_doc},
|
||||||
{"shutdown", (PyCFunction)PySocketSock_shutdown},
|
{"send", (PyCFunction)PySocketSock_send, 1,
|
||||||
|
send_doc},
|
||||||
|
{"sendto", (PyCFunction)PySocketSock_sendto, 0,
|
||||||
|
sendto_doc},
|
||||||
|
{"setblocking", (PyCFunction)PySocketSock_setblocking, 0,
|
||||||
|
setblocking_doc},
|
||||||
|
{"setsockopt", (PyCFunction)PySocketSock_setsockopt, 0,
|
||||||
|
setsockopt_doc},
|
||||||
|
{"shutdown", (PyCFunction)PySocketSock_shutdown, 0,
|
||||||
|
shutdown_doc},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1148,6 +1287,11 @@ BUILD_FUNC_DEF_2(PySocket_gethostname,PyObject *,self, PyObject *,args)
|
||||||
return PyString_FromString(buf);
|
return PyString_FromString(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char gethostname_doc[] =
|
||||||
|
"gethostname() -> string\n\
|
||||||
|
\n\
|
||||||
|
Return the current host name.";
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to gethostbyname(name). */
|
/* Python interface to gethostbyname(name). */
|
||||||
|
|
||||||
|
|
@ -1164,6 +1308,12 @@ BUILD_FUNC_DEF_2(PySocket_gethostbyname,PyObject *,self, PyObject *,args)
|
||||||
return makeipaddr(&addrbuf);
|
return makeipaddr(&addrbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char gethostbyname_doc[] =
|
||||||
|
"gethostbyname(host) -> address\n\
|
||||||
|
\n\
|
||||||
|
Return the IP address (a string of the form '255.255.255.255') for a host.";
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to gethostbyaddr(IP). */
|
/* Python interface to gethostbyaddr(IP). */
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
|
|
@ -1249,6 +1399,12 @@ BUILD_FUNC_DEF_2(PySocket_gethostbyaddr,PyObject *,self, PyObject *, args)
|
||||||
return rtn_tuple;
|
return rtn_tuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char gethostbyaddr_doc[] =
|
||||||
|
"gethostbyaddr(host) -> (name, aliaslist, addresslist)\n\
|
||||||
|
\n\
|
||||||
|
Return the true host name, a list of aliases, and a list of IP addresses,\n\
|
||||||
|
for a host. The host argument is a string giving a host name or IP number.";
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to getservbyname(name).
|
/* Python interface to getservbyname(name).
|
||||||
This only returns the port number, since the other info is already
|
This only returns the port number, since the other info is already
|
||||||
|
|
@ -1272,6 +1428,12 @@ BUILD_FUNC_DEF_2(PySocket_getservbyname,PyObject *,self, PyObject *,args)
|
||||||
return PyInt_FromLong((long) ntohs(sp->s_port));
|
return PyInt_FromLong((long) ntohs(sp->s_port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char getservbyname_doc[] =
|
||||||
|
"getservbyname(servicename, protocolname) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Return a port number from a service name and protocol name.\n\
|
||||||
|
The protocol name should be 'tcp' or 'udp'.";
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to getprotobyname(name).
|
/* Python interface to getprotobyname(name).
|
||||||
This only returns the protocol number, since the other info is
|
This only returns the protocol number, since the other info is
|
||||||
|
|
@ -1295,6 +1457,11 @@ BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args)
|
||||||
return PyInt_FromLong((long) sp->p_proto);
|
return PyInt_FromLong((long) sp->p_proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char getprotobyname_doc[] =
|
||||||
|
"getprotobyname(name) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Return the protocol number for the named protocol. (Rarely used.)";
|
||||||
|
|
||||||
|
|
||||||
/* Python interface to socket(family, type, proto).
|
/* Python interface to socket(family, type, proto).
|
||||||
The third (protocol) argument is optional.
|
The third (protocol) argument is optional.
|
||||||
|
|
@ -1335,6 +1502,16 @@ BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
|
||||||
return (PyObject *) s;
|
return (PyObject *) s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char socket_doc[] =
|
||||||
|
"socket(family, type[, proto]) -> socket object\n\
|
||||||
|
\n\
|
||||||
|
Open a socket of the given type. The family argument specifies the\n\
|
||||||
|
address family; it is normally AF_INET, sometimes AF_UNIX.\n\
|
||||||
|
The type argument specifies whether this is a stream (SOCK_STREAM)\n\
|
||||||
|
or datagram (SOCK_DGRAM) socket. The protocol argument defaults to 0,\n\
|
||||||
|
specifying the default protocol.";
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
/* Create a socket object from a numeric file description.
|
/* Create a socket object from a numeric file description.
|
||||||
Useful e.g. if stdin is a socket.
|
Useful e.g. if stdin is a socket.
|
||||||
|
|
@ -1360,8 +1537,16 @@ BUILD_FUNC_DEF_2(PySocket_fromfd,PyObject *,self, PyObject *,args)
|
||||||
#endif
|
#endif
|
||||||
return (PyObject *) s;
|
return (PyObject *) s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char fromfd_doc[] =
|
||||||
|
"fromfd(fd, family, type[, proto]) -> socket object\n\
|
||||||
|
\n\
|
||||||
|
Create a socket object from the given file descriptor.\n\
|
||||||
|
The remaining arguments are the same as for socket().";
|
||||||
|
|
||||||
#endif /* NO_DUP */
|
#endif /* NO_DUP */
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
BUILD_FUNC_DEF_2(PySocket_ntohs, PyObject *, self, PyObject *, args)
|
BUILD_FUNC_DEF_2(PySocket_ntohs, PyObject *, self, PyObject *, args)
|
||||||
{
|
{
|
||||||
|
|
@ -1374,6 +1559,12 @@ BUILD_FUNC_DEF_2(PySocket_ntohs, PyObject *, self, PyObject *, args)
|
||||||
return PyInt_FromLong(x2);
|
return PyInt_FromLong(x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char ntohs_doc[] =
|
||||||
|
"ntohs(integer) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Convert a 16-bit integer from network to host byte order.";
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
BUILD_FUNC_DEF_2(PySocket_ntohl, PyObject *, self, PyObject *, args)
|
BUILD_FUNC_DEF_2(PySocket_ntohl, PyObject *, self, PyObject *, args)
|
||||||
{
|
{
|
||||||
|
|
@ -1386,6 +1577,12 @@ BUILD_FUNC_DEF_2(PySocket_ntohl, PyObject *, self, PyObject *, args)
|
||||||
return PyInt_FromLong(x2);
|
return PyInt_FromLong(x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char ntohl_doc[] =
|
||||||
|
"ntohl(integer) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Convert a 32-bit integer from network to host byte order.";
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
BUILD_FUNC_DEF_2(PySocket_htons, PyObject *, self, PyObject *, args)
|
BUILD_FUNC_DEF_2(PySocket_htons, PyObject *, self, PyObject *, args)
|
||||||
{
|
{
|
||||||
|
|
@ -1398,6 +1595,12 @@ BUILD_FUNC_DEF_2(PySocket_htons, PyObject *, self, PyObject *, args)
|
||||||
return PyInt_FromLong(x2);
|
return PyInt_FromLong(x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char htons_doc[] =
|
||||||
|
"htons(integer) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Convert a 16-bit integer from host to network byte order.";
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
BUILD_FUNC_DEF_2(PySocket_htonl, PyObject *, self, PyObject *, args)
|
BUILD_FUNC_DEF_2(PySocket_htonl, PyObject *, self, PyObject *, args)
|
||||||
{
|
{
|
||||||
|
|
@ -1410,22 +1613,28 @@ BUILD_FUNC_DEF_2(PySocket_htonl, PyObject *, self, PyObject *, args)
|
||||||
return PyInt_FromLong(x2);
|
return PyInt_FromLong(x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char htonl_doc[] =
|
||||||
|
"htonl(integer) -> integer\n\
|
||||||
|
\n\
|
||||||
|
Convert a 32-bit integer from host to network byte order.";
|
||||||
|
|
||||||
|
|
||||||
/* List of functions exported by this module. */
|
/* List of functions exported by this module. */
|
||||||
|
|
||||||
static PyMethodDef PySocket_methods[] = {
|
static PyMethodDef PySocket_methods[] = {
|
||||||
{"gethostbyname", PySocket_gethostbyname},
|
{"gethostbyname", PySocket_gethostbyname, 0, gethostbyname_doc},
|
||||||
{"gethostbyaddr", PySocket_gethostbyaddr},
|
{"gethostbyaddr", PySocket_gethostbyaddr, 0, gethostbyaddr_doc},
|
||||||
{"gethostname", PySocket_gethostname},
|
{"gethostname", PySocket_gethostname, 0, gethostname_doc},
|
||||||
{"getservbyname", PySocket_getservbyname},
|
{"getservbyname", PySocket_getservbyname, 0, getservbyname_doc},
|
||||||
{"getprotobyname", PySocket_getprotobyname},
|
{"getprotobyname", PySocket_getprotobyname, 0,getprotobyname_doc},
|
||||||
{"socket", PySocket_socket, 1},
|
{"socket", PySocket_socket, 1, socket_doc},
|
||||||
#ifndef NO_DUP
|
#ifndef NO_DUP
|
||||||
{"fromfd", PySocket_fromfd, 1},
|
{"fromfd", PySocket_fromfd, 1, fromfd_doc},
|
||||||
#endif
|
#endif
|
||||||
{"ntohs", PySocket_ntohs},
|
{"ntohs", PySocket_ntohs, 0, ntohs_doc},
|
||||||
{"ntohl", PySocket_ntohl},
|
{"ntohl", PySocket_ntohl, 0, ntohl_doc},
|
||||||
{"htons", PySocket_htons},
|
{"htons", PySocket_htons, 0, htons_doc},
|
||||||
{"htonl", PySocket_htonl},
|
{"htonl", PySocket_htonl, 0, htonl_doc},
|
||||||
{NULL, NULL} /* Sentinel */
|
{NULL, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1534,6 +1743,66 @@ OS2init()
|
||||||
* operating system's filesystem layer.
|
* operating system's filesystem layer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static char module_doc[] =
|
||||||
|
"This module provides socket operations and some related functions.\n\
|
||||||
|
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.\n\
|
||||||
|
On other systems, it only supports IP.\n\
|
||||||
|
\n\
|
||||||
|
Functions:\n\
|
||||||
|
\n\
|
||||||
|
socket() -- create a new socket object\n\
|
||||||
|
fromfd() -- create a socket object from an open file descriptor (*)\n\
|
||||||
|
gethostname() -- return the current hostname\n\
|
||||||
|
gethostbyname() -- map a hostname to its IP number\n\
|
||||||
|
gethostbyaddr() -- map an IP number or hostname to DNS info\n\
|
||||||
|
getservbyname() -- map a service name and a protocol name to a port number\n\
|
||||||
|
getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number\n\
|
||||||
|
ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order\n\
|
||||||
|
htons(), htonl() -- convert 16, 32 bit int from host to network byte order\n\
|
||||||
|
\n\
|
||||||
|
(*) not available on all platforms!)\n\
|
||||||
|
\n\
|
||||||
|
Special objects:\n\
|
||||||
|
\n\
|
||||||
|
SocketType -- type object for socket objects\n\
|
||||||
|
error -- exception raised for I/O errors\n\
|
||||||
|
\n\
|
||||||
|
Integer constants:\n\
|
||||||
|
\n\
|
||||||
|
AF_INET, AF_UNIX -- socket domains (first argument to socket() call)\n\
|
||||||
|
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)\n\
|
||||||
|
\n\
|
||||||
|
Many other constants may be defined; these may be used in calls to\n\
|
||||||
|
the setsockopt() and getsockopt() methods.\n\
|
||||||
|
";
|
||||||
|
|
||||||
|
static char sockettype_doc[] =
|
||||||
|
"A socket represents one endpoint of a network connection.\n\
|
||||||
|
\n\
|
||||||
|
Methods:\n\
|
||||||
|
\n\
|
||||||
|
accept() -- accept a connection, returning new socket and client address\n\
|
||||||
|
bind() -- bind the socket to a local address\n\
|
||||||
|
close() -- close the socket\n\
|
||||||
|
connect() -- connect the socket to a remote address\n\
|
||||||
|
connect_ex() -- connect, return an error code instead of an exception \n\
|
||||||
|
dup() -- return a new socket object identical to the current one (*)\n\
|
||||||
|
fileno() -- return underlying file descriptor\n\
|
||||||
|
getpeername() -- return remote address (*)\n\
|
||||||
|
getsockname() -- return local address\n\
|
||||||
|
getsockopt() -- get socket options\n\
|
||||||
|
listen() -- start listening for incoming connections\n\
|
||||||
|
makefile() -- return a file object corresponding tot the socket (*)\n\
|
||||||
|
recv() -- receive data\n\
|
||||||
|
recvfrom() -- receive data and sender's address\n\
|
||||||
|
send() -- send data\n\
|
||||||
|
sendto() -- send data to a given address\n\
|
||||||
|
setblocking() -- set or clear the blocking I/O flag\n\
|
||||||
|
setsockopt() -- set socket options\n\
|
||||||
|
shutdown() -- shut down traffic in one or both directions\n\
|
||||||
|
\n\
|
||||||
|
(*) not available on all platforms!)";
|
||||||
|
|
||||||
void
|
void
|
||||||
#if defined(MS_WINDOWS) || defined(PYOS_OS2)
|
#if defined(MS_WINDOWS) || defined(PYOS_OS2)
|
||||||
init_socket()
|
init_socket()
|
||||||
|
|
@ -1545,14 +1814,14 @@ initsocket()
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
if (!NTinit())
|
if (!NTinit())
|
||||||
return;
|
return;
|
||||||
m = Py_InitModule("_socket", PySocket_methods);
|
m = Py_InitModule3("_socket", PySocket_methods, module_doc);
|
||||||
#else
|
#else
|
||||||
#if defined(__TOS_OS2__)
|
#if defined(__TOS_OS2__)
|
||||||
if (!OS2init())
|
if (!OS2init())
|
||||||
return;
|
return;
|
||||||
m = Py_InitModule("_socket", PySocket_methods);
|
m = Py_InitModule3("_socket", PySocket_methods, module_doc);
|
||||||
#else
|
#else
|
||||||
m = Py_InitModule("socket", PySocket_methods);
|
m = Py_InitModule3("socket", PySocket_methods, module_doc);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
|
|
@ -1561,6 +1830,7 @@ initsocket()
|
||||||
return;
|
return;
|
||||||
PyDict_SetItemString(d, "error", PySocket_Error);
|
PyDict_SetItemString(d, "error", PySocket_Error);
|
||||||
PySocketSock_Type.ob_type = &PyType_Type;
|
PySocketSock_Type.ob_type = &PyType_Type;
|
||||||
|
PySocketSock_Type.tp_doc = sockettype_doc;
|
||||||
Py_INCREF(&PySocketSock_Type);
|
Py_INCREF(&PySocketSock_Type);
|
||||||
if (PyDict_SetItemString(d, "SocketType",
|
if (PyDict_SetItemString(d, "SocketType",
|
||||||
(PyObject *)&PySocketSock_Type) != 0)
|
(PyObject *)&PySocketSock_Type) != 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue