xref: /haiku/src/servers/app/drawing/interface/remote/NetReceiver.h (revision c42868a015daa160e093679b2637b1cf9f0b26ba)
1 /*
2  * Copyright 2009, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 #ifndef NET_RECEIVER_H
9 #define NET_RECEIVER_H
10 
11 #include <OS.h>
12 #include <SupportDefs.h>
13 
14 class BNetEndpoint;
15 class StreamingRingBuffer;
16 
17 typedef status_t (*NewConnectionCallback)(void *cookie, BNetEndpoint &endpoint);
18 
19 
20 class NetReceiver {
21 public:
22 								NetReceiver(BNetEndpoint *endpoint,
23 									StreamingRingBuffer *target,
24 									NewConnectionCallback callback = NULL,
25 									void *newConnectionCookie = NULL);
26 								~NetReceiver();
27 
28 		BNetEndpoint *			Endpoint() { return fEndpoint; }
29 
30 private:
31 static	int32					_NetworkReceiverEntry(void *data);
32 		status_t				_Listen();
33 		status_t				_Transfer();
34 
35 		BNetEndpoint *			fListener;
36 		StreamingRingBuffer *	fTarget;
37 
38 		thread_id				fReceiverThread;
39 		bool					fStopThread;
40 
41 		NewConnectionCallback	fNewConnectionCallback;
42 		void *					fNewConnectionCookie;
43 
44 		BNetEndpoint *			fEndpoint;
45 };
46 
47 #endif // NET_RECEIVER_H
48