ucx update

Tue, 27 Dec 2016 18:42:36 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 27 Dec 2016 18:42:36 +0100
changeset 135
471e28cca288
parent 134
44415e4399ce
child 136
9b48a1427aef

ucx update

src/server/daemon/config.c file | annotate | diff | comparison | revisions
src/server/daemon/sessionhandler.c file | annotate | diff | comparison | revisions
src/ucx/allocator.c file | annotate | diff | comparison | revisions
src/ucx/allocator.h file | annotate | diff | comparison | revisions
src/ucx/avl.c file | annotate | diff | comparison | revisions
src/ucx/avl.h file | annotate | diff | comparison | revisions
src/ucx/buffer.c file | annotate | diff | comparison | revisions
src/ucx/buffer.h file | annotate | diff | comparison | revisions
src/ucx/list.c file | annotate | diff | comparison | revisions
src/ucx/list.h file | annotate | diff | comparison | revisions
src/ucx/logging.c file | annotate | diff | comparison | revisions
src/ucx/logging.h file | annotate | diff | comparison | revisions
src/ucx/map.c file | annotate | diff | comparison | revisions
src/ucx/map.h file | annotate | diff | comparison | revisions
src/ucx/mempool.c file | annotate | diff | comparison | revisions
src/ucx/mempool.h file | annotate | diff | comparison | revisions
src/ucx/properties.c file | annotate | diff | comparison | revisions
src/ucx/properties.h file | annotate | diff | comparison | revisions
src/ucx/stack.c file | annotate | diff | comparison | revisions
src/ucx/stack.h file | annotate | diff | comparison | revisions
src/ucx/string.c file | annotate | diff | comparison | revisions
src/ucx/string.h file | annotate | diff | comparison | revisions
src/ucx/test.c file | annotate | diff | comparison | revisions
src/ucx/test.h file | annotate | diff | comparison | revisions
src/ucx/ucx.c file | annotate | diff | comparison | revisions
src/ucx/ucx.h file | annotate | diff | comparison | revisions
src/ucx/utils.c file | annotate | diff | comparison | revisions
src/ucx/utils.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/config.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/server/daemon/config.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1025,7 +1025,7 @@
         return r;
     }
     
