From 0db570a6227e514c99795e7a6f3cb194a92d2008 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 9 Feb 2007 00:10:28 +0000 Subject: [PATCH] build nativenet on Linux --- dtool/Config.Linux.pp | 2 ++ dtool/Config.OSX.pp | 7 ++++-- dtool/Config.pp | 4 ++++ dtool/LocalSetup.pp | 4 +++- dtool/src/parser-inc/Sources.pp | 3 ++- dtool/src/parser-inc/ip.h | 22 +++++++++++++++++++ dtool/src/parser-inc/tcp.h | 22 +++++++++++++++++++ .../nativenet/buffered_datagramconnection.h | 14 +++++------- panda/src/nativenet/buffered_datagramreader.h | 2 +- panda/src/nativenet/buffered_datagramwriter.h | 4 ++-- panda/src/nativenet/socket_address.h | 10 ++++----- panda/src/nativenet/socket_base.h | 2 ++ panda/src/nativenet/socket_fdset.h | 14 +++++++----- panda/src/nativenet/socket_portable.h | 2 +- panda/src/nativenet/socket_tcp_ssl.h | 7 ++++-- panda/src/nativenet/time_clock.h | 4 ++-- panda/src/nativenet/time_span.h | 2 +- 17 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 dtool/src/parser-inc/ip.h create mode 100644 dtool/src/parser-inc/tcp.h diff --git a/dtool/Config.Linux.pp b/dtool/Config.Linux.pp index 8e9ab6676d..82eedd1782 100644 --- a/dtool/Config.Linux.pp +++ b/dtool/Config.Linux.pp @@ -19,6 +19,8 @@ // to a subsequent version of Panda. // ******************************************************************* +#define IS_LINUX 1 + // What additional flags should we pass to interrogate? #define SYSTEM_IGATE_FLAGS -D__i386__ -D__const=const -Dvolatile= diff --git a/dtool/Config.OSX.pp b/dtool/Config.OSX.pp index 90deb1fba2..0a28f97242 100644 --- a/dtool/Config.OSX.pp +++ b/dtool/Config.OSX.pp @@ -19,10 +19,13 @@ // to a subsequent version of Panda. // ******************************************************************* +#define IS_OSX 1 + +// Assume that OSX has OpenGL available. +#define HAVE_GL 1 + // What additional flags should we pass to interrogate? #define SYSTEM_IGATE_FLAGS -D__FLT_EVAL_METHOD__=0 -D__i386__ -D__const=const -Dvolatile -D__LITTLE_ENDIAN__ -D__inline__=inline -D__GNUC__ -#define HAVE_GL 1 -#define IS_OSX 1 // We don't need worry about defining WORDS_BIGENDIAN (and we // shouldn't anyway, since ppc and intel are different). We rely on diff --git a/dtool/Config.pp b/dtool/Config.pp index e98fef9b67..c01ce326e4 100644 --- a/dtool/Config.pp +++ b/dtool/Config.pp @@ -410,6 +410,10 @@ #define NSPR_LIBS nspr4 #defer HAVE_NSPR $[isfile $[NSPR_IPATH]/prtypes.h] +// Define this true to build a native network implementation, +// bypassing NSPR. +#define WANT_NATIVE_NET + // Is a third-party STL library installed, and where? This is only // necessary if the default include and link lines that come with the // compiler don't provide adequate STL support. At least some form of diff --git a/dtool/LocalSetup.pp b/dtool/LocalSetup.pp index 8a350f2cbd..6f8ae8dfec 100644 --- a/dtool/LocalSetup.pp +++ b/dtool/LocalSetup.pp @@ -506,7 +506,7 @@ $[cdefine USE_MEMORY_PTMALLOC2] $[cdefine USE_MEMORY_MALLOC] $[cdefine USE_MEMORY_NOWRAPPERS] -#define if we want native net +// If we are to build the native net interfaces. $[cdefine WANT_NATIVE_NET] @@ -514,7 +514,9 @@ $[cdefine WANT_NATIVE_NET] $[cdefine USE_STL_ALLOCATOR] +/* Platform-identifying defines. */ $[cdefine IS_OSX] +$[cdefine IS_LINUX] #end dtool_config.h diff --git a/dtool/src/parser-inc/Sources.pp b/dtool/src/parser-inc/Sources.pp index 164c9f4e48..cc03ca290e 100644 --- a/dtool/src/parser-inc/Sources.pp +++ b/dtool/src/parser-inc/Sources.pp @@ -11,5 +11,6 @@ avcodec.h avformat.h avio.h avutil.h common.h integer.h \ intfloat_readwrite.h mathematics.h rational.h rtp.h \ rtsp.h rtspcodes.h winsock2.h \ - ode/config.h ode/common.h collision_trimesh.h + ode/config.h ode/common.h collision_trimesh.h \ + netinet/tcp.h netinet/ip.h diff --git a/dtool/src/parser-inc/ip.h b/dtool/src/parser-inc/ip.h new file mode 100644 index 0000000000..2b5a8f8d87 --- /dev/null +++ b/dtool/src/parser-inc/ip.h @@ -0,0 +1,22 @@ +// Filename: ip.h +// Created by: drose (08Feb07) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. diff --git a/dtool/src/parser-inc/tcp.h b/dtool/src/parser-inc/tcp.h new file mode 100644 index 0000000000..ab6578d336 --- /dev/null +++ b/dtool/src/parser-inc/tcp.h @@ -0,0 +1,22 @@ +// Filename: tcp.h +// Created by: drose (08Feb07) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +// This file, and all the other files in this directory, aren't +// intended to be compiled--they're just parsed by CPPParser (and +// interrogate) in lieu of the actual system headers, to generate the +// interrogate database. diff --git a/panda/src/nativenet/buffered_datagramconnection.h b/panda/src/nativenet/buffered_datagramconnection.h index 824f460fa4..fe0c664f39 100755 --- a/panda/src/nativenet/buffered_datagramconnection.h +++ b/panda/src/nativenet/buffered_datagramconnection.h @@ -11,12 +11,10 @@ // 3. Handle Framing and Unframing properly .. // //////////////////////////////////////////////////////////////////// -#include "dtoolbase.h" -#include +#include "pandabase.h" #include "socket_base.h" -//#include "../express/datagram.h" #include "datagram.h" - +#include "pvector.h" #include "buffered_datagramreader.h" #include "buffered_datagramwriter.h" @@ -31,7 +29,7 @@ class EXPCL_PANDA Buffered_DatagramConnection : protected Socket_TCP { private: - struct AddressQueue : private std::vector // this is used to do a round robin for addres to connect to .. + struct AddressQueue : private pvector // this is used to do a round robin for addres to connect to .. { size_t _active_index; bool GetNext(Socket_Address &out) @@ -46,17 +44,17 @@ private: return true; } - void clear() { std::vector::clear(); }; + void clear() { pvector::clear(); }; void push_back(Socket_Address &address) { iterator ii; for(ii = begin(); ii != end(); ii++) if(*ii == address) return; - std::vector::push_back(address); + pvector::push_back(address); } - size_t size() { return std::vector::size(); }; + size_t size() { return pvector::size(); }; }; protected: // c++ upcals for diff --git a/panda/src/nativenet/buffered_datagramreader.h b/panda/src/nativenet/buffered_datagramreader.h index baa99bd1e6..68812ee81c 100755 --- a/panda/src/nativenet/buffered_datagramreader.h +++ b/panda/src/nativenet/buffered_datagramreader.h @@ -56,7 +56,7 @@ public: int gotbytes = sck.RecvData(ff,(int)readsize); if(gotbytes < 0) // some error { - int er = GETERROR(); + //int er = GETERROR(); if(!sck.ErrorIs_WouldBlocking(gotbytes) ) { answer = -3; // hard error ? diff --git a/panda/src/nativenet/buffered_datagramwriter.h b/panda/src/nativenet/buffered_datagramwriter.h index 6831315b21..d2de4a480d 100755 --- a/panda/src/nativenet/buffered_datagramwriter.h +++ b/panda/src/nativenet/buffered_datagramwriter.h @@ -60,7 +60,7 @@ public: if(Writesize > 0) { int Writen = sck.SendData(GetMessageHead(),(int)Writesize); - if(_are_we_going_to_block_on_write == true && Writen < 0 && sck.ErrorIs_WouldBlocking(Writen) == TRUE) { + if(_are_we_going_to_block_on_write == true && Writen < 0 && sck.ErrorIs_WouldBlocking(Writen) == true) { //sck.SetBlocking(); Writen = sck.SendData(GetMessageHead(),(int)Writesize); //sck.SetNonBlocking(); @@ -74,7 +74,7 @@ public: answer = 1; } else if(Writen < 0) { - if(sck.ErrorIs_WouldBlocking(Writen) != TRUE) + if(sck.ErrorIs_WouldBlocking(Writen) != true) answer = -1; } } diff --git a/panda/src/nativenet/socket_address.h b/panda/src/nativenet/socket_address.h index 9e3777a844..d2ef9d954e 100755 --- a/panda/src/nativenet/socket_address.h +++ b/panda/src/nativenet/socket_address.h @@ -1,9 +1,9 @@ #ifndef __SOCKET_ADDRESS_H__ #define __SOCKET_ADDRESS_H__ -#include -#include "dtoolbase.h" #include "pandabase.h" +#include "numeric_types.h" + /////////////////////////////////// // Class : Socket_Address // @@ -202,7 +202,7 @@ inline bool Socket_Address::set_host(const std::string &hostname, int port) // // - UINT32 addr = (long)inet_addr (hostname.c_str()); + PN_uint32 addr = (long)inet_addr (hostname.c_str()); if(addr == INADDR_NONE) { hp = gethostbyname(hostname.c_str()); @@ -241,7 +241,7 @@ inline bool Socket_Address::set_host(const std::string &hostname) // Function name : Socket_Address::set_host // Description : ////////////////////////////////////////////////////////////// -inline bool Socket_Address::set_host(UINT32 in_hostname, int port) +inline bool Socket_Address::set_host(PN_uint32 in_hostname, int port) { memcpy(&_addr.sin_addr, &in_hostname, sizeof(in_hostname)); _addr.sin_port = htons(port); @@ -276,7 +276,7 @@ inline bool Socket_Address::operator < (const Socket_Address &in) const ////////////////////////////////////////////////////////////// inline bool Socket_Address::isMcastRange(void) { - UINT32 address = ntohl(_addr.sin_addr.s_addr); + PN_uint32 address = ntohl(_addr.sin_addr.s_addr); //224.0.0.0-239.255.255.255 .. e0,ef if(address >= 0xe0000000 && address < 0xefffffff) return true; diff --git a/panda/src/nativenet/socket_base.h b/panda/src/nativenet/socket_base.h index b4f53a7814..5521ceeda9 100755 --- a/panda/src/nativenet/socket_base.h +++ b/panda/src/nativenet/socket_base.h @@ -1,8 +1,10 @@ #ifndef __SOCKET_BASE_H__ #define __SOCKET_BASE_H__ + //////////////////////////////////////////// // Quick way to get all the network code defined //////////////////////////////////////////// +#include "pandabase.h" #include "socket_portable.h" #include "socket_address.h" #include "socket_ip.h" diff --git a/panda/src/nativenet/socket_fdset.h b/panda/src/nativenet/socket_fdset.h index 5c1cb1336f..eaaf28998c 100755 --- a/panda/src/nativenet/socket_fdset.h +++ b/panda/src/nativenet/socket_fdset.h @@ -11,6 +11,8 @@ // fits more with the normal Berkeley mind set... ** Not ** Should think about using POLL() on BSD-based systems // ////////////////////////////////////////////////////////// +#include "pandabase.h" +#include "numeric_types.h" #include "time_base.h" class Socket_fdset @@ -20,9 +22,9 @@ public: inline Socket_fdset(); inline void setForSocket(const Socket_IP &incon); inline bool IsSetFor(const Socket_IP & incon) const; - inline int WaitForRead(bool zeroFds, UINT32 sleep_time = 0xffffffff); - inline int WaitForWrite(bool zeroFds, UINT32 sleep_time = 0xffffffff); - inline int WaitForError(bool zeroFds, UINT32 sleep_time = 0xffffffff); + inline int WaitForRead(bool zeroFds, PN_uint32 sleep_time = 0xffffffff); + inline int WaitForWrite(bool zeroFds, PN_uint32 sleep_time = 0xffffffff); + inline int WaitForError(bool zeroFds, PN_uint32 sleep_time = 0xffffffff); inline int WaitForRead(bool zeroFds, const Time_Span & timeout); @@ -90,7 +92,7 @@ inline bool Socket_fdset::IsSetFor(const Socket_IP & incon) const // Function name : WaitForRead // Description : //////////////////////////////////////////////////////////////////// -inline int Socket_fdset::WaitForRead(bool zeroFds, UINT32 sleep_time) +inline int Socket_fdset::WaitForRead(bool zeroFds, PN_uint32 sleep_time) { int retVal = 0; if (sleep_time == 0xffffffff) @@ -151,7 +153,7 @@ inline void Socket_fdset::setForSocket(const Socket_IP &incon) // Description : This is the function that will wait till // one of the sockets is ready for writing //////////////////////////////////////////////////////////////////// -inline int Socket_fdset::WaitForWrite(bool zeroFds, UINT32 sleep_time) +inline int Socket_fdset::WaitForWrite(bool zeroFds, PN_uint32 sleep_time) { int retVal = 0; if (sleep_time == 0xffffffff) @@ -177,7 +179,7 @@ inline int Socket_fdset::WaitForWrite(bool zeroFds, UINT32 sleep_time) // Description : This is the function that will wait till // one of the sockets is in error state ////////////////////////////////////////////////////////////// -inline int Socket_fdset::WaitForError(bool zeroFds, UINT32 sleep_time) +inline int Socket_fdset::WaitForError(bool zeroFds, PN_uint32 sleep_time) { int retVal = 0; if (sleep_time == 0xffffffff) diff --git a/panda/src/nativenet/socket_portable.h b/panda/src/nativenet/socket_portable.h index 51d3fcb1d5..021cdb57af 100755 --- a/panda/src/nativenet/socket_portable.h +++ b/panda/src/nativenet/socket_portable.h @@ -244,7 +244,7 @@ const int LOCAL_CONNECT_BLOCKING = EINPROGRESS; * LINUX and FreeBSD STUFF ************************************************************************/ -#elif defined(Linux) || defined(FreeBSD) ||defined(LINUX) +#elif defined(IS_LINUX) || defined(FreeBSD) #include #include diff --git a/panda/src/nativenet/socket_tcp_ssl.h b/panda/src/nativenet/socket_tcp_ssl.h index 0684f51fe2..5b9460289a 100755 --- a/panda/src/nativenet/socket_tcp_ssl.h +++ b/panda/src/nativenet/socket_tcp_ssl.h @@ -9,6 +9,9 @@ // platform differences from machine to machine // ///////////////////////////////////////////////////////////////////// +#include "pandabase.h" +#include "numeric_types.h" + #include /* SSLeay stuff */ #include #include @@ -281,12 +284,12 @@ inline void Socket_TCP_SSL::DetailErrorFormat(void) { return; // turn on fir debuging - UINT32 l; + PN_uint32 l; char buf[256]; char buf2[4096]; const char *file,*data; int line,flags; - UINT32 es; + PN_uint32 es; es=CRYPTO_thread_id(); while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) diff --git a/panda/src/nativenet/time_clock.h b/panda/src/nativenet/time_clock.h index 47e79dca21..b9e7627c23 100755 --- a/panda/src/nativenet/time_clock.h +++ b/panda/src/nativenet/time_clock.h @@ -247,7 +247,7 @@ inline std::string Time_Clock::Format(char * pFormat) const *pch++ = ch1; break; case 'N': - pch += sprintf(pch, "%03d", _my_time.tv_usec / 1000); + pch += sprintf(pch, "%03ld", _my_time.tv_usec / 1000); break; } } @@ -295,7 +295,7 @@ inline std::string Time_Clock::FormatGmt(char * pFormat) const *pch++ = ch1; break; case 'N': - pch += sprintf(pch, "%03d", _my_time.tv_usec / 1000); + pch += sprintf(pch, "%03ld", _my_time.tv_usec / 1000); break; } } diff --git a/panda/src/nativenet/time_span.h b/panda/src/nativenet/time_span.h index 66f5421d58..93b0f4b455 100755 --- a/panda/src/nativenet/time_span.h +++ b/panda/src/nativenet/time_span.h @@ -372,7 +372,7 @@ inline std::string Time_Span::Format(char * pFormat) const pch += sprintf(pch, "%02d", GetSeconds()); break; case 'N': - pch += sprintf(pch, "%03d", _my_time.tv_usec / 1000); + pch += sprintf(pch, "%03ld", _my_time.tv_usec / 1000); break; } } else {