2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
10 #include <Archivable.h>
11 #include <NetAddress.h>
12 #include <NetBuffer.h>
13 #include <SupportDefs.h>
15 #include <sys/socket.h>
18 class BNetEndpoint
: public BArchivable
{
20 BNetEndpoint(int type
= SOCK_STREAM
);
21 BNetEndpoint(int family
, int type
, int protocol
);
22 BNetEndpoint(const BNetEndpoint
& other
);
23 BNetEndpoint(BMessage
* archive
);
24 virtual ~BNetEndpoint();
26 BNetEndpoint
& operator=(const BNetEndpoint
& other
);
28 status_t
InitCheck() const;
30 virtual status_t
Archive(BMessage
* into
, bool deep
= true) const;
31 static BArchivable
* Instantiate(BMessage
* archive
);
33 status_t
SetProtocol(int protocol
);
34 int SetOption(int32 option
, int32 level
, const void* data
,
35 unsigned int dataSize
);
36 int SetNonBlocking(bool on
= true);
37 int SetReuseAddr(bool on
= true);
39 const BNetAddress
& LocalAddr() const;
40 const BNetAddress
& RemoteAddr() const;
46 virtual status_t
Bind(const BNetAddress
& addr
);
47 virtual status_t
Bind(int port
= 0);
48 virtual status_t
Connect(const BNetAddress
& addr
);
49 virtual status_t
Connect(const char* addr
, int port
);
50 virtual status_t
Listen(int backlog
= 5);
51 virtual BNetEndpoint
* Accept(int32 timeout
= -1);
54 char* ErrorStr() const;
56 virtual int32
Send(const void* buffer
, size_t size
, int flags
= 0);
57 virtual int32
Send(BNetBuffer
& buffer
, int flags
= 0);
59 virtual int32
SendTo(const void* buffer
, size_t size
,
60 const BNetAddress
& to
, int flags
= 0);
61 virtual int32
SendTo(BNetBuffer
& buffer
, const BNetAddress
& to
,
64 void SetTimeout(bigtime_t usec
);
66 virtual int32
Receive(void* buffer
, size_t size
, int flags
= 0);
67 virtual int32
Receive(BNetBuffer
& buffer
, size_t size
, int flags
= 0);
68 virtual int32
ReceiveFrom(void* buffer
, size_t size
, BNetAddress
& from
,
70 virtual int32
ReceiveFrom(BNetBuffer
& buffer
, size_t size
,
71 BNetAddress
& from
, int flags
= 0);
73 virtual bool IsDataPending(bigtime_t timeout
= 0);
75 // TODO: drop these compatibility cruft methods after R1
77 const BNetAddress
& LocalAddr();
78 const BNetAddress
& RemoteAddr();
81 BNetEndpoint(const BNetEndpoint
& other
, int socket
,
82 const struct sockaddr_in
& localAddress
,
83 const struct sockaddr_in
& peerAddress
);
85 status_t
_SetupSocket();
87 virtual void _ReservedBNetEndpointFBCCruft1();
88 virtual void _ReservedBNetEndpointFBCCruft2();
89 virtual void _ReservedBNetEndpointFBCCruft3();
90 virtual void _ReservedBNetEndpointFBCCruft4();
91 virtual void _ReservedBNetEndpointFBCCruft5();
92 virtual void _ReservedBNetEndpointFBCCruft6();
107 #endif // H_NETENDPOINT