-    if(ucx_stream_hcopy(in, buf, (read_func)fread, (write_func)ucx_buffer_write) == 0) {
+    if(ucx_stream_copy(in, buf, (read_func)fread, (write_func)ucx_buffer_write) == 0) {
         fclose(in);
         ucx_buffer_free(buf);
         return r;
--- a/src/server/daemon/sessionhandler.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/server/daemon/sessionhandler.c	Tue Dec 27 18:42:36 2016 +0100
@@ -158,7 +158,7 @@
 }
 
 void basic_keep_alive(SessionHandler *handler, Connection *conn) {
-    
+    connection_destroy(conn);
 }
 
 
--- a/src/ucx/allocator.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/allocator.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/allocator.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/allocator.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -28,7 +28,7 @@
 /**
  * Allocator for custom memory management.
  * 
- * An UCX allocator consists of a pointer to the memory area / pool and four
+ * A UCX allocator consists of a pointer to the memory area / pool and four
  * function pointers to memory management functions operating on this memory
  * area / pool. These functions shall behave equivalent to the standard libc
  * functions <code>malloc(), calloc(), realloc()</code> and <code>free()</code>.
@@ -38,7 +38,7 @@
  * memory area / pool as first argument.
  * 
  * As the pointer to the memory area / pool can be arbitrarily chosen, any data
- * can be provided to the memory management functions. An UcxMempool is just
+ * can be provided to the memory management functions. A UcxMempool is just
  * one example.
  * 
  * @see mempool.h
@@ -116,7 +116,7 @@
  * management functions. Use this function to get a pointer to a globally
  * available allocator. You may also define an own UcxAllocator by assigning
  * #UCX_ALLOCATOR_DEFAULT to a variable and pass the address of this variable
- * to any function that takes an UcxAllocator as argument. Note that using
+ * to any function that takes a UcxAllocator as argument. Note that using
  * this function is the recommended way of passing a default allocator, thus
  * it never runs out of scope.
  * 
--- a/src/ucx/avl.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/avl.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -29,6 +29,8 @@
 #include "avl.h"
 
 #define ptrcast(ptr) ((void*)(ptr))
+#define alloc_tree(al) (UcxAVLTree*) almalloc((al), sizeof(UcxAVLTree))
+#define alloc_node(al) (UcxAVLNode*) almalloc((al), sizeof(UcxAVLNode))
 
 static void ucx_avl_connect(UcxAVLTree *tree,
         UcxAVLNode *node, UcxAVLNode *child, intptr_t nullkey) {
@@ -107,7 +109,7 @@
 }
 
 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator) {
-    UcxAVLTree *tree = almalloc(allocator, sizeof(UcxAVLTree));
+    UcxAVLTree* tree = alloc_tree(allocator);
     if (tree) {
         tree->allocator = allocator;
         tree->cmpfunc = cmpfunc;
@@ -167,7 +169,7 @@
         }
 
         if (cmpresult) {
-            UcxAVLNode *e = almalloc(tree->allocator, sizeof(UcxAVLNode));
+            UcxAVLNode* e = alloc_node(tree->allocator);
             if (e) {
                 e->key = key; e->value = value; e->height = 1;
                 e->parent = e->left = e->right = NULL;
@@ -185,7 +187,7 @@
             return 0;
         }
     } else {
-        tree->root = almalloc(tree->allocator, sizeof(UcxAVLNode));
+        tree->root = alloc_node(tree->allocator);
         if (tree->root) {
             tree->root->key = key; tree->root->value = value;
             tree->root->height = 1;
--- a/src/ucx/avl.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/avl.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -44,7 +44,7 @@
 
 #include "ucx.h"
 #include "allocator.h"
-#include <stdint.h>
+#include <inttypes.h>
 
 #ifdef	__cplusplus
 extern "C" {
@@ -134,7 +134,7 @@
 UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
 
 /**
- * Destroys an UcxAVLTree.
+ * Destroys a UcxAVLTree.
  * @param tree the tree to destroy
  */
 void ucx_avl_free(UcxAVLTree *tree);
--- a/src/ucx/buffer.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/buffer.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/buffer.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/buffer.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -197,9 +197,9 @@
 int ucx_buffer_extend(UcxBuffer *buffer, size_t additional_bytes);
 
 /**
- * Writes data to an UcxBuffer.
+ * Writes data to a UcxBuffer.
  * 
- * The position of the buffer is increased by the number of bytes read.
+ * The position of the buffer is increased by the number of bytes written.
  * 
  * @param ptr a pointer to the memory area containing the bytes to be written
  * @param size the length of one element
@@ -211,7 +211,7 @@
         UcxBuffer *buffer);
 
 /**
- * Reads data from an UcxBuffer.
+ * Reads data from a UcxBuffer.
  * 
  * The position of the buffer is increased by the number of bytes read.
  * 
--- a/src/ucx/list.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/list.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -76,6 +76,13 @@
     }
 }
 
+void ucx_list_free_content(UcxList* list, ucx_destructor destr) {
+    while (list != NULL) {
+        destr(list->data);
+        list = list->next;
+    }
+}
+
 UcxList *ucx_list_append(UcxList *l, void *data)  {
     return ucx_list_append_a(ucx_default_allocator(), l, data);
 }
--- a/src/ucx/list.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/list.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -46,13 +46,13 @@
 /**
  * Loop statement for UCX lists.
  * 
- * The first argument is a pointer to the list. In most cases this will be the
+ * The first argument is the name of the iteration variable. The scope of
+ * this variable is limited to the <code>UCX_FOREACH</code> statement.
+ * 
+ * The second argument is a pointer to the list. In most cases this will be the
  * pointer to the first element of the list, but it may also be an arbitrary
  * element of the list. The iteration will then start with that element.
  * 
- * The second argument is the name of the iteration variable. The scope of
- * this variable is limited to the <code>UCX_FOREACH</code> statement.
- * 
  * @param list The first element of the list
  * @param elem The variable name of the element
  */
@@ -102,13 +102,12 @@
 UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data);
 
 /**
- * Creates an element-wise copy of a list using an UcxAllocator.
+ * Creates an element-wise copy of a list using a UcxAllocator.
  * 
  * See ucx_list_clone() for details.
  * 
- * Keep in mind, that you might want to pass the allocator as an (part of the)
- * argument for the <code>data</code> parameter, if you want the copy_func() to
- * make use of the allocator.
+ * You might want to pass the allocator via the <code>data</code> parameter,
+ * to access it within the copy function for making deep copies.
  * 
  * @param allocator the allocator to use
  * @param list the list to copy
@@ -146,17 +145,19 @@
  * Destroys the entire list.
  * 
  * The members of the list are not automatically freed, so ensure they are
- * otherwise referenced or a memory leak will occur.
+ * otherwise referenced or destroyed by ucx_list_free_contents().
+ * Otherwise, a memory leak is likely to occur.
  * 
  * <b>Caution:</b> the argument <b>MUST</b> denote an entire list (i.e. a call
  * to ucx_list_first() on the argument must return the argument itself)
  * 
  * @param list the list to free
+ * @see ucx_list_free_contents()
  */
 void ucx_list_free(UcxList *list);
 
 /**
- * Destroys the entire list using an UcxAllocator.
+ * Destroys the entire list using a UcxAllocator.
  * 
  * See ucx_list_free() for details.
  * 
@@ -167,6 +168,20 @@
 void ucx_list_free_a(UcxAllocator *allocator, UcxList *list);
 
 /**
+ * Destroys the contents of the specified list by calling the specified
+ * destructor on each of them.
+ * 
+ * Note, that the contents are not usable afterwards and the list should be
+ * destroyed with ucx_list_free().
+ * 
+ * @param list the list for which the contents shall be freed
+ * @param destr the destructor function (e.g. stdlib free())
+ * @see ucx_list_free()
+ */
+void ucx_list_free_content(UcxList* list, ucx_destructor destr);
+
+
+/**
  * Inserts an element at the end of the list.
  * 
  * This is generally an O(n) operation, as the end of the list is retrieved with
@@ -181,7 +196,7 @@
 UcxList *ucx_list_append(UcxList *list, void *data);
 
 /**
- * Inserts an element at the end of the list using an UcxAllocator.
+ * Inserts an element at the end of the list using a UcxAllocator.
  * 
  * See ucx_list_append() for details.
  * 
@@ -212,7 +227,7 @@
 UcxList *ucx_list_prepend(UcxList *list, void *data);
 
 /**
- * Inserts an element at the beginning of the list using an UcxAllocator.
+ * Inserts an element at the beginning of the list using a UcxAllocator.
  * 
  * See ucx_list_prepend() for details.
  * 
@@ -327,7 +342,7 @@
 int ucx_list_contains(UcxList *list, void *elem, cmp_func cmpfnc, void *data);
 
 /**
- * Sorts an UcxList with natural merge sort.
+ * Sorts a UcxList with natural merge sort.
  * 
  * This function uses O(n) additional temporary memory for merge operations
  * that is automatically freed after each merge.
@@ -357,7 +372,7 @@
 UcxList *ucx_list_remove(UcxList *list, UcxList *element);
 
 /**
- * Removes an element from the list using an UcxAllocator.
+ * Removes an element from the list using a UcxAllocator.
  * 
  * See ucx_list_remove() for details.
  * 
--- a/src/ucx/logging.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/logging.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/logging.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/logging.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/map.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/map.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/map.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/map.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -59,7 +59,7 @@
  * 
  * @param key the variable name for the key
  * @param value the variable name for the value
- * @param iter an UcxMapIterator
+ * @param iter a UcxMapIterator
  * @see ucx_map_iterator()
  */
 #define UCX_MAP_FOREACH(key,value,iter) \
