@@ -94,7 +94,7 @@ Socket methods:
9494#include <unistd.h>
9595#endif
9696
97- #if !defined(MS_WINDOWS ) && !defined(PYOS_OS2 )
97+ #if !defined(MS_WINDOWS ) && !defined(PYOS_OS2 ) && !defined( __BEOS__ )
9898extern int gethostname (); /* For Solaris, at least */
9999#endif
100100
@@ -113,6 +113,11 @@ extern int gethostname(); /* For Solaris, at least */
113113#include <os2.h>
114114#endif
115115
116+ #if defined(__BEOS__ )
117+ /* It's in the libs, but not the headers... - [cjh] */
118+ int shutdown ( int , int );
119+ #endif
120+
116121#include <sys/types.h>
117122#include "mytime.h"
118123
@@ -147,7 +152,8 @@ extern int gethostname(); /* For Solaris, at least */
147152 it must be compiled by the C++ compiler, as it takes the address of
148153 a static data item exported from the main Python DLL.
149154*/
150- #ifdef MS_WINDOWS
155+ #if defined(MS_WINDOWS ) || defined(__BEOS__ )
156+ /* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */
151157/* seem to be a few differences in the API */
152158#define close closesocket
153159#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
@@ -407,6 +413,11 @@ BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *,addr, int,addrlen)
407413 return Py_None ;
408414 }
409415
416+ #ifdef __BEOS__
417+ /* XXX: BeOS version of accept() doesn't set family coreectly */
418+ addr -> sa_family = AF_INET ;
419+ #endif
420+
410421 switch (addr -> sa_family ) {
411422
412423 case AF_INET :
@@ -600,6 +611,11 @@ BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
600611 if (!PyArg_Parse (args , "i" , & block ))
601612 return NULL ;
602613 Py_BEGIN_ALLOW_THREADS
614+ #ifdef __BEOS__
615+ block = !block ;
616+ setsockopt ( s -> sock_fd , SOL_SOCKET , SO_NONBLOCK ,
617+ (void * )(& block ), sizeof ( int ) );
618+ #else
603619#ifndef MS_WINDOWS
604620#ifdef PYOS_OS2
605621 block = !block ;
@@ -616,6 +632,7 @@ BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
616632 block = !block ;
617633 ioctlsocket (s -> sock_fd , FIONBIO , (u_long * )& block );
618634#endif /* MS_WINDOWS */
635+ #endif /* __BEOS__ */
619636 Py_END_ALLOW_THREADS
620637
621638 Py_INCREF (Py_None );
@@ -682,6 +699,12 @@ BUILD_FUNC_DEF_2(PySocketSock_getsockopt,PySocketSockObject *,s, PyObject *,args
682699 PyObject * buf ;
683700 int buflen = 0 ;
684701
702+ #ifdef __BEOS__
703+ /* We have incomplete socket support. */
704+ PyErr_SetString ( PySocket_Error , "getsockopt not supported" );
705+ return NULL ;
706+ #else
707+
685708 if (!PyArg_ParseTuple (args , "ii|i" , & level , & optname , & buflen ))
686709 return NULL ;
687710
@@ -710,6 +733,7 @@ BUILD_FUNC_DEF_2(PySocketSock_getsockopt,PySocketSockObject *,s, PyObject *,args
710733 }
711734 _PyString_Resize (& buf , buflen );
712735 return buf ;
736+ #endif /* __BEOS__ */
713737}
714738
715739static char getsockopt_doc [] =
@@ -1506,6 +1530,11 @@ BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args)
15061530{
15071531 char * name ;
15081532 struct protoent * sp ;
1533+ #ifdef __BEOS__
1534+ /* Not available in BeOS yet. - [cjh] */
1535+ PyErr_SetString ( PySocket_Error , "getprotobyname not supported" );
1536+ return NULL ;
1537+ #else
15091538 if (!PyArg_Parse (args , "s" , & name ))
15101539 return NULL ;
15111540 Py_BEGIN_ALLOW_THREADS
@@ -1516,6 +1545,7 @@ BUILD_FUNC_DEF_2(PySocket_getprotobyname,PyObject *,self, PyObject *,args)
15161545 return NULL ;
15171546 }
15181547 return PyInt_FromLong ((long ) sp -> p_proto );
1548+ #endif
15191549}
15201550
15211551static char getprotobyname_doc [] =
@@ -1866,7 +1896,7 @@ shutdown() -- shut down traffic in one or both directions\n\
18661896(*) not available on all platforms!)" ;
18671897
18681898void
1869- #if defined(MS_WINDOWS ) || defined(PYOS_OS2 )
1899+ #if defined(MS_WINDOWS ) || defined(PYOS_OS2 ) || defined( __BEOS__ )
18701900init_socket ()
18711901#else
18721902initsocket ()
@@ -1882,8 +1912,12 @@ initsocket()
18821912 if (!OS2init ())
18831913 return ;
18841914 m = Py_InitModule3 ("_socket" , PySocket_methods , module_doc );
1915+ #else
1916+ #if defined(__BEOS__ )
1917+ m = Py_InitModule3 ("_socket" , PySocket_methods , module_doc );
18851918#else
18861919 m = Py_InitModule3 ("socket" , PySocket_methods , module_doc );
1920+ #endif /* __BEOS__ */
18871921#endif
18881922#endif
18891923 d = PyModule_GetDict (m );
@@ -1903,9 +1937,12 @@ initsocket()
19031937#endif /* AF_UNIX */
19041938 insint (d , "SOCK_STREAM" , SOCK_STREAM );
19051939 insint (d , "SOCK_DGRAM" , SOCK_DGRAM );
1940+ #ifndef __BEOS__
1941+ /* We have incomplete socket support. */
19061942 insint (d , "SOCK_RAW" , SOCK_RAW );
19071943 insint (d , "SOCK_SEQPACKET" , SOCK_SEQPACKET );
19081944 insint (d , "SOCK_RDM" , SOCK_RDM );
1945+ #endif
19091946
19101947#ifdef SO_DEBUG
19111948 insint (d , "SO_DEBUG" , SO_DEBUG );
0 commit comments