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
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
status_t InitCheck() const;
|
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);
|
2008-07-13 23:58:35 +04:00
|
|
|
int SetOption(int32 option, int32 level, const void* data,
|
|
|
|
unsigned int dataSize);
|
2006-08-29 04:19:23 +04:00
|
|
|
int SetNonBlocking(bool on = true);
|
|
|
|
int SetReuseAddr(bool on = true);
|
2002-08-29 01:25:08 +04:00
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
const BNetAddress& LocalAddr() const;
|
|
|
|
const BNetAddress& RemoteAddr() const;
|
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
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
// TODO: drop these compatibility cruft methods after R1
|
|
|
|
status_t InitCheck();
|
|
|
|
const BNetAddress& LocalAddr();
|
|
|
|
const BNetAddress& RemoteAddr();
|
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
private:
|
2013-11-25 00:32:30 +04:00
|
|
|
BNetEndpoint(const BNetEndpoint& other, int socket,
|
|
|
|
const struct sockaddr_in& localAddress,
|
|
|
|
const struct sockaddr_in& peerAddress);
|
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
status_t _SetupSocket();
|
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
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
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
status_t fStatus;
|
|
|
|
int fFamily;
|
|
|
|
int fType;
|
|
|
|
int fProtocol;
|
2006-08-29 04:19:23 +04:00
|
|
|
int fSocket;
|
|
|
|
bigtime_t fTimeout;
|
|
|
|
BNetAddress fAddr;
|
|
|
|
BNetAddress fPeer;
|
2004-08-14 04:18:18 +04:00
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
int32 _reserved[16];
|
2002-08-29 01:25:08 +04:00
|
|
|
};
|
|
|
|
|
2008-07-13 23:58:35 +04:00
|
|
|
|
2006-08-29 04:19:23 +04:00
|
|
|
#endif // H_NETENDPOINT
|