diff options
Diffstat (limited to 'src/base/system.h')
| -rw-r--r-- | src/base/system.h | 94 |
1 files changed, 67 insertions, 27 deletions
diff --git a/src/base/system.h b/src/base/system.h index a486b89d..b3588dbf 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -240,6 +240,18 @@ unsigned io_skip(IOHANDLE io, int size); unsigned io_write(IOHANDLE io, const void *buffer, unsigned size); /* + Function: io_write_newline + Writes newline to file. + + Parameters: + io - Handle to the file. + + Returns: + Number of bytes written. +*/ +unsigned io_write_newline(IOHANDLE io); + +/* Function: io_seek Seeks to a specified offset in the file. @@ -367,6 +379,16 @@ void thread_destroy(void *thread); */ void thread_yield(); +/* + Function: thread_detach + Puts the thread in the detached thread, guaranteeing that + resources of the thread will be freed immediately when the + thread terminates. + + Parameters: + thread - Thread to detach +*/ +void thread_detach(void *thread); /* Group: Locks */ typedef void* LOCK; @@ -378,6 +400,23 @@ int lock_try(LOCK lock); void lock_wait(LOCK lock); void lock_release(LOCK lock); + +/* Group: Semaphores */ + +#if defined(CONF_FAMILY_UNIX) + #include <semaphore.h> + typedef sem_t SEMAPHORE; +#elif defined(CONF_FAMILY_WINDOWS) + typedef void* SEMAPHORE; +#else + #error missing sempahore implementation +#endif + +void semaphore_init(SEMAPHORE *sem); +void semaphore_wait(SEMAPHORE *sem); +void semaphore_signal(SEMAPHORE *sem); +void semaphore_destroy(SEMAPHORE *sem); + /* Group: Timer */ #ifdef __GNUC__ /* if compiled with -pedantic-errors it will complain about long @@ -415,7 +454,7 @@ int64 time_freq(); Returns: The time as a UNIX timestamp */ -unsigned time_timestamp(); +int time_timestamp(); /* Group: Network General */ typedef struct @@ -489,12 +528,13 @@ int net_addr_comp(const NETADDR *a, const NETADDR *b); addr - Address to turn into a string. string - Buffer to fill with the string. max_length - Maximum size of the string. + add_port - add port to string or not Remarks: - The string will always be zero terminated */ -void net_addr_str(const NETADDR *addr, char *string, int max_length); +void net_addr_str(const NETADDR *addr, char *string, int max_length, int add_port); /* Function: net_addr_from_str @@ -581,7 +621,7 @@ int net_udp_close(NETSOCKET sock); Returns: On success it returns an handle to the socket. On failure it returns NETSOCKET_INVALID. */ -NETSOCKET net_tcp_create(const NETADDR *a); +NETSOCKET net_tcp_create(NETADDR bindaddr); /* Function: net_tcp_listen @@ -815,6 +855,25 @@ char *str_skip_whitespaces(char *str); */ int str_comp_nocase(const char *a, const char *b); +/* + Function: str_comp_nocase_num + Compares up to num characters of two strings case insensitive. + + Parameters: + a - String to compare. + b - String to compare. + num - Maximum characters to compare + + Returns: + <0 - String a is lesser than string b + 0 - String a is equal to string b + >0 - String a is greater than string b + + Remarks: + - Only garanted to work with a-z/A-Z. + - The strings are treated as zero-termineted strings. +*/ +int str_comp_nocase_num(const char *a, const char *b, const int num); /* Function: str_comp @@ -1065,21 +1124,21 @@ int fs_rename(const char *oldname, const char *newname); DOCTODO: serp */ -int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a); +int net_tcp_connect_non_blocking(NETSOCKET sock, NETADDR bindaddr); /* - Function: net_tcp_set_non_blocking + Function: net_set_non_blocking DOCTODO: serp */ -int net_tcp_set_non_blocking(NETSOCKET sock); +int net_set_non_blocking(NETSOCKET sock); /* - Function: net_tcp_set_non_blocking + Function: net_set_non_blocking DOCTODO: serp */ -int net_tcp_set_blocking(NETSOCKET sock); +int net_set_blocking(NETSOCKET sock); /* Function: net_errno @@ -1101,25 +1160,6 @@ void mem_debug_dump(IOHANDLE file); void swap_endian(void *data, unsigned elem_size, unsigned num); -/* Group: Debug levels */ -//by format -enum { - DBG_FMT_RAW = 1, //raw output - DBG_FMT_TIME = 2, //show time - DBG_FMT_SYS = 3, //show sys - DBG_FMT_FULL = 4 //show both -}; - -enum { - DBG_LEVEL_IMPORTANT = 0, //important always showed messages - DBG_LEVEL_ERROR = 1, //error messages - DBG_LEVEL_WARNING = 2, //warning messages - DBG_LEVEL_MSG = 3, //extra debug messages - DBG_LEVEL_INFO = 4 //info messages -}; - -#define DBG_LEVEL_LOW DBG_LEVEL_IMPORTANT -#define DBG_LEVEL_HIGH DBG_LEVEL_INFO typedef void (*DBG_LOGGER)(const char *line); void dbg_logger(DBG_LOGGER logger); |