2006-08-29 04:19:23 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef H_NETENDPOINT
|
|
|
|
#define H_NETENDPOINT
|
2002-08-29 01:25:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include <BeBuild.h>
|
|
|
|
#include <Archivable.h>
|
|
|
|
#include <NetAddress.h>
|
|
|
|
#include <NetBuffer.h>
|
2006-08-29 04:19:23 +04:00
|
|
|
#include <SupportDefs.h>
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
#include <sys/socket.h>
|
2004-08-14 04:18:18 +04:00
|
|
|
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
class BNetEndpoint : public BArchivable {
|
|
|
|
public:
|
|
|
|
BNetEndpoint(int type = SOCK_STREAM);
|
|
|
|
BNetEndpoint(int family, int type, int protocol);
|
|
|
|
BNetEndpoint(const BNetEndpoint& other);
|
|
|
|
BNetEndpoint(BMessage* archive);
|
|
|
|
virtual ~BNetEndpoint();
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
BNetEndpoint& operator=(const BNetEndpoint& other);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
status_t InitCheck();
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
status_t SetProtocol(int protocol);
|
|
|
|
int SetOption(int32 option, int32 level, const void* data, unsigned int dataSize);
|
|
|
|
int SetNonBlocking(bool on = true);
|
|
|
|
int SetReuseAddr(bool on = true);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
const BNetAddress& LocalAddr();
|
|
|
|
const BNetAddress& RemoteAddr();
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
int Socket() const;
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual void Close();
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual status_t Bind(const BNetAddress& addr);
|
|
|
|
virtual status_t Bind(int port = 0);
|
|
|
|
virtual status_t Connect(const BNetAddress& addr);
|
|
|
|
virtual status_t Connect(const char* addr, int port);
|
|
|
|
virtual status_t Listen(int backlog = 5);
|
|
|
|
virtual BNetEndpoint* Accept(int32 timeout = -1);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
int Error() const;
|
|
|
|
char* ErrorStr() const;
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual int32 Send(const void* buffer, size_t size, int flags = 0);
|
|
|
|
virtual int32 Send(BNetBuffer& buffer, int flags = 0);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual int32 SendTo(const void* buffer, size_t size,
|
|
|
|
const BNetAddress& to, int flags = 0);
|
|
|
|
virtual int32 SendTo(BNetBuffer& buffer, const BNetAddress& to,
|
|
|
|
int flags = 0);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
void SetTimeout(bigtime_t usec);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual int32 Receive(void* buffer, size_t size, int flags = 0);
|
|
|
|
virtual int32 Receive(BNetBuffer& buffer, size_t size, int flags = 0);
|
|
|
|
virtual int32 ReceiveFrom(void* buffer, size_t size, BNetAddress& from,
|
|
|
|
int flags = 0);
|
|
|
|
virtual int32 ReceiveFrom(BNetBuffer& buffer, size_t size,
|
|
|
|
BNetAddress& from, int flags = 0);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
virtual bool IsDataPending(bigtime_t timeout = 0);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
private:
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft1();
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft2();
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft3();
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft4();
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft5();
|
|
|
|
virtual void _ReservedBNetEndpointFBCCruft6();
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
status_t fInit;
|
|
|
|
int fSocket;
|
|
|
|
bigtime_t fTimeout;
|
|
|
|
int fLastError;
|
|
|
|
BNetAddress fAddr;
|
|
|
|
BNetAddress fPeer;
|
2004-08-14 04:18:18 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
int32 _reserved[18];
|
2002-08-29 01:25:08 +04:00
|
|
|
};
|
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
#endif // H_NETENDPOINT
|