[Python-checkins] python/dist/src/Modules socketmodule.c,1.220,1.221
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Thu, 06 Jun 2002 19:08:37 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv22693
Modified Files:
socketmodule.c
Log Message:
Whitespace normalization, folding long lines, uniform comment
delimiters. Also repaired some docstrings and comments.
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.220
retrieving revision 1.221
diff -C2 -d -r1.220 -r1.221
*** socketmodule.c 7 Jun 2002 01:42:47 -0000 1.220
--- socketmodule.c 7 Jun 2002 02:08:35 -0000 1.221
***************
*** 107,111 ****
#endif
! #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS)
# define USE_GETHOSTBYNAME_LOCK
#endif
--- 107,112 ----
#endif
! #if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && \
! !defined(MS_WINDOWS)
# define USE_GETHOSTBYNAME_LOCK
#endif
***************
*** 185,189 ****
#ifndef HAVE_INET_PTON
! int inet_pton (int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#endif
--- 186,190 ----
#ifndef HAVE_INET_PTON
! int inet_pton(int af, const char *src, void *dst);
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#endif
***************
*** 219,224 ****
#ifdef MS_WIN32
! # define EAFNOSUPPORT WSAEAFNOSUPPORT
! # define snprintf _snprintf
#endif
--- 220,225 ----
#ifdef MS_WIN32
! #define EAFNOSUPPORT WSAEAFNOSUPPORT
! #define snprintf _snprintf
#endif
***************
*** 261,331 ****
#ifdef MS_WINDOWS
int err_no = WSAGetLastError();
if (err_no) {
- static struct { int no; const char *msg; } *msgp, msgs[] = {
- { WSAEINTR, "Interrupted system call" },
- { WSAEBADF, "Bad file descriptor" },
- { WSAEACCES, "Permission denied" },
- { WSAEFAULT, "Bad address" },
- { WSAEINVAL, "Invalid argument" },
- { WSAEMFILE, "Too many open files" },
- { WSAEWOULDBLOCK,
- "The socket operation could not complete "
- "without blocking" },
- { WSAEINPROGRESS, "Operation now in progress" },
- { WSAEALREADY, "Operation already in progress" },
- { WSAENOTSOCK, "Socket operation on non-socket" },
- { WSAEDESTADDRREQ, "Destination address required" },
- { WSAEMSGSIZE, "Message too long" },
- { WSAEPROTOTYPE, "Protocol wrong type for socket" },
- { WSAENOPROTOOPT, "Protocol not available" },
- { WSAEPROTONOSUPPORT, "Protocol not supported" },
- { WSAESOCKTNOSUPPORT, "Socket type not supported" },
- { WSAEOPNOTSUPP, "Operation not supported" },
- { WSAEPFNOSUPPORT, "Protocol family not supported" },
- { WSAEAFNOSUPPORT, "Address family not supported" },
- { WSAEADDRINUSE, "Address already in use" },
- { WSAEADDRNOTAVAIL,
- "Can't assign requested address" },
- { WSAENETDOWN, "Network is down" },
- { WSAENETUNREACH, "Network is unreachable" },
- { WSAENETRESET,
- "Network dropped connection on reset" },
- { WSAECONNABORTED,
- "Software caused connection abort" },
- { WSAECONNRESET, "Connection reset by peer" },
- { WSAENOBUFS, "No buffer space available" },
- { WSAEISCONN, "Socket is already connected" },
- { WSAENOTCONN, "Socket is not connected" },
- { WSAESHUTDOWN, "Can't send after socket shutdown" },
- { WSAETOOMANYREFS,
- "Too many references: can't splice" },
- { WSAETIMEDOUT, "Operation timed out" },
- { WSAECONNREFUSED, "Connection refused" },
- { WSAELOOP, "Too many levels of symbolic links" },
- { WSAENAMETOOLONG, "File name too long" },
- { WSAEHOSTDOWN, "Host is down" },
- { WSAEHOSTUNREACH, "No route to host" },
- { WSAENOTEMPTY, "Directory not empty" },
- { WSAEPROCLIM, "Too many processes" },
- { WSAEUSERS, "Too many users" },
- { WSAEDQUOT, "Disc quota exceeded" },
- { WSAESTALE, "Stale NFS file handle" },
- { WSAEREMOTE, "Too many levels of remote in path" },
- { WSASYSNOTREADY,
- "Network subsystem is unvailable" },
- { WSAVERNOTSUPPORTED,
- "WinSock version is not supported" },
- { WSANOTINITIALISED,
- "Successful WSAStartup() not yet performed" },
- { WSAEDISCON, "Graceful shutdown in progress" },
- /* Resolver errors */
- { WSAHOST_NOT_FOUND, "No such host is known" },
- { WSATRY_AGAIN, "Host not found, or server failed" },
- { WSANO_RECOVERY,
- "Unexpected server error encountered" },
- { WSANO_DATA, "Valid name without requested data" },
- { WSANO_ADDRESS, "No address, look for MX record" },
- { 0, NULL }
- };
PyObject *v;
const char *msg = "winsock error";
--- 262,328 ----
#ifdef MS_WINDOWS
int err_no = WSAGetLastError();
+ static struct {
+ int no;
+ const char *msg;
+ } *msgp, msgs[] = {
+ {WSAEINTR, "Interrupted system call"},
+ {WSAEBADF, "Bad file descriptor"},
+ {WSAEACCES, "Permission denied"},
+ {WSAEFAULT, "Bad address"},
+ {WSAEINVAL, "Invalid argument"},
+ {WSAEMFILE, "Too many open files"},
+ {WSAEWOULDBLOCK,
+ "The socket operation could not complete "
+ "without blocking"},
+ {WSAEINPROGRESS, "Operation now in progress"},
+ {WSAEALREADY, "Operation already in progress"},
+ {WSAENOTSOCK, "Socket operation on non-socket"},
+ {WSAEDESTADDRREQ, "Destination address required"},
+ {WSAEMSGSIZE, "Message too long"},
+ {WSAEPROTOTYPE, "Protocol wrong type for socket"},
+ {WSAENOPROTOOPT, "Protocol not available"},
+ {WSAEPROTONOSUPPORT, "Protocol not supported"},
+ {WSAESOCKTNOSUPPORT, "Socket type not supported"},
+ {WSAEOPNOTSUPP, "Operation not supported"},
+ {WSAEPFNOSUPPORT, "Protocol family not supported"},
+ {WSAEAFNOSUPPORT, "Address family not supported"},
+ {WSAEADDRINUSE, "Address already in use"},
+ {WSAEADDRNOTAVAIL, "Can't assign requested address"},
+ {WSAENETDOWN, "Network is down"},
+ {WSAENETUNREACH, "Network is unreachable"},
+ {WSAENETRESET, "Network dropped connection on reset"},
+ {WSAECONNABORTED, "Software caused connection abort"},
+ {WSAECONNRESET, "Connection reset by peer"},
+ {WSAENOBUFS, "No buffer space available"},
+ {WSAEISCONN, "Socket is already connected"},
+ {WSAENOTCONN, "Socket is not connected"},
+ {WSAESHUTDOWN, "Can't send after socket shutdown"},
+ {WSAETOOMANYREFS, "Too many references: can't splice"},
+ {WSAETIMEDOUT, "Operation timed out"},
+ {WSAECONNREFUSED, "Connection refused"},
+ {WSAELOOP, "Too many levels of symbolic links"},
+ {WSAENAMETOOLONG, "File name too long"},
+ {WSAEHOSTDOWN, "Host is down"},
+ {WSAEHOSTUNREACH, "No route to host"},
+ {WSAENOTEMPTY, "Directory not empty"},
+ {WSAEPROCLIM, "Too many processes"},
+ {WSAEUSERS, "Too many users"},
+ {WSAEDQUOT, "Disc quota exceeded"},
+ {WSAESTALE, "Stale NFS file handle"},
+ {WSAEREMOTE, "Too many levels of remote in path"},
+ {WSASYSNOTREADY, "Network subsystem is unvailable"},
+ {WSAVERNOTSUPPORTED, "WinSock version is not supported"},
+ {WSANOTINITIALISED,
+ "Successful WSAStartup() not yet performed"},
+ {WSAEDISCON, "Graceful shutdown in progress"},
+ /* Resolver errors */
+ {WSAHOST_NOT_FOUND, "No such host is known"},
+ {WSATRY_AGAIN, "Host not found, or server failed"},
+ {WSANO_RECOVERY, "Unexpected server error encountered"},
+ {WSANO_DATA, "Valid name without requested data"},
+ {WSANO_ADDRESS, "No address, look for MX record"},
+ {0, NULL}
+ };
if (err_no) {
PyObject *v;
const char *msg = "winsock error";
***************
*** 349,378 ****
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
! if (sock_errno() != NO_ERROR) {
! APIRET rc;
! ULONG msglen;
! char outbuf[100];
! int myerrorcode = sock_errno();
! /* Retrieve Socket-Related Error Message from MPTN.MSG File */
! rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
! myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen);
! if (rc == NO_ERROR) {
! PyObject *v;
! outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
! if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
! char *lastc = &outbuf[ strlen(outbuf)-1 ];
! while (lastc > outbuf && isspace(*lastc))
! *lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
! }
! v = Py_BuildValue("(is)", myerrorcode, outbuf);
! if (v != NULL) {
! PyErr_SetObject(PySocket_Error, v);
! Py_DECREF(v);
! }
! return NULL;
! }
! }
#endif
--- 346,381 ----
#if defined(PYOS_OS2) && !defined(PYCC_GCC)
! if (sock_errno() != NO_ERROR) {
! APIRET rc;
! ULONG msglen;
! char outbuf[100];
! int myerrorcode = sock_errno();
! /* Retrieve socket-related error message from MPTN.MSG file */
! rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
! myerrorcode - SOCBASEERR + 26,
! "mptn.msg",
! &msglen);
! if (rc == NO_ERROR) {
! PyObject *v;
! /* OS/2 doesn't guarantee a terminator */
! outbuf[msglen] = '\0';
! if (strlen(outbuf) > 0) {
! /* If non-empty msg, trim CRLF */
! char *lastc = &outbuf[ strlen(outbuf)-1 ];
! while (lastc > outbuf && isspace(*lastc)) {
! /* Trim trailing whitespace (CRLF) */
! *lastc-- = '\0';
! }
! }
! v = Py_BuildValue("(is)", myerrorcode, outbuf);
! if (v != NULL) {
! PyErr_SetObject(PySocket_Error, v);
! Py_DECREF(v);
! }
! return NULL;
! }
! }
#endif
***************
*** 444,450 ****
}
! /* Function to perfrom the setting of socket blocking mode
! * internally. block = (1 | 0).
! */
static int
internal_setblocking(PySocketSockObject *s, int block)
--- 447,452 ----
}
! /* Function to perform the setting of socket blocking mode
! internally. block = (1 | 0). */
static int
internal_setblocking(PySocketSockObject *s, int block)
***************
*** 459,464 ****
#ifdef __BEOS__
block = !block;
! setsockopt( s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
! (void *)(&block), sizeof(int));
#else
#ifndef RISCOS
--- 461,466 ----
#ifdef __BEOS__
block = !block;
! setsockopt(s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
! (void *)(&block), sizeof(int));
#else
#ifndef RISCOS
***************
*** 488,495 ****
/* For access to the select module to poll the socket for timeout
! * functionality. writing is 1 for writing, 0 for reading.
! * Return value: -1 if error, 0 if not ready, >= 1 if ready.
! * An exception is set when the return value is <= 0 (!).
! */
static int
internal_select(PySocketSockObject *s, int writing)
--- 490,496 ----
/* For access to the select module to poll the socket for timeout
! functionality. writing is 1 for writing, 0 for reading.
! Return value: -1 if error, 0 if not ready, >= 1 if ready.
! An exception is set when the return value is <= 0 (!). */
static int
internal_select(PySocketSockObject *s, int writing)
***************
*** 518,523 ****
/* Set the error if the timeout has elapsed, i.e, we were not
! * polled.
! */
if (count == 0)
timeout_err();
--- 519,523 ----
/* Set the error if the timeout has elapsed, i.e, we were not
! polled. */
if (count == 0)
timeout_err();
***************
*** 544,550 ****
s->errorhandler = &PySocket_Err;
#ifdef RISCOS
! if(taskwindow) {
socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
- }
#endif
}
--- 544,549 ----
s->errorhandler = &PySocket_Err;
#ifdef RISCOS
! if (taskwindow)
socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
#endif
}
***************
*** 582,586 ****
static int
! setipaddr(char* name, struct sockaddr * addr_ret, int af)
{
struct addrinfo hints, *res;
--- 581,585 ----
static int
! setipaddr(char *name, struct sockaddr *addr_ret, int af)
{
struct addrinfo hints, *res;
***************
*** 644,653 ****
error = getaddrinfo(name, NULL, &hints, &res);
#if defined(__digital__) && defined(__unix__)
! if (error == EAI_NONAME && af == AF_UNSPEC) {
! /* On Tru64 V5.1, numeric-to-addr conversion
! fails if no address family is given. Assume IPv4 for now.*/
! hints.ai_family = AF_INET;
! error = getaddrinfo(name, NULL, &hints, &res);
! }
#endif
if (error) {
--- 643,652 ----
error = getaddrinfo(name, NULL, &hints, &res);
#if defined(__digital__) && defined(__unix__)
! if (error == EAI_NONAME && af == AF_UNSPEC) {
! /* On Tru64 V5.1, numeric-to-addr conversion fails
! if no address family is given. Assume IPv4 for now.*/
! hints.ai_family = AF_INET;
! error = getaddrinfo(name, NULL, &hints, &res);
! }
#endif
if (error) {
***************
*** 742,747 ****
if (addrobj) {
a = (struct sockaddr_in6 *)addr;
! ret = Py_BuildValue("Oiii", addrobj, ntohs(a->sin6_port),
! a->sin6_flowinfo, a->sin6_scope_id);
Py_DECREF(addrobj);
}
--- 741,749 ----
if (addrobj) {
a = (struct sockaddr_in6 *)addr;
! ret = Py_BuildValue("Oiii",
! addrobj,
! ntohs(a->sin6_port),
! a->sin6_flowinfo,
! a->sin6_scope_id);
Py_DECREF(addrobj);
}
***************
*** 762,768 ****
ifname = ifr.ifr_name;
}
! return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol),
! a->sll_pkttype, a->sll_hatype,
! a->sll_addr, a->sll_halen);
}
#endif
--- 764,774 ----
ifname = ifr.ifr_name;
}
! return Py_BuildValue("shbhs#",
! ifname,
! ntohs(a->sll_protocol),
! a->sll_pkttype,
! a->sll_hatype,
! a->sll_addr,
! a->sll_halen);
}
#endif
***************
*** 823,829 ****
addr=(struct sockaddr_in*)&(s->sock_addr).in;
if (!PyTuple_Check(args)) {
! PyErr_Format(PyExc_TypeError,
! "getsockaddrarg: AF_INET address must be tuple, not %.500s",
! args->ob_type->tp_name);
return 0;
}
--- 829,837 ----
addr=(struct sockaddr_in*)&(s->sock_addr).in;
if (!PyTuple_Check(args)) {
! PyErr_Format(
! PyExc_TypeError,
! "getsockaddrarg: "
! "AF_INET address must be tuple, not %.500s",
! args->ob_type->tp_name);
return 0;
}
***************
*** 848,852 ****
flowinfo = scope_id = 0;
if (!PyArg_ParseTuple(args, "si|ii", &host, &port, &flowinfo,
! &scope_id)) {
return 0;
}
--- 856,860 ----
flowinfo = scope_id = 0;
if (!PyArg_ParseTuple(args, "si|ii", &host, &port, &flowinfo,
! &scope_id)) {
return 0;
}
***************
*** 1008,1013 ****
/* At this point, we really have an error, whether using timeout
! * behavior or regular socket behavior
! */
#ifdef MS_WINDOWS
if (newfd == INVALID_SOCKET)
--- 1016,1020 ----
/* At this point, we really have an error, whether using timeout
! behavior or regular socket behavior */
#ifdef MS_WINDOWS
if (newfd == INVALID_SOCKET)
***************
*** 1029,1033 ****
}
addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
! addrlen);
if (addr == NULL)
goto finally;
--- 1036,1040 ----
}
addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
! addrlen);
if (addr == NULL)
goto finally;
***************
*** 1062,1067 ****
/* If we're not using timeouts, actually set the blocking to give
! * old python behavior.
! */
if (s->sock_timeout < 0.0)
internal_setblocking(s, block);
--- 1069,1073 ----
/* If we're not using timeouts, actually set the blocking to give
! old python behavior. */
if (s->sock_timeout < 0.0)
internal_setblocking(s, block);
***************
*** 1077,1084 ****
This uses the FIONBIO ioctl with the O_NDELAY flag.";
! /* s.settimeout(float | None) method.
! * Causes an exception to be raised when the given time has
! * elapsed when performing a blocking socket operation.
! */
static PyObject *
PySocketSock_settimeout(PySocketSockObject *s, PyObject *arg)
--- 1083,1089 ----
This uses the FIONBIO ioctl with the O_NDELAY flag.";
! /* s.settimeout(None | float) method.
! Causes an exception to be raised when the given time has
! elapsed when performing a blocking socket operation. */
static PyObject *
PySocketSock_settimeout(PySocketSockObject *s, PyObject *arg)
***************
*** 1101,1115 ****
/* The semantics of setting socket timeouts are:
! * If you settimeout(!=None):
! * The actual socket gets put in non-blocking mode and the select
! * is used to control timeouts.
! * Else if you settimeout(None) [then value is -1.0]:
! * The old behavior is used AND automatically, the socket is set
! * to blocking mode. That means that someone who was doing
! * non-blocking stuff before, sets a timeout, and then unsets
! * one, will have to call setblocking(0) again if he wants
! * non-blocking stuff. This makes sense because timeout stuff is
! * blocking by nature.
! */
internal_setblocking(s, value < 0.0);
--- 1106,1119 ----
/* The semantics of setting socket timeouts are:
! If you settimeout(!=None):
! The actual socket gets put in non-blocking mode and the select
! is used to control timeouts.
! Else if you settimeout(None) [then value is -1.0]:
! The old behavior is used AND automatically, the socket is set
! to blocking mode. That means that someone who was doing
! non-blocking stuff before, sets a timeout, and then unsets
! one, will have to call setblocking(0) again if he wants
! non-blocking stuff. This makes sense because timeout stuff is
! blocking by nature. */
internal_setblocking(s, value < 0.0);
***************
*** 1121,1135 ****
static char settimeout_doc[] =
! "settimeout(seconds)\n\
\n\
! Set a timeout on blocking socket operations. 'seconds' can be a floating,\n\
! integer, or long number of seconds, or the None value. Socket operations\n\
! will raise an exception if the timeout period has elapsed before the\n\
! operation has completed. Setting a timeout of None disables timeouts\n\
! on socket operations.";
! /* s.gettimeout () method.
! * Returns the timeout associated with a socket.
! */
static PyObject *
PySocketSock_gettimeout(PySocketSockObject *s)
--- 1125,1135 ----
static char settimeout_doc[] =
! "settimeout(timeout)\n\
\n\
! Set a timeout on blocking socket operations. 'timeout' can be a float,\n\
! giving seconds, or None. Setting a timeout of None disables timeout.";
! /* s.gettimeout() method.
! Returns the timeout associated with a socket. */
static PyObject *
PySocketSock_gettimeout(PySocketSockObject *s)
***************
*** 1357,1362 ****
/* Check if we have an error */
if (!s->sock_blocking)
! return s->errorhandler ();
! /* Check if we have a true failure for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
--- 1357,1363 ----
/* Check if we have an error */
if (!s->sock_blocking)
! return s->errorhandler();
! /* Check if we have a true failure
! for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
***************
*** 1424,1428 ****
if (!s->sock_blocking)
goto conex_finally;
! /* Check if we have a true failure for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
--- 1425,1430 ----
if (!s->sock_blocking)
goto conex_finally;
! /* Check if we have a true failure
! for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
***************
*** 1754,1758 ****
if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
! addrlen)))
goto finally;
--- 1756,1760 ----
if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
! addrlen)))
goto finally;
***************
*** 1940,1948 ****
fileno_doc},
#ifdef HAVE_GETPEERNAME
! {"getpeername", (PyCFunction)PySocketSock_getpeername,
! METH_NOARGS, getpeername_doc},
#endif
{"getsockname", (PyCFunction)PySocketSock_getsockname,
! METH_NOARGS, getsockname_doc},
{"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS,
getsockopt_doc},
--- 1942,1950 ----
fileno_doc},
#ifdef HAVE_GETPEERNAME
! {"getpeername", (PyCFunction)PySocketSock_getpeername,
! METH_NOARGS, getpeername_doc},
#endif
{"getsockname", (PyCFunction)PySocketSock_getsockname,
! METH_NOARGS, getsockname_doc},
{"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS,
getsockopt_doc},
***************
*** 2003,2015 ****
printing, only bother if necessary*/
PyErr_SetString(PyExc_OverflowError,
! "no printf formatter to display the socket descriptor in decimal");
return NULL;
}
#endif
! PyOS_snprintf(buf, sizeof(buf),
! "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
! (long)s->sock_fd, s->sock_family,
! s->sock_type,
! s->sock_proto);
return PyString_FromString(buf);
}
--- 2005,2019 ----
printing, only bother if necessary*/
PyErr_SetString(PyExc_OverflowError,
! "no printf formatter to display "
! "the socket descriptor in decimal");
return NULL;
}
#endif
! PyOS_snprintf(
! buf, sizeof(buf),
! "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
! (long)s->sock_fd, s->sock_family,
! s->sock_type,
! s->sock_proto);
return PyString_FromString(buf);
}
***************
*** 2107,2110 ****
--- 2111,2115 ----
sendto() -- send data to a given address\n\
setblocking() -- set or clear the blocking I/O flag\n\
+ settimeout() -- set or clear the timeout\n\
setsockopt() -- set socket options\n\
shutdown() -- shut down traffic in one or both directions\n\
***************
*** 2227,2235 ****
if (h->h_addrtype != af) {
#ifdef HAVE_STRERROR
! /* Let's get real error message to return */
! PyErr_SetString(PySocket_Error, (char *)strerror(EAFNOSUPPORT));
! #else
PyErr_SetString(PySocket_Error,
! "Address family not supported by protocol family");
#endif
return NULL;
--- 2232,2242 ----
if (h->h_addrtype != af) {
#ifdef HAVE_STRERROR
! /* Let's get real error message to return */
PyErr_SetString(PySocket_Error,
! (char *)strerror(EAFNOSUPPORT));
! #else
! PyErr_SetString(
! PySocket_Error,
! "Address family not supported by protocol family");
#endif
return NULL;
***************
*** 2313,2317 ****
default: /* can't happen */
PyErr_SetString(PySocket_Error,
! "unsupported address family");
return NULL;
}
--- 2320,2324 ----
default: /* can't happen */
PyErr_SetString(PySocket_Error,
! "unsupported address family");
return NULL;
}
***************
*** 2368,2372 ****
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
! result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &errnop);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
--- 2375,2380 ----
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
! result = gethostbyname_r(name, &hp_allocated, buf, buf_len,
! &h, &errnop);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
***************
*** 2384,2394 ****
Py_END_ALLOW_THREADS
/* Some C libraries would require addr.__ss_family instead of
! * addr.ss_family.
! * Therefore, we cast the sockaddr_storage into sockaddr to
! * access sa_family.
! */
sa = (struct sockaddr*)&addr;
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr),
! sa->sa_family);
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(gethostbyname_lock);
--- 2392,2401 ----
Py_END_ALLOW_THREADS
/* Some C libraries would require addr.__ss_family instead of
! addr.ss_family.
! Therefore, we cast the sockaddr_storage into sockaddr to
! access sa_family. */
sa = (struct sockaddr*)&addr;
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr),
! sa->sa_family);
#ifdef USE_GETHOSTBYNAME_LOCK
PyThread_release_lock(gethostbyname_lock);
***************
*** 2411,2415 ****
{
#ifdef ENABLE_IPV6
! struct sockaddr_storage addr;
#else
struct sockaddr_in addr;
--- 2418,2422 ----
{
#ifdef ENABLE_IPV6
! struct sockaddr_storage addr;
#else
struct sockaddr_in addr;
***************
*** 2665,2674 ****
Convert a 32-bit integer from host to network byte order.";
! /*
! * socket.inet_aton() and socket.inet_ntoa() functions
! *
! * written 20 Aug 1999 by Ben Gertzfield <che@debian.org> <- blame him!
! *
! */
static char inet_aton_doc[] =
--- 2672,2676 ----
Convert a 32-bit integer from host to network byte order.";
! /* socket.inet_aton() and socket.inet_ntoa() functions. */
static char inet_aton_doc[] =
***************
*** 2828,2832 ****
if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
return NULL;
! if (!PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, &scope_id))
return NULL;
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
--- 2830,2835 ----
if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
return NULL;
! if (!PyArg_ParseTuple(sa, "si|ii",
! &hostp, &port, &flowinfo, &scope_id))
return NULL;
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
***************
*** 2952,2957 ****
case WSAVERNOTSUPPORTED:
case WSAEINVAL:
! PyErr_SetString(PyExc_ImportError,
! "WSAStartup failed: requested version not supported");
break;
default:
--- 2955,2961 ----
case WSAVERNOTSUPPORTED:
case WSAEINVAL:
! PyErr_SetString(
! PyExc_ImportError,
! "WSAStartup failed: requested version not supported");
break;
default:
***************
*** 2973,2977 ****
OS2cleanup(void)
{
! /* No cleanup is necessary for OS/2 Sockets */
}
--- 2977,2981 ----
OS2cleanup(void)
{
! /* No cleanup is necessary for OS/2 Sockets */
}
***************
*** 2980,2999 ****
{
#if !defined(PYCC_GCC)
! char reason[64];
! int rc = sock_init();
! if (rc == 0) {
! atexit(OS2cleanup);
! return 1; /* Indicate Success */
! }
! PyOS_snprintf(reason, sizeof(reason),
! "OS/2 TCP/IP Error# %d", sock_errno());
! PyErr_SetString(PyExc_ImportError, reason);
! return 0; /* Indicate Failure */
#else
! /* no need to initialise sockets with GCC/EMX */
! return 1;
#endif
}
--- 2984,3003 ----
{
#if !defined(PYCC_GCC)
! char reason[64];
! int rc = sock_init();
! if (rc == 0) {
! atexit(OS2cleanup);
! return 1; /* Indicate Success */
! }
! PyOS_snprintf(reason, sizeof(reason),
! "OS/2 TCP/IP Error# %d", sock_errno());
! PyErr_SetString(PyExc_ImportError, reason);
! return 0; /* Indicate Failure */
#else
! /* no need to initialise sockets with GCC/EMX */
! return 1;
#endif
}
***************
*** 3006,3029 ****
PySocketModule_APIObject PySocketModuleAPI =
{
! &PySocketSock_Type,
};
/* Initialize this module.
! * This is called when the first 'import socket' is done,
! * via a table in config.c, if config.c is compiled with USE_SOCKET
! * defined.
! *
! * For MS_WINDOWS (which means any Windows variant), this module
! * is actually called "_socket", and there's a wrapper "socket.py"
! * which implements some missing functionality (such as makefile(),
! * dup() and fromfd()). The import of "_socket" may fail with an
! * ImportError exception if initialization of WINSOCK fails. When
! * WINSOCK is initialized succesfully, a call to WSACleanup() is
! * scheduled to be made at exit time.
! *
! * For OS/2, this module is also called "_socket" and uses a wrapper
! * "socket.py" which implements that functionality that is missing
! * when PC operating systems don't put socket descriptors in the
! * operating system's filesystem layer.
*/
--- 3010,3034 ----
PySocketModule_APIObject PySocketModuleAPI =
{
! &PySocketSock_Type,
};
/* Initialize this module.
!
! This is called when the first 'import socket' is done,
! via a table in config.c, if config.c is compiled with USE_SOCKET
! defined.
!
! For MS_WINDOWS (which means any Windows variant), this module
! is actually called "_socket", and there's a wrapper "socket.py"
! which implements some missing functionality (such as makefile(),
! dup() and fromfd()). The import of "_socket" may fail with an
! ImportError exception if initialization of WINSOCK fails. When
! WINSOCK is initialized succesfully, a call to WSACleanup() is
! scheduled to be made at exit time.
!
! For OS/2, this module is also called "_socket" and uses a wrapper
! "socket.py" which implements that functionality that is missing
! when PC operating systems don't put socket descriptors in the
! operating system's filesystem layer.
*/
***************
*** 3056,3061 ****
PySocketSock_Type.tp_alloc = PyType_GenericAlloc;
PySocketSock_Type.tp_free = PyObject_Del;
! m = Py_InitModule3(PySocket_MODULE_NAME,
! PySocket_methods,
module_doc);
--- 3061,3066 ----
PySocketSock_Type.tp_alloc = PyType_GenericAlloc;
PySocketSock_Type.tp_free = PyObject_Del;
! m = Py_InitModule3(PySocket_MODULE_NAME,
! PySocket_methods,
module_doc);
***************
*** 3217,3221 ****
PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
#else
! PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
#endif
--- 3222,3226 ----
PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
#else
! PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
#endif
***************
*** 3667,3674 ****
/* Simplistic emulation code for inet_pton that only works for IPv4 */
#ifndef HAVE_INET_PTON
! int
inet_pton (int af, const char *src, void *dst)
{
! if(af == AF_INET){
long packed_addr;
packed_addr = inet_addr(src);
--- 3672,3679 ----
/* Simplistic emulation code for inet_pton that only works for IPv4 */
#ifndef HAVE_INET_PTON
! int
inet_pton (int af, const char *src, void *dst)
{
! if (af == AF_INET){
long packed_addr;
packed_addr = inet_addr(src);