Fix FreeBSD build.
[haiku.git] / headers / os / net / AbstractSocket.h
blob761379099ee32fa9b66a87b7f5a682e4b030fd93
1 /*
2 * Copyright 2011-2016, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _ABSTRACT_SOCKET_H
6 #define _ABSTRACT_SOCKET_H
9 #include <DataIO.h>
10 #include <NetworkAddress.h>
12 #include <sys/socket.h>
15 class BAbstractSocket : public BDataIO {
16 public:
17 BAbstractSocket();
18 BAbstractSocket(const BAbstractSocket& other);
19 virtual ~BAbstractSocket();
21 status_t InitCheck() const;
23 virtual status_t Bind(const BNetworkAddress& local, bool reuseAddr) = 0;
24 virtual bool IsBound() const;
25 virtual bool IsListening() const;
27 virtual status_t Listen(int backlog = 10);
28 virtual status_t Accept(BAbstractSocket*& _socket) = 0;
30 virtual status_t Connect(const BNetworkAddress& peer,
31 bigtime_t timeout = B_INFINITE_TIMEOUT) = 0;
32 virtual bool IsConnected() const;
33 virtual void Disconnect();
35 virtual status_t SetTimeout(bigtime_t timeout);
36 virtual bigtime_t Timeout() const;
38 virtual const BNetworkAddress& Local() const;
39 virtual const BNetworkAddress& Peer() const;
41 virtual size_t MaxTransmissionSize() const;
43 virtual status_t WaitForReadable(bigtime_t timeout
44 = B_INFINITE_TIMEOUT) const;
45 virtual status_t WaitForWritable(bigtime_t timeout
46 = B_INFINITE_TIMEOUT) const;
48 int Socket() const;
50 protected:
51 status_t Bind(const BNetworkAddress& local,
52 bool reuseAddr, int type);
53 status_t Connect(const BNetworkAddress& peer, int type,
54 bigtime_t timeout = B_INFINITE_TIMEOUT);
55 status_t AcceptNext(int& _acceptedSocket,
56 BNetworkAddress& _peer);
58 private:
59 status_t _OpenIfNeeded(int family, int type);
60 status_t _UpdateLocalAddress();
61 status_t _WaitFor(int flags, bigtime_t timeout) const;
63 protected:
64 status_t fInitStatus;
65 int fSocket;
66 BNetworkAddress fLocal;
67 BNetworkAddress fPeer;
68 bool fIsBound;
69 bool fIsConnected;
70 bool fIsListening;
74 #endif // _ABSTRACT_SOCKET_H