@@ -68,13 +68,13 @@
 /** Type for the UCX map. @see UcxMap */
 typedef struct UcxMap          UcxMap;
 
-/** Type for a key of an UcxMap. @see UcxKey */
+/** Type for a key of a UcxMap. @see UcxKey */
 typedef struct UcxKey          UcxKey;
 
-/** Type for an element of an UcxMap. @see UcxMapElement */
+/** Type for an element of a UcxMap. @see UcxMapElement */
 typedef struct UcxMapElement   UcxMapElement;
 
-/** Type for an iterator over an UcxMap. @see UcxMapIterator */
+/** Type for an iterator over a UcxMap. @see UcxMapIterator */
 typedef struct UcxMapIterator  UcxMapIterator;
 
 /** Structure for the UCX map. */
@@ -89,7 +89,7 @@
     size_t        count;
 };
 
-/** Structure for a key of an UcxMap. */
+/** Structure for a key of a UcxMap. */
 struct UcxKey {
     /** The key data. */
     void   *data;
@@ -99,7 +99,7 @@
     int    hash;
 };
 
-/** Structure for an element of an UcxMap. */
+/** Structure for an element of a UcxMap. */
 struct UcxMapElement {
     /** The value data. */
     void          *data;
@@ -111,7 +111,7 @@
     UcxKey        key;
 };
 
