xref: /haiku/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  */
8 #ifndef ENDPOINT_MANAGER_H
9 #define ENDPOINT_MANAGER_H
10 
11 
12 #include <lock.h>
13 #include <util/khash.h>
14 
15 #include <sys/socket.h>
16 
17 
18 class TCPEndpoint;
19 
20 class EndpointManager {
21 	public:
22 		EndpointManager();
23 		~EndpointManager();
24 
25 		status_t InitCheck() const;
26 
27 		recursive_lock *Locker() { return &fLock; }
28 
29 		status_t SetConnection(TCPEndpoint *endpoint, const sockaddr *local,
30 			const sockaddr *peer, const sockaddr *interfaceLocal);
31 		TCPEndpoint *FindConnection(sockaddr *local, sockaddr *peer);
32 
33 		status_t Bind(TCPEndpoint *endpoint, sockaddr *address);
34 		status_t BindToEphemeral(TCPEndpoint *endpoint, sockaddr *address);
35 		status_t Unbind(TCPEndpoint *endpoint);
36 
37 	private:
38 		TCPEndpoint *_LookupConnection(sockaddr *local, sockaddr *peer);
39 		status_t _RemoveConnection(TCPEndpoint *endpoint);
40 		TCPEndpoint *_LookupEndpoint(uint16 port);
41 		void _DumpConnections();
42 
43 		static int _ConnectionCompare(void *_endpoint, const void *_key);
44 		static uint32 _ConnectionHash(void *_endpoint, const void *_key, uint32 range);
45 		static int _EndpointCompare(void *_endpoint, const void *_key);
46 		static uint32 _EndpointHash(void *_endpoint, const void *_key, uint32 range);
47 
48 		hash_table *fConnectionHash;
49 		hash_table *fEndpointHash;
50 		recursive_lock fLock;
51 };
52 
53 #endif	// ENDPOINT_MANAGER_H
54