On behalf of Scott Mansfield, the 3/4 Net* classes headers are there.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1806 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2002-11-01 02:49:38 +00:00
parent 2b1e7eaca7
commit 2ae4404ac1
3 changed files with 228 additions and 258 deletions
+103 -106
View File
@@ -1,106 +1,103 @@
/*=--------------------------------------------------------------------------=* /*=--------------------------------------------------------------------------=*
* NetAddress.h -- Interface definition for the BNetAddress class. * NetAddress.h -- Interface definition for the BNetAddress class.
* *
* Written by S.T. Mansfield ([email protected]) * Written by S.T. Mansfield ([email protected])
* *=--------------------------------------------------------------------------=*
* Remarks: * Copyright (c) 2002, The OpenBeOS project.
* Mr. Phipps, put that fish away, dude. *
*=--------------------------------------------------------------------------=* * Permission is hereby granted, free of charge, to any person obtaining a
* Copyright (c) 2002, The OpenBeOS project. * copy of this software and associated documentation files (the "Software"),
* * to deal in the Software without restriction, including without limitation
* Permission is hereby granted, free of charge, to any person obtaining a * the rights to use, copy, modify, merge, publish, distribute, sublicense,
* copy of this software and associated documentation files (the "Software"), * and/or sell copies of the Software, and to permit persons to whom the
* to deal in the Software without restriction, including without limitation * Software is furnished to do so, subject to the following conditions:
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the * The above copyright notice and this permission notice shall be included in
* Software is furnished to do so, subject to the following conditions: * all copies or substantial portions of the Software.
* *
* The above copyright notice and this permission notice shall be included in * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* all copies or substantial portions of the Software. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * DEALINGS IN THE SOFTWARE.
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *=--------------------------------------------------------------------------=*
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER */
* DEALINGS IN THE SOFTWARE.
*=--------------------------------------------------------------------------=* #ifndef _NETADDRESS_H
*/ #define _NETADDRESS_H
#ifndef _NETADDRESS_H #include <BeBuild.h>
#define _NETADDRESS_H #include <SupportDefs.h>
#include <Archivable.h>
#include <Archivable.h> #include <socket.h>
#include <Errors.h>
#include <Application.h> /*
#include <Message.h> * Empty forward declaration to satisfy the GetImpl method.
*/
/* class NLAddress;
* Empty forward declaration to satisfy the GetImpl method.
*/ class BNetAddress : public BArchivable
class NLAddress; {
public:
class BNetAddress : public BArchivable BNetAddress( BMessage* archive );
{ virtual ~BNetAddress( void );
public:
BNetAddress( BMessage* archive ); virtual status_t Archive( BMessage* into, bool deep = true ) const;
virtual ~BNetAddress( void ); static BArchivable* Instantiate( BMessage* archive );
virtual status_t Archive( BMessage* into, bool deep = true ) const; BNetAddress( const char* hostname = 0, unsigned short port = 0 );
static BArchivable* Instantiate( BMessage* archive ); BNetAddress( const struct sockaddr_in& sa );
BNetAddress( in_addr addr, int port = 0 );
BNetAddress( const char* hostname = NULL, unsigned short port = 0 ); BNetAddress( uint32 addr, int port = 0 );
BNetAddress( const struct sockaddr_in& sa ); BNetAddress( const BNetAddress& refparam );
BNetAddress( in_addr addr, int port = 0 ); BNetAddress( const char* hostname, const char* protocol, const char* service );
BNetAddress( uint32 addr, int port = 0 );
BNetAddress( const BNetAddress& refparam ); BNetAddress& operator=( const BNetAddress& );
BNetAddress( const char* hostname, const char* protocol, const char* service );
status_t InitCheck( void );
BNetAddress& operator=( const BNetAddress& );
status_t SetTo( const char* hostname, const char* protocol, const char* service );
status_t InitCheck( void ) const; status_t SetTo( const char* hostname = NULL, unsigned short port = 0 );
status_t SetTo( const struct sockaddr_in& sa );
status_t SetTo( const char* hostname, const char* protocol, const char* service ); status_t SetTo( in_addr addr, int port = 0 );
status_t SetTo( const char* hostname = NULL, unsigned short port = 0 ); status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 );
status_t SetTo( const struct sockaddr_in& sa );
status_t SetTo( in_addr addr, int port = 0 ); status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const;
status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 ); status_t GetAddr( struct sockaddr_in& sa ) const;
status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const;
status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const;
status_t GetAddr( struct sockaddr_in& sa ) const; inline NLAddress *GetImpl( void ) const;
status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const;
protected:
inline NLAddress *GetImpl( void ) const; // Attributes.
status_t fInitialized;
protected:
// Attributes. // Class-specific attributes. Basically re-encapsulate the saddr_in
status_t fInitialized; // struct (the POSiX version, hopefully). We can be inheritance-friendly
// here and still not break binary compatibility with R5.
// Class-specific attributes. Basically re-encapsulate the saddr_in int32 fFamily; // Encapsulation of sockaddr::sin_family
// struct (the POSiX version, hopefully). We can be inheritance-friendly int32 fPort; // Encapsulation of sockaddr::sin_port
// here and still not break binary compatibility with R5. int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr
int32 fFamily; // Encapsulation of sockaddr::sin_family
int32 fPort; // Encapsulation of sockaddr::sin_port private:
int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr // Private copy helper.
status_t clone( const BNetAddress& RefParam );
private:
// Private copy helper. // Not used, here to maintain R5 binary compatiblilty.
status_t clone( const BNetAddress& RefParam ); int32 fPrivateData[6];
};
// Not used, here to maintain R5 binary compatiblilty.
int32 fPrivateData[6];
}; // WARNING: This method, as it stands, breaks R5 compatibility *STM*.
inline NLAddress* BNetAddress::GetImpl( void ) const
{
// WARNING: This method, as it stands, breaks R5 compatibility *STM*. return NULL; // Cheeky, yes; but no Nettle stuff is allowed...
inline NLAddress* BNetAddress::GetImpl( void ) const }
{
return NULL; // Cheeky, yes; but no Nettle stuff is allowed... #endif // <-- #ifndef _NETADDRESS_H
}
#endif // <-- #ifndef _NETADDRESS_H /*=------------------------------------------------------------------- End -=*/
/*=------------------------------------------------------------------- End -=*/
+89 -116
View File
@@ -1,24 +1,29 @@
//------------------------------------------------------------------------------ /*=--------------------------------------------------------------------------=*
// Copyright (c) 2001-2002, OpenBeOS * NetBuffer.h -- Interface definition for the BNetBuffer class.
// *
// Permission is hereby granted, free of charge, to any person obtaining a * Written by S.T. Mansfield ([email protected])
// copy of this software and associated documentation files (the "Software"), *=--------------------------------------------------------------------------=*
// to deal in the Software without restriction, including without limitation * Copyright (c) 2002, The OpenBeOS project.
// the rights to use, copy, modify, merge, publish, distribute, sublicense, *
// and/or sell copies of the Software, and to permit persons to whom the * Permission is hereby granted, free of charge, to any person obtaining a
// Software is furnished to do so, subject to the following conditions: * copy of this software and associated documentation files (the "Software"),
// * to deal in the Software without restriction, including without limitation
// The above copyright notice and this permission notice shall be included in * the rights to use, copy, modify, merge, publish, distribute, sublicense,
// all copies or substantial portions of the Software. * and/or sell copies of the Software, and to permit persons to whom the
// * Software is furnished to do so, subject to the following conditions:
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * The above copyright notice and this permission notice shall be included in
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * all copies or substantial portions of the Software.
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// DEALINGS IN THE SOFTWARE. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//------------------------------------------------------------------------------ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*=--------------------------------------------------------------------------=*
*/
#ifndef _NETBUFFER_H #ifndef _NETBUFFER_H
#define _NETBUFFER_H #define _NETBUFFER_H
@@ -26,123 +31,91 @@
#include <BeBuild.h> #include <BeBuild.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <Archivable.h> #include <Archivable.h>
#include <sys/socket.h> #include <socket.h>
/* /*
* BNetBuffer * Empty forward declaration to satisfy the GetImpl method.
*
* BNetBuffer is a dynamic buffer useful for storing data to be sent
* across the network. Data is inserted into and removed from
* the object using one of the many insert and remove member functions.
* Access to the raw stored data is possible. The BNetEndpoint class has a
* send and recv function for use with BNetBuffer. Network byte order conversion
* is done automatically for all appropriate integral types in the insert and remove
* functions for that type.
*
*/ */
class NLPacket; class NLPacket;
class BNetBuffer : public BArchivable class BNetBuffer : public BArchivable
{ {
public: public:
BNetBuffer( size_t size = 0 );
virtual ~BNetBuffer( void );
BNetBuffer(size_t size = 0); status_t InitCheck( void );
virtual ~BNetBuffer();
/* BNetBuffer( BMessage* Archive );
* It is important to call InitCheck() after creating an instance of this class. virtual status_t Archive( BMessage* into, bool deep = true ) const;
*/ static BArchivable* Instantiate( BMessage* archive );
status_t InitCheck(); BNetBuffer( const BNetBuffer& );
BNetBuffer& operator=( const BNetBuffer& );
BNetBuffer(BMessage *archive);
virtual status_t Archive(BMessage *into, bool deep = true) const;
static BArchivable *Instantiate(BMessage *archive);
BNetBuffer(const BNetBuffer &); // Mutators.
BNetBuffer &operator=(const BNetBuffer &); status_t AppendInt8( int8 );
status_t AppendUint8( uint8 );
status_t AppendInt16( int16 );
status_t AppendUint16( uint16 );
status_t AppendInt32( int32 );
status_t AppendUint32( uint32 );
status_t AppendFloat( float );
status_t AppendDouble( double );
status_t AppendString( const char* );
status_t AppendData( const void*, size_t );
status_t AppendMessage( const BMessage& );
status_t AppendInt64( int64 );
status_t AppendUint64( uint64 );
/* status_t RemoveInt8( int8& );
* Data insertion member functions. Data is inserted at the end of the internal status_t RemoveUint8( uint8& );
* dynamic buffer. For the short, int, and long versions (and unsigned of status_t RemoveInt16( int16& );
* each as well) byte order conversion is performed. status_t RemoveUint16( uint16& );
* status_t RemoveInt32( int32& );
* The terminating null of all strings are inserted as status_t RemoveUint32( uint32& );
* well. status_t RemoveFloat( float& );
* status_t RemoveDouble( double& );
* Returns B_OK if successful, B_ERROR otherwise. status_t RemoveString( char*, size_t );
*/ status_t RemoveData( void*, size_t );
status_t AppendInt8(int8); status_t RemoveMessage( BMessage& );
status_t AppendUint8(uint8); status_t RemoveInt64( int64& );
status_t AppendInt16(int16); status_t RemoveUint64( uint64& );
status_t AppendUint16(uint16);
status_t AppendInt32(int32);
status_t AppendUint32(uint32);
status_t AppendFloat(float);
status_t AppendDouble(double);
status_t AppendString(const char *);
status_t AppendData(const void *, size_t);
status_t AppendMessage(const BMessage &);
status_t AppendInt64(int64);
status_t AppendUint64(uint64);
/* // Accessors.
* Data extraction member functions. Data is extracted from the start of the unsigned char* Data( void ) const;
* internal dynamic buffer. For the short, int, and long versions (and size_t Size( void ) const;
* unsigned of each as well) byte order conversion is performed. size_t BytesRemaining( void ) const;
*
* Returns B_OK if successful, B_ERROR otherwise. inline NLPacket *GetImpl( void ) const;
*/
status_t RemoveInt8(int8 &);
status_t RemoveUint8(uint8 &);
status_t RemoveInt16(int16 &);
status_t RemoveUint16(uint16 &);
status_t RemoveInt32(int32 &);
status_t RemoveUint32(uint32 &);
status_t RemoveFloat(float &);
status_t RemoveDouble(double &);
status_t RemoveString(char *, size_t);
status_t RemoveData(void *, size_t);
status_t RemoveMessage(BMessage &);
status_t RemoveInt64(int64 &);
status_t RemoveUint64(uint64 &);
/*
* GetData() returns a pointer to the internal data buffer. This is useful
* when wanting to pass the data to a function expecting a pointer to data.
* GetSize() returns the size of the BNetPacket's data, in bytes.
* GetBytesRemaining() returns the bytes remaining in the BNetPacket available
* to be extracted via BNetPacket::Remove*().
*/
unsigned char *Data() const;
size_t Size() const;
size_t BytesRemaining() const;
inline NLPacket *GetImpl() const;
protected: protected:
status_t m_init; // Attributes.
status_t fInitialized;
unsigned char* fData;
int32 fDataSize;
int32 fStackSize;
int32 fCapacity;
private: private:
virtual void _ReservedBNetBufferFBCCruft1(); // Private class helpers.
virtual void _ReservedBNetBufferFBCCruft2(); status_t clone( const BNetBuffer& );
virtual void _ReservedBNetBufferFBCCruft3(); status_t dpop( int32, int32, void* );
virtual void _ReservedBNetBufferFBCCruft4(); status_t dpush( int32, int32, const void* );
virtual void _ReservedBNetBufferFBCCruft5(); status_t resize( int32 NewSize, bool RegenStack = false );
virtual void _ReservedBNetBufferFBCCruft6();
int32 __ReservedBNetBufferFBCCruftData[9];
// Not used, here to maintain R5 binary compatiblilty.
int32 fPrivateData[5];
}; };
inline NLPacket *BNetBuffer::GetImpl() const // WARNING: This method, as it stands, breaks R5 compatibility *STM*.
inline NLPacket* BNetBuffer::GetImpl( void ) const
{ {
return NULL; // No Nettle backward compatibility return NULL; // Cheeky, yes; but no Nettle stuff is allowed...
} }
#endif // _NETBUFFER_H #endif // <-- #ifndef _NETBUFFER_H
/*=------------------------------------------------------------------- End -=*/
+36 -36
View File
@@ -1,24 +1,29 @@
//------------------------------------------------------------------------------ /*=--------------------------------------------------------------------------=*
// Copyright (c) 2001-2002, OpenBeOS * NetDebug.h -- Interface definition for the BNetDebug class.
// *
// Permission is hereby granted, free of charge, to any person obtaining a * Written by S.T. Mansfield ([email protected])
// copy of this software and associated documentation files (the "Software"), *=--------------------------------------------------------------------------=*
// to deal in the Software without restriction, including without limitation * Copyright (c) 2002, The OpenBeOS project.
// the rights to use, copy, modify, merge, publish, distribute, sublicense, *
// and/or sell copies of the Software, and to permit persons to whom the * Permission is hereby granted, free of charge, to any person obtaining a
// Software is furnished to do so, subject to the following conditions: * copy of this software and associated documentation files (the "Software"),
// * to deal in the Software without restriction, including without limitation
// The above copyright notice and this permission notice shall be included in * the rights to use, copy, modify, merge, publish, distribute, sublicense,
// all copies or substantial portions of the Software. * and/or sell copies of the Software, and to permit persons to whom the
// * Software is furnished to do so, subject to the following conditions:
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * The above copyright notice and this permission notice shall be included in
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * all copies or substantial portions of the Software.
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// DEALINGS IN THE SOFTWARE. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//------------------------------------------------------------------------------ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*=--------------------------------------------------------------------------=*
*/
#ifndef _NETDEBUG_H #ifndef _NETDEBUG_H
#define _NETDEBUG_H #define _NETDEBUG_H
@@ -34,25 +39,20 @@
class BNetDebug class BNetDebug
{ {
public: public:
/* // turn debugging message output on or off
* turn debugging message output on or off
*/
static void Enable(bool); static void Enable(bool);
/* // test debugging message output state
* test debugging message output state
*/
static bool IsEnabled(); static bool IsEnabled();
/* // print a debugging message
* print a debugging message static void Print( const char* msg );
*/
static void Print(const char *msg);
/* // dump raw data in a nice hd-like format
* dump raw data in a nice hd-like format static void Dump( const char* data, size_t size, const char* title );
*/
static void Dump(const char *data, size_t size, const char *title);
}; };
#endif // _NETDEBUG_H #endif // <-- #ifndef _NETDEBUG_H
/*=------------------------------------------------------------------- End -=*/