-/** Structure for an iterator over an UcxMap. */
+/** Structure for an iterator over a UcxMap. */
 struct UcxMapIterator {
     /** The map to iterate over. */
     UcxMap        *map;
@@ -136,7 +136,7 @@
 UcxMap *ucx_map_new(size_t size);
 
 /**
- * Creates a new hash map with the specified size using an UcxAllocator.
+ * Creates a new hash map with the specified size using a UcxAllocator.
  * @param allocator the allocator to use
  * @param size the size of the hash map
  * @return a pointer to the new hash map
@@ -357,13 +357,13 @@
     ucx_map_remove(map, ucx_key((void*)&key, sizeof(key)))
 
 /**
- * Creates an UcxKey based on the given data.
+ * Creates a UcxKey based on the given data.
  * 
  * This function implicitly computes the hash.
  * 
  * @param data the data for the key
  * @param len the length of the data
- * @return an UcxKey with implicitly computed hash
+ * @return a UcxKey with implicitly computed hash
  * @see ucx_hash()
  */
 UcxKey ucx_key(void *data, size_t len);
@@ -380,14 +380,14 @@
 /**
  * Creates an iterator for a map.
  * 
- * <b>Note:</b> An UcxMapIterator iterates over all elements in all element
+ * <b>Note:</b> A UcxMapIterator iterates over all elements in all element
  * lists successively. Therefore the order highly depends on the key hashes and
  * may vary under different map sizes. So generally you may <b>NOT</b> rely on
  * the iteration order.
  * 
  * <b>Note:</b> The iterator is <b>NOT</b> initialized. You need to call
  * ucx_map_iter_next() at least once before accessing any information. However,
- * it is not recommended to access the fields of an UcxMapIterator directly.
+ * it is not recommended to access the fields of a UcxMapIterator directly.
  * 
  * @param map the map to create the iterator for
  * @return an iterator initialized on the first element of the
--- a/src/ucx/mempool.c	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/mempool.c	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
--- a/src/ucx/mempool.h	Tue Dec 27 17:54:00 2016 +0100
+++ b/src/ucx/mempool.h	Tue Dec 27 18:42:36 2016 +0100
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2015 Olaf Wintermann. All rights reserved.
+ * Copyright 2016 Olaf Wintermann. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -127,10 +127,8 @@
 /**
  * Reallocates pooled memory.
  *