1 /* 2 * Copyright 2006-2008, 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 NET_UTILITY_H 9 #define NET_UTILITY_H 10 11 12 #include <net_stack.h> 13 14 15 class UserBuffer { 16 public: 17 UserBuffer(void* buffer, size_t size); 18 19 void* Push(void* source, size_t size); 20 status_t Pad(size_t length); 21 status_t PadToNext(size_t length); 22 23 status_t Status() const 24 { return fStatus; } 25 size_t BytesConsumed() const 26 { return fBufferSize - fAvailable; } 27 28 private: 29 uint8* fBuffer; 30 size_t fBufferSize; 31 size_t fAvailable; 32 status_t fStatus; 33 }; 34 35 36 inline 37 UserBuffer::UserBuffer(void* buffer, size_t size) 38 : 39 fBuffer((uint8*)buffer), 40 fBufferSize(size), 41 fAvailable(size), 42 fStatus(B_OK) 43 { 44 } 45 46 47 // checksums 48 uint16 compute_checksum(uint8* _buffer, size_t length); 49 uint16 checksum(uint8* buffer, size_t length); 50 51 // notifications 52 status_t notify_socket(net_socket* socket, uint8 event, int32 value); 53 54 // fifos 55 status_t init_fifo(net_fifo* fifo, const char *name, size_t maxBytes); 56 void uninit_fifo(net_fifo* fifo); 57 status_t fifo_enqueue_buffer(net_fifo* fifo, struct net_buffer* buffer); 58 ssize_t fifo_dequeue_buffer(net_fifo* fifo, uint32 flags, bigtime_t timeout, 59 struct net_buffer** _buffer); 60 status_t clear_fifo(net_fifo* fifo); 61 status_t fifo_socket_enqueue_buffer(net_fifo* fifo, net_socket* socket, 62 uint8 event, net_buffer* buffer); 63 64 // timer 65 void init_timer(net_timer* timer, net_timer_func hook, void* data); 66 void set_timer(net_timer* timer, bigtime_t delay); 67 bool cancel_timer(struct net_timer* timer); 68 status_t wait_for_timer(struct net_timer* timer); 69 bool is_timer_active(net_timer* timer); 70 bool is_timer_running(net_timer* timer); 71 status_t init_timers(void); 72 void uninit_timers(void); 73 74 // syscall restart 75 bool is_syscall(void); 76 bool is_restarted_syscall(void); 77 void store_syscall_restart_timeout(bigtime_t timeout); 78 bigtime_t restore_syscall_restart_timeout(void); 79 80 #endif // NET_UTILITY_H 81