Restore the "GPL licensing not permitted" in GLUT license headers.
[haiku.git] / headers / os / net / NetEndpoint.h
blob37a0e27fd6f636783b3f7908188f0a4b0ebea4c9
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
9 #include <BeBuild.h>
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 {
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();
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;
42 int Socket() const;
44 virtual void Close();
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);
53 int Error() const;
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,
62 int flags = 0);
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,
69 int flags = 0);
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
76 status_t InitCheck();
77 const BNetAddress& LocalAddr();
78 const BNetAddress& RemoteAddr();
80 private:
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();
94 status_t fStatus;
95 int fFamily;
96 int fType;
97 int fProtocol;
98 int fSocket;
99 bigtime_t fTimeout;
100 BNetAddress fAddr;
101 BNetAddress fPeer;
103 int32 _reserved[16];
107 #endif // H_NETENDPOINT