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 <AutoDeleter.h>
12#include <OS.h>
13#include <SupportDefs.h>
14
15class BNetEndpoint;
16class StreamingRingBuffer;
17
18typedef status_t (*NewConnectionCallback)(void *cookie, BNetEndpoint &endpoint);
19
20
21class NetReceiver {
22public:
23								NetReceiver(BNetEndpoint *endpoint,
24									StreamingRingBuffer *target,
25									NewConnectionCallback callback = NULL,
26									void *newConnectionCookie = NULL);
27								~NetReceiver();
28
29		BNetEndpoint *			Endpoint() { return fEndpoint.Get(); }
30
31private:
32static	int32					_NetworkReceiverEntry(void *data);
33		status_t				_Listen();
34		status_t				_Transfer();
35
36		BNetEndpoint *			fListener;
37		StreamingRingBuffer *	fTarget;
38
39		thread_id				fReceiverThread;
40		bool					fStopThread;
41
42		NewConnectionCallback	fNewConnectionCallback;
43		void *					fNewConnectionCookie;
44
45		ObjectDeleter<BNetEndpoint>
46								fEndpoint;
47};
48
49#endif // NET_RECEIVER_H
50