1 /*
2 * Copyright 2003-2004, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 */
5
6 #ifndef _K_PPP_UTILS__H
7 #define _K_PPP_UTILS__H
8
9 #ifndef _K_PPP_DEFS__H
10 #include <KPPPDefs.h>
11 #endif
12
13 #include <OS.h>
14
15 class KPPPProtocol;
16
17
18 // helper functions
19 extern bool IsProtocolAllowed(const KPPPProtocol& protocol);
20
21 // the list template does not support iterating over each item :(
22 // this template iterates over each item in an indexed list
23 template<class _LIST, class _FUNCTION>
24 inline
25 void
ForEachItem(_LIST & list,_FUNCTION function)26 ForEachItem(_LIST& list, _FUNCTION function)
27 {
28 for(int index = 0; index < list.CountItems(); index++)
29 function(list.ItemAt(index));
30 }
31
32
33 // These are very simple send/receive_data functions with a timeout
34 // and there is a race condition beween has_data() and send/receive_data().
35 // Timeouts in ms.
36 extern status_t send_data_with_timeout(thread_id thread, int32 code, void *buffer,
37 size_t buffer_size, uint32 timeout);
38 extern status_t receive_data_with_timeout(thread_id *sender, int32 *code,
39 void *buffer, size_t buffer_size, uint32 timeout);
40
41
42 #endif
43