2 * Copyright 2012-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
12 #include <netinet/in.h>
15 #include <SupportDefs.h>
19 sockaddr_storage fAddress
;
22 bool operator==(const PeerAddress
& address
);
23 bool operator<(const PeerAddress
& address
);
25 PeerAddress
& operator=(const PeerAddress
& address
);
28 PeerAddress(int networkFamily
);
30 inline int Family() const;
32 const char* ProtocolString() const;
33 void SetProtocol(const char* protocol
);
35 char* UniversalAddress() const;
37 socklen_t
AddressSize() const;
39 void SetPort(uint16 port
);
42 const void* InAddr() const;
43 size_t InAddrSize() const;
48 PeerAddress::Family() const
50 return fAddress
.ss_family
;
56 class AddressResolver
{
58 AddressResolver(const char* name
);
61 status_t
GetNextAddress(PeerAddress
* address
);
63 void ForceProtocol(const char* protocol
);
64 void ForcePort(uint16 port
);
67 status_t
ResolveAddress(const char* name
);
81 class ConnectionBase
{
83 ConnectionBase(const PeerAddress
& address
);
84 virtual ~ConnectionBase();
86 status_t
GetLocalAddress(PeerAddress
* address
);
95 const PeerAddress fPeerAddress
;
98 class Connection
: public ConnectionBase
{
100 static status_t
Connect(Connection
**connection
,
101 const PeerAddress
& address
);
102 static status_t
SetTo(Connection
**connection
, int socket
,
103 const PeerAddress
& address
);
105 virtual status_t
Send(const void* buffer
, uint32 size
) = 0;
106 virtual status_t
Receive(void** buffer
, uint32
* size
) = 0;
108 status_t
Reconnect();
111 static Connection
* CreateObject(const PeerAddress
& address
);
113 Connection(const PeerAddress
& address
);
118 class ConnectionStream
: public Connection
{
120 ConnectionStream(const PeerAddress
& address
);
122 virtual status_t
Send(const void* buffer
, uint32 size
);
123 virtual status_t
Receive(void** buffer
, uint32
* size
);
126 class ConnectionPacket
: public Connection
{
128 ConnectionPacket(const PeerAddress
& address
);
130 virtual status_t
Send(const void* buffer
, uint32 size
);
131 virtual status_t
Receive(void** buffer
, uint32
* size
);
134 class ConnectionListener
: public ConnectionBase
{
136 static status_t
Listen(ConnectionListener
** listener
, int networkFamily
,
139 status_t
AcceptConnection(Connection
** connection
);
142 ConnectionListener(const PeerAddress
& address
);
145 #endif // CONNECTION_H