comparison Modules/socketmodule.c @ 42622:4d2aa4bfb2d6

Remove RISCOS support
author Skip Montanaro <skip@pobox.com>
date Thu, 16 Aug 2007 14:35:24 +0000
parents 980308fbda29
children a5e984eda45a
comparison
equal deleted inserted replaced
42616:cb8c1dd7ee32 42622:4d2aa4bfb2d6
249 typedef size_t socklen_t; 249 typedef size_t socklen_t;
250 # else 250 # else
251 # include <arpa/inet.h> 251 # include <arpa/inet.h>
252 # endif 252 # endif
253 253
254 # ifndef RISCOS
255 # include <fcntl.h> 254 # include <fcntl.h>
256 # else
257 # include <sys/ioctl.h>
258 # include <socklib.h>
259 # define NO_DUP
260 int h_errno; /* not used */
261 # define INET_ADDRSTRLEN 16
262 # endif
263 255
264 #else 256 #else
265 257
266 /* MS_WINDOWS includes */ 258 /* MS_WINDOWS includes */
267 # ifdef HAVE_FCNTL_H 259 # ifdef HAVE_FCNTL_H
414 by this module (but not argument type or memory errors, etc.). */ 406 by this module (but not argument type or memory errors, etc.). */
415 static PyObject *socket_error; 407 static PyObject *socket_error;
416 static PyObject *socket_herror; 408 static PyObject *socket_herror;
417 static PyObject *socket_gaierror; 409 static PyObject *socket_gaierror;
418 static PyObject *socket_timeout; 410 static PyObject *socket_timeout;
419
420 #ifdef RISCOS
421 /* Global variable which is !=0 if Python is running in a RISC OS taskwindow */
422 static int taskwindow;
423 #endif
424 411
425 /* A forward reference to the socket type object. 412 /* A forward reference to the socket type object.
426 The sock_type variable contains pointers to various functions, 413 The sock_type variable contains pointers to various functions,
427 some of which call new_sockobject(), which uses sock_type, so 414 some of which call new_sockobject(), which uses sock_type, so
428 there has to be a circular reference. */ 415 there has to be a circular reference. */
580 return NULL; 567 return NULL;
581 } 568 }
582 } 569 }
583 #endif 570 #endif
584 571
585 #if defined(RISCOS)
586 if (_inet_error.errnum != NULL) {
587 PyObject *v;
588 v = Py_BuildValue("(is)", errno, _inet_err());
589 if (v != NULL) {
590 PyErr_SetObject(socket_error, v);
591 Py_DECREF(v);
592 }
593 return NULL;
594 }
595 #endif
596
597 return PyErr_SetFromErrno(socket_error); 572 return PyErr_SetFromErrno(socket_error);
598 } 573 }
599 574
600 575
601 static PyObject * 576 static PyObject *
668 /* Function to perform the setting of socket blocking mode 643 /* Function to perform the setting of socket blocking mode
669 internally. block = (1 | 0). */ 644 internally. block = (1 | 0). */
670 static int 645 static int
671 internal_setblocking(PySocketSockObject *s, int block) 646 internal_setblocking(PySocketSockObject *s, int block)
672 { 647 {
673 #ifndef RISCOS
674 #ifndef MS_WINDOWS 648 #ifndef MS_WINDOWS
675 int delay_flag; 649 int delay_flag;
676 #endif
677 #endif 650 #endif
678 651
679 Py_BEGIN_ALLOW_THREADS 652 Py_BEGIN_ALLOW_THREADS
680 #ifdef __BEOS__ 653 #ifdef __BEOS__
681 block = !block; 654 block = !block;
682 setsockopt(s->sock_fd, SOL_SOCKET, SO_NONBLOCK, 655 setsockopt(s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
683 (void *)(&block), sizeof(int)); 656 (void *)(&block), sizeof(int));
684 #else 657 #else
685 #ifndef RISCOS
686 #ifndef MS_WINDOWS 658 #ifndef MS_WINDOWS
687 #if defined(PYOS_OS2) && !defined(PYCC_GCC) 659 #if defined(PYOS_OS2) && !defined(PYCC_GCC)
688 block = !block; 660 block = !block;
689 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block)); 661 ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
690 #elif defined(__VMS) 662 #elif defined(__VMS)
700 #endif /* !PYOS_OS2 */ 672 #endif /* !PYOS_OS2 */
701 #else /* MS_WINDOWS */ 673 #else /* MS_WINDOWS */
702 block = !block; 674 block = !block;
703 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); 675 ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
704 #endif /* MS_WINDOWS */ 676 #endif /* MS_WINDOWS */
705 #else /* RISCOS */
706 block = !block;
707 socketioctl(s->sock_fd, FIONBIO, (u_long*)&block);
708 #endif /* RISCOS */
709 #endif /* __BEOS__ */ 677 #endif /* __BEOS__ */
710 Py_END_ALLOW_THREADS 678 Py_END_ALLOW_THREADS
711 679
712 /* Since these don't return anything */ 680 /* Since these don't return anything */
713 return 1; 681 return 1;
776 744
777 PyMODINIT_FUNC 745 PyMODINIT_FUNC
778 init_sockobject(PySocketSockObject *s, 746 init_sockobject(PySocketSockObject *s,
779 SOCKET_T fd, int family, int type, int proto) 747 SOCKET_T fd, int family, int type, int proto)
780 { 748 {
781 #ifdef RISCOS
782 int block = 1;
783 #endif
784 s->sock_fd = fd; 749 s->sock_fd = fd;
785 s->sock_family = family; 750 s->sock_family = family;
786 s->sock_type = type; 751 s->sock_type = type;
787 s->sock_proto = proto; 752 s->sock_proto = proto;
788 s->sock_timeout = defaulttimeout; 753 s->sock_timeout = defaulttimeout;
790 s->errorhandler = &set_error; 755 s->errorhandler = &set_error;
791 756
792 if (defaulttimeout >= 0.0) 757 if (defaulttimeout >= 0.0)
793 internal_setblocking(s, 0); 758 internal_setblocking(s, 0);
794 759
795 #ifdef RISCOS
796 if (taskwindow)
797 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
798 #endif
799 } 760 }
800 761
801 762
802 /* Create a new socket object. 763 /* Create a new socket object.
803 This just creates the object and initializes it. 764 This just creates the object and initializes it.
1697 "gettimeout() -> timeout\n\ 1658 "gettimeout() -> timeout\n\
1698 \n\ 1659 \n\
1699 Returns the timeout in floating seconds associated with socket \n\ 1660 Returns the timeout in floating seconds associated with socket \n\
1700 operations. A timeout of None indicates that timeouts on socket \n\ 1661 operations. A timeout of None indicates that timeouts on socket \n\
1701 operations are disabled."); 1662 operations are disabled.");
1702
1703 #ifdef RISCOS
1704 /* s.sleeptaskw(1 | 0) method */
1705
1706 static PyObject *
1707 sock_sleeptaskw(PySocketSockObject *s,PyObject *arg)
1708 {
1709 int block;
1710 block = PyInt_AsLong(arg);
1711 if (block == -1 && PyErr_Occurred())
1712 return NULL;
1713 Py_BEGIN_ALLOW_THREADS
1714 socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
1715 Py_END_ALLOW_THREADS
1716
1717 Py_INCREF(Py_None);
1718 return Py_None;
1719 }
1720 PyDoc_STRVAR(sleeptaskw_doc,
1721 "sleeptaskw(flag)\n\
1722 \n\
1723 Allow sleeps in taskwindows.");
1724 #endif
1725
1726 1663
1727 /* s.setsockopt() method. 1664 /* s.setsockopt() method.
1728 With an integer third argument, sets an integer option. 1665 With an integer third argument, sets an integer option.
1729 With a string third argument, sets an option from a buffer; 1666 With a string third argument, sets an option from a buffer;
1730 use optional built-in module 'struct' to encode the string. */ 1667 use optional built-in module 'struct' to encode the string. */
2747 gettimeout_doc}, 2684 gettimeout_doc},
2748 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS, 2685 {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS,
2749 setsockopt_doc}, 2686 setsockopt_doc},
2750 {"shutdown", (PyCFunction)sock_shutdown, METH_O, 2687 {"shutdown", (PyCFunction)sock_shutdown, METH_O,
2751 shutdown_doc}, 2688 shutdown_doc},
2752 #ifdef RISCOS
2753 {"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O,
2754 sleeptaskw_doc},
2755 #endif
2756 {NULL, NULL} /* sentinel */ 2689 {NULL, NULL} /* sentinel */
2757 }; 2690 };
2758 2691
2759 /* SockObject members */ 2692 /* SockObject members */
2760 static PyMemberDef sock_memberlist[] = { 2693 static PyMemberDef sock_memberlist[] = {
2961 PyObject *addr_list = (PyObject *)NULL; 2894 PyObject *addr_list = (PyObject *)NULL;
2962 PyObject *tmp; 2895 PyObject *tmp;
2963 2896
2964 if (h == NULL) { 2897 if (h == NULL) {
2965 /* Let's get real error message to return */ 2898 /* Let's get real error message to return */
2966 #ifndef RISCOS
2967 set_herror(h_errno); 2899 set_herror(h_errno);
2968 #else
2969 PyErr_SetString(socket_error, "host not found");
2970 #endif
2971 return NULL; 2900 return NULL;
2972 } 2901 }
2973 2902
2974 if (h->h_addrtype != af) { 2903 if (h->h_addrtype != af) {
2975 #ifdef HAVE_STRERROR 2904 #ifdef HAVE_STRERROR
4012 METH_NOARGS, getdefaulttimeout_doc}, 3941 METH_NOARGS, getdefaulttimeout_doc},
4013 {"setdefaulttimeout", socket_setdefaulttimeout, 3942 {"setdefaulttimeout", socket_setdefaulttimeout,
4014 METH_O, setdefaulttimeout_doc}, 3943 METH_O, setdefaulttimeout_doc},
4015 {NULL, NULL} /* Sentinel */ 3944 {NULL, NULL} /* Sentinel */
4016 }; 3945 };
4017
4018
4019 #ifdef RISCOS
4020 #define OS_INIT_DEFINED
4021
4022 static int
4023 os_init(void)
4024 {
4025 _kernel_swi_regs r;
4026
4027 r.r[0] = 0;
4028 _kernel_swi(0x43380, &r, &r);
4029 taskwindow = r.r[0];
4030
4031 return 1;
4032 }
4033
4034 #endif /* RISCOS */
4035 3946
4036 3947
4037 #ifdef MS_WINDOWS 3948 #ifdef MS_WINDOWS
4038 #define OS_INIT_DEFINED 3949 #define OS_INIT_DEFINED
4039 3950