xref: /haiku/headers/os/net/NetEndpoint.h (revision 302f62604763c95777d6d04cca456e876f471c4f)
1 /*
2  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef H_NETENDPOINT
6 #define H_NETENDPOINT
7 
8 
9 #include <BeBuild.h>
10 #include <Archivable.h>
11 #include <NetAddress.h>
12 #include <NetBuffer.h>
13 #include <SupportDefs.h>
14 
15 #include <sys/socket.h>
16 
17 
18 class BNetEndpoint : public BArchivable {
19 	public:
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();
25 
26 		BNetEndpoint& operator=(const BNetEndpoint& other);
27 
28 		status_t InitCheck();
29 
30 		virtual	status_t Archive(BMessage* into, bool deep = true) const;
31 		static BArchivable* Instantiate(BMessage* archive);
32 
33 		status_t SetProtocol(int protocol);
34 		int SetOption(int32 option, int32 level, const void* data, unsigned int dataSize);
35 		int SetNonBlocking(bool on = true);
36 		int SetReuseAddr(bool on = true);
37 
38 		const BNetAddress& LocalAddr();
39 		const BNetAddress& RemoteAddr();
40 
41 		int Socket() const;
42 
43 		virtual void Close();
44 
45 		virtual status_t Bind(const BNetAddress& addr);
46 		virtual status_t Bind(int port = 0);
47 		virtual status_t Connect(const BNetAddress& addr);
48 		virtual status_t Connect(const char* addr, int port);
49 		virtual status_t Listen(int backlog = 5);
50 		virtual BNetEndpoint* Accept(int32 timeout = -1);
51 
52 		int Error() const;
53 		char* ErrorStr() const;
54 
55 		virtual int32 Send(const void* buffer, size_t size, int flags = 0);
56 		virtual int32 Send(BNetBuffer& buffer, int flags = 0);
57 
58 		virtual int32 SendTo(const void* buffer, size_t size,
59 			const BNetAddress& to, int flags = 0);
60 		virtual int32 SendTo(BNetBuffer& buffer, const BNetAddress& to,
61 			int flags = 0);
62 
63 		void SetTimeout(bigtime_t usec);
64 
65 		virtual int32 Receive(void* buffer, size_t size, int flags = 0);
66 		virtual int32 Receive(BNetBuffer& buffer, size_t size, int flags = 0);
67 		virtual int32 ReceiveFrom(void* buffer, size_t size, BNetAddress& from,
68 			int flags = 0);
69 		virtual int32 ReceiveFrom(BNetBuffer& buffer, size_t size,
70 			BNetAddress& from, int flags = 0);
71 
72 		virtual bool IsDataPending(bigtime_t timeout = 0);
73 
74 	private:
75 		virtual	void _ReservedBNetEndpointFBCCruft1();
76 		virtual	void _ReservedBNetEndpointFBCCruft2();
77 		virtual	void _ReservedBNetEndpointFBCCruft3();
78 		virtual	void _ReservedBNetEndpointFBCCruft4();
79 		virtual	void _ReservedBNetEndpointFBCCruft5();
80 		virtual	void _ReservedBNetEndpointFBCCruft6();
81 
82 		status_t	fInit;
83 		int			fSocket;
84 		bigtime_t	fTimeout;
85 		int			fLastError;
86 		BNetAddress fAddr;
87 		BNetAddress fPeer;
88 
89 		int32		_reserved[18];
90 };
91 
92 #endif	// H_NETENDPOINT
93