xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPUtils.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 //-----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //-----------------------------------------------------------------------
7 
8 #ifndef _K_PPP_UTILS__H
9 #define _K_PPP_UTILS__H
10 
11 #ifndef _K_PPP_DEFS__H
12 #include <KPPPDefs.h>
13 #endif
14 
15 #include <OS.h>
16 
17 class KPPPProtocol;
18 
19 
20 // helper functions
21 extern bool IsProtocolAllowed(const KPPPProtocol& protocol);
22 
23 // the list template does not support iterating over each item :(
24 // this template iterates over each item in an indexed list
25 template<class _LIST, class _FUNCTION>
26 inline
27 void
28 ForEachItem(_LIST& list, _FUNCTION function)
29 {
30 	for(int index = 0; index < list.CountItems(); index++)
31 		function(list.ItemAt(index));
32 }
33 
34 
35 // These are very simple send/receive_data functions with a timeout
36 // and there is a race condition beween has_data() and send/receive_data().
37 // Timeouts in ms.
38 extern status_t send_data_with_timeout(thread_id thread, int32 code, void *buffer,
39 	size_t buffer_size, uint32 timeout);
40 extern status_t receive_data_with_timeout(thread_id *sender, int32 *code,
41 	void *buffer, size_t buffer_size, uint32 timeout);
42 
43 
44 #endif
45