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.
*
* Written by S.T. Mansfield ([email protected])
*
* Remarks:
* Mr. Phipps, put that fish away, dude.
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* 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 above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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 _NETADDRESS_H
#define _NETADDRESS_H
#include <Archivable.h>
#include <Errors.h>
#include <Application.h>
#include <Message.h>
/*
* Empty forward declaration to satisfy the GetImpl method.
*/
class NLAddress;
class BNetAddress : public BArchivable
{
public:
BNetAddress( BMessage* archive );
virtual ~BNetAddress( void );
virtual status_t Archive( BMessage* into, bool deep = true ) const;
static BArchivable* Instantiate( BMessage* archive );
BNetAddress( const char* hostname = NULL, unsigned short port = 0 );
BNetAddress( const struct sockaddr_in& sa );
BNetAddress( in_addr addr, int port = 0 );
BNetAddress( uint32 addr, int port = 0 );
BNetAddress( const BNetAddress& refparam );
BNetAddress( const char* hostname, const char* protocol, const char* service );
BNetAddress& operator=( const BNetAddress& );
status_t InitCheck( void ) const;
status_t SetTo( const char* hostname, const char* protocol, const char* service );
status_t SetTo( const char* hostname = NULL, unsigned short port = 0 );
status_t SetTo( const struct sockaddr_in& sa );
status_t SetTo( in_addr addr, int port = 0 );
status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 );
status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const;
status_t GetAddr( struct sockaddr_in& sa ) const;
status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const;
inline NLAddress *GetImpl( void ) const;
protected:
// Attributes.
status_t fInitialized;
// Class-specific attributes. Basically re-encapsulate the saddr_in
// struct (the POSiX version, hopefully). We can be inheritance-friendly
// here and still not break binary compatibility with R5.
int32 fFamily; // Encapsulation of sockaddr::sin_family
int32 fPort; // Encapsulation of sockaddr::sin_port
int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr
private:
// Private copy helper.
status_t clone( const BNetAddress& RefParam );
// 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
{
return NULL; // Cheeky, yes; but no Nettle stuff is allowed...
}
#endif // <-- #ifndef _NETADDRESS_H
/*=------------------------------------------------------------------- End -=*/
/*=--------------------------------------------------------------------------=*
* NetAddress.h -- Interface definition for the BNetAddress class.
*
* Written by S.T. Mansfield ([email protected])
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* 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 above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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 _NETADDRESS_H
#define _NETADDRESS_H
#include <BeBuild.h>
#include <SupportDefs.h>
#include <Archivable.h>
#include <socket.h>
/*
* Empty forward declaration to satisfy the GetImpl method.
*/
class NLAddress;
class BNetAddress : public BArchivable
{
public:
BNetAddress( BMessage* archive );
virtual ~BNetAddress( void );
virtual status_t Archive( BMessage* into, bool deep = true ) const;
static BArchivable* Instantiate( BMessage* archive );
BNetAddress( const char* hostname = 0, unsigned short port = 0 );
BNetAddress( const struct sockaddr_in& sa );
BNetAddress( in_addr addr, int port = 0 );
BNetAddress( uint32 addr, int port = 0 );
BNetAddress( const BNetAddress& refparam );
BNetAddress( const char* hostname, const char* protocol, const char* service );
BNetAddress& operator=( const BNetAddress& );
status_t InitCheck( void );
status_t SetTo( const char* hostname, const char* protocol, const char* service );
status_t SetTo( const char* hostname = NULL, unsigned short port = 0 );
status_t SetTo( const struct sockaddr_in& sa );
status_t SetTo( in_addr addr, int port = 0 );
status_t SetTo( uint32 addr = INADDR_ANY, int port = 0 );
status_t GetAddr( char* hostname = NULL, unsigned short* port = NULL ) const;
status_t GetAddr( struct sockaddr_in& sa ) const;
status_t GetAddr( in_addr& addr, unsigned short* port = NULL ) const;
inline NLAddress *GetImpl( void ) const;
protected:
// Attributes.
status_t fInitialized;
// Class-specific attributes. Basically re-encapsulate the saddr_in
// struct (the POSiX version, hopefully). We can be inheritance-friendly
// here and still not break binary compatibility with R5.
int32 fFamily; // Encapsulation of sockaddr::sin_family
int32 fPort; // Encapsulation of sockaddr::sin_port
int32 fAddress; // Encapsulation of sockaddr::sin_addr.s_addr
private:
// Private copy helper.
status_t clone( const BNetAddress& RefParam );
// 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
{
return NULL; // Cheeky, yes; but no Nettle stuff is allowed...
}
#endif // <-- #ifndef _NETADDRESS_H
/*=------------------------------------------------------------------- End -=*/
+89 -116
View File
@@ -1,24 +1,29 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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 above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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.
//------------------------------------------------------------------------------
/*=--------------------------------------------------------------------------=*
* NetBuffer.h -- Interface definition for the BNetBuffer class.
*
* Written by S.T. Mansfield ([email protected])
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* 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 above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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
#define _NETBUFFER_H
@@ -26,123 +31,91 @@
#include <BeBuild.h>
#include <SupportDefs.h>
#include <Archivable.h>
#include <sys/socket.h>
#include <socket.h>
/*
* BNetBuffer
*
* 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.
*
* Empty forward declaration to satisfy the GetImpl method.
*/
class NLPacket;
class BNetBuffer : public BArchivable
{
public:
BNetBuffer( size_t size = 0 );
virtual ~BNetBuffer( void );
BNetBuffer(size_t size = 0);
virtual ~BNetBuffer();
status_t InitCheck( void );
/*
* It is important to call InitCheck() after creating an instance of this class.
*/
BNetBuffer( BMessage* Archive );
virtual status_t Archive( BMessage* into, bool deep = true ) const;
static BArchivable* Instantiate( BMessage* archive );
status_t InitCheck();
BNetBuffer(BMessage *archive);
virtual status_t Archive(BMessage *into, bool deep = true) const;
static BArchivable *Instantiate(BMessage *archive);
BNetBuffer( const BNetBuffer& );
BNetBuffer& operator=( const BNetBuffer& );
BNetBuffer(const BNetBuffer &);
BNetBuffer &operator=(const BNetBuffer &);
// Mutators.
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 );
/*
* Data insertion member functions. Data is inserted at the end of the internal
* dynamic buffer. For the short, int, and long versions (and unsigned of
* each as well) byte order conversion is performed.
*
* The terminating null of all strings are inserted as
* well.
*
* Returns B_OK if successful, B_ERROR otherwise.
*/
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& );
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& );
/*
* Data extraction member functions. Data is extracted from the start of the
* internal dynamic buffer. For the short, int, and long versions (and
* unsigned of each as well) byte order conversion is performed.
*
* Returns B_OK if successful, B_ERROR otherwise.
*/
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;
// Accessors.
unsigned char* Data( void ) const;
size_t Size( void ) const;
size_t BytesRemaining( void ) const;
inline NLPacket *GetImpl( void ) const;
protected:
status_t m_init;
// Attributes.
status_t fInitialized;
unsigned char* fData;
int32 fDataSize;
int32 fStackSize;
int32 fCapacity;
private:
virtual void _ReservedBNetBufferFBCCruft1();
virtual void _ReservedBNetBufferFBCCruft2();
virtual void _ReservedBNetBufferFBCCruft3();
virtual void _ReservedBNetBufferFBCCruft4();
virtual void _ReservedBNetBufferFBCCruft5();
virtual void _ReservedBNetBufferFBCCruft6();
int32 __ReservedBNetBufferFBCCruftData[9];
// Private class helpers.
status_t clone( const BNetBuffer& );
status_t dpop( int32, int32, void* );
status_t dpush( int32, int32, const void* );
status_t resize( int32 NewSize, bool RegenStack = false );
// 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
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// 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 above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// 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.
//------------------------------------------------------------------------------
/*=--------------------------------------------------------------------------=*
* NetDebug.h -- Interface definition for the BNetDebug class.
*
* Written by S.T. Mansfield ([email protected])
*=--------------------------------------------------------------------------=*
* Copyright (c) 2002, The OpenBeOS project.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* 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 above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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
#define _NETDEBUG_H
@@ -34,25 +39,20 @@
class BNetDebug
{
public:
/*
* turn debugging message output on or off
*/
// turn debugging message output on or off
static void Enable(bool);
/*
* test debugging message output state
*/
// test debugging message output state
static bool IsEnabled();
/*
* print a debugging message
*/
static void Print(const char *msg);
// print a debugging message
static void Print( const char* msg );
/*
* dump raw data in a nice hd-like format
*/
static void Dump(const char *data, size_t size, const char *title);
// dump raw data in a nice hd-like format
static void Dump( const char* data, size_t size, const char* title );
};
#endif // _NETDEBUG_H
#endif // <-- #ifndef _NETDEBUG_H
/*=------------------------------------------------------------------- End -=*/