diff options
Diffstat (limited to 'Modules/socketmodule.h')
-rw-r--r-- | Modules/socketmodule.h | 67 |
1 files changed, 12 insertions, 55 deletions
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h index 8515499b028..f064795b80f 100644 --- a/Modules/socketmodule.h +++ b/Modules/socketmodule.h @@ -8,7 +8,7 @@ # include <sys/socket.h> # endif # include <netinet/in.h> -# if !(defined(__BEOS__) || defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))) +# if !(defined(__CYGWIN__) || (defined(PYOS_OS2) && defined(PYCC_VACPP))) # include <netinet/tcp.h> # endif @@ -78,7 +78,7 @@ extern "C" { /* Python module and C API name */ #define PySocket_MODULE_NAME "_socket" #define PySocket_CAPI_NAME "CAPI" -#define PySocket_CAPSULE_NAME (PySocket_MODULE_NAME "." PySocket_CAPI_NAME) +#define PySocket_CAPSULE_NAME PySocket_MODULE_NAME "." PySocket_CAPI_NAME /* Abstract the socket file descriptor type */ #ifdef MS_WINDOWS @@ -93,6 +93,14 @@ typedef int SOCKET_T; # define SIZEOF_SOCKET_T SIZEOF_INT #endif +#if SIZEOF_SOCKET_T <= SIZEOF_LONG +#define PyLong_FromSocket_t(fd) PyLong_FromLong((SOCKET_T)(fd)) +#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLong(fd) +#else +#define PyLong_FromSocket_t(fd) PyLong_FromLongLong((SOCKET_T)(fd)) +#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd) +#endif + /* Socket address */ typedef union sock_addr { struct sockaddr_in in; @@ -188,61 +196,10 @@ typedef struct { typedef struct { PyTypeObject *Sock_Type; PyObject *error; + PyObject *timeout_error; } PySocketModule_APIObject; -/* XXX The net effect of the following appears to be to define a function - XXX named PySocketModule_APIObject in _ssl.c. It's unclear why it isn't - XXX defined there directly. - - >>> It's defined here because other modules might also want to use - >>> the C API. - -*/ -#ifndef PySocket_BUILDING_SOCKET - -/* --- C API ----------------------------------------------------*/ - -/* Interfacestructure to C API for other modules. - Call PySocketModule_ImportModuleAndAPI() to initialize this - structure. After that usage is simple: - - if (!PyArg_ParseTuple(args, "O!|zz:ssl", - &PySocketModule.Sock_Type, (PyObject*)&Sock, - &key_file, &cert_file)) - return NULL; - ... -*/ - -static -PySocketModule_APIObject PySocketModule; - -/* You *must* call this before using any of the functions in - PySocketModule and check its outcome; otherwise all accesses will - result in a segfault. Returns 0 on success. */ - -#ifndef DPRINTF -# define DPRINTF if (0) printf -#endif - -static -int PySocketModule_ImportModuleAndAPI(void) -{ - void *api; - - DPRINTF(" Loading capsule %s\n", PySocket_CAPSULE_NAME); - api = PyCapsule_Import(PySocket_CAPSULE_NAME, 1); - if (api == NULL) - goto onError; - memcpy(&PySocketModule, api, sizeof(PySocketModule)); - DPRINTF(" API object loaded and initialized.\n"); - return 0; - - onError: - DPRINTF(" not found.\n"); - return -1; -} - -#endif /* !PySocket_BUILDING_SOCKET */ +#define PySocketModule_ImportModuleAndAPI() PyCapsule_Import(PySocket_CAPSULE_NAME, 1) #ifdef __cplusplus } |