diff options
author | sandmann <sandmann> | 2005-05-13 15:58:50 +0000 |
---|---|---|
committer | sandmann <sandmann> | 2005-05-13 15:58:50 +0000 |
commit | c236ace4214bef63330ea9176dc99a3ff8f307a6 (patch) | |
tree | ad006c2fbb7522f76ae88db5da94aea7cceac288 | |
parent | 5f418d7e05af4b42a3750a526f1e91cc837bbc6f (diff) |
*** empty log message ***
-rw-r--r-- | CODINGSTYLE | 45 | ||||
-rwxr-xr-x | TODO | 47 | ||||
-rw-r--r-- | src/lacbytequeue.c | 41 |
3 files changed, 106 insertions, 27 deletions
diff --git a/CODINGSTYLE b/CODINGSTYLE index 720629e..46b4663 100644 --- a/CODINGSTYLE +++ b/CODINGSTYLE @@ -1,6 +1,8 @@ Indent: +======= + + - Indent each level four spaces - - Rules for braces @@ -9,15 +11,36 @@ Rules for braces - if one branch of an if statement has braces, then both brances must have braces -if (foo) -{ - something(); - something_else(); -} -else -{ - blah(); -} + if (foo) + { + something(); + something_else(); + } + else + { + blah(); + } - if a branch of an if statement spans more than one line, then it must - have braces.
\ No newline at end of file + have braces, even if the branch itself is only a single statement + + if (foo) + { + a_long_function_name_with_lots (and, lots, and, lots, of + parameters, etc); + } + + - if the condition of an if statement is spans more than one line, then + the branches must have braces. + + - similar rules apply for for and while statements + +do-while: +========= + + - do-whiles are formatted like this + + do + { + blah(); + } while (foo); @@ -125,6 +125,10 @@ consistency: - foo_new() means "you must free whatever is returned" + - foo_new_lookup_from_bar() means "a new foo is created, + you must free it" + + * len -> length error handling: @@ -185,10 +189,45 @@ features: bool lac_address_is_ip6(); Assumption: the LacAddress will never need to cover - more than IP4 and IP6. + more than IP4 and IP6, at least not binary compatibly. - consider for 1.0 to make the ipv4 specific API conditional - on !LAC_IPV6_UNSAFE + on !LAC_IPV6_UNSAFE. Later on this API will + g_return_if_fail() when faced with an IP6 address. + + - Another idea is to just add the is_ip6() call + and have it always return TRUE for 1.0. + + - Another idea is to just remove the get_a_b_c_d() call, or + rename it lac_address_ip4_get_a_b_c_d(). + + - get_a_b_c_d() *is* unfortunately useful for protocols + involving sending addresses. Maybe add a + + const char * + address_serialize (LacAddress *, int &length); + + The returned string would be valid for as long as the + address is valid. Maybe also + address_new_from_serialized() + + - Note that sockets are different depending on the protocol + used. Ie., + + s = socket (AF_INET6, SOCK_STREAM, 0); + + vs. + + s = socket (AF_INET, SOCK_STREAM, 0); + + so just virtualizing the LacAddress may not be enough. + + Need to test if an AF_INET6 socket can be used for + IP4 communication. If so, we can get away with just + virtualizing addresses, if not, we probably lose. + + According to RFC 3493 it does look like you can use + an IP6 socket to communicate with IP4 nodes. * https/ssl support, at least make is possible later * proxy support in http module @@ -217,6 +256,10 @@ features: - On the other hand, maybe the library should know about different ways of structuring i/o + - Cache does have to live in library - otherwise it + could deal with half-done requests and multiple + simultaneous requests for the same object. + * cookie support (see RFC 2109) activity: diff --git a/src/lacbytequeue.c b/src/lacbytequeue.c index 0160e32..b8965db 100644 --- a/src/lacbytequeue.c +++ b/src/lacbytequeue.c @@ -1,9 +1,10 @@ struct _LacByteQueue { - guint allocated; - guint8 *data; - guint8 *head; - guint8 *tail; + guint allocated; + + guint8 * data; + guint8 * head; + guint8 * tail; }; enum { @@ -16,9 +17,10 @@ lac_byte_queue_new (void) LacByteQueue *byte_queue = g_new (LacByteQueue, 1); byte_queue->allocated = INITIAL_SIZE; + byte_queue->data = g_new (guint8, INITIAL_SIZE); - byte_queue->head = &(byte_queue->data[0]); - byte_queue->tail = &(byte_queue->data[0]); + byte_queue->head = byte_queue->data; + byte_queue->tail = byte_queue->data; return byte_queue; } @@ -26,13 +28,7 @@ lac_byte_queue_new (void) guint lac_byte_queue_get_length (LacByteQueue *byte_queue) { - guint8 *head = byte_queue->head; - guint8 *tail = byte_queue->tail; - - if (head >= tail) - return head - tail; - else - return byte_queue->allocated - (tail - head); + return byte_queue->tail - byte_queue->head; } static guint @@ -41,9 +37,26 @@ lac_byte_queue_get_capacity (LacByteQueue *byte_queue) return byte_queue->allocated - lac_byte_queue_get_length (byte_queue); } +static guint +power_of_two_bigger_than (guint n) +{ + guint result = 1; + + while (result <= n) + result *= 2; + + return result; +} + static void -lac_byte_queue_ensure_capacity (LacByteQueue *byte_queue, guint capacity) +lac_byte_queue_ensure_capacity (LacByteQueue *byte_queue, guint needed) { + guint new_size; + + if (needed <= lac_byte_queue_get_capacity (byte_queue)) + return; + + new_size = power_of_two_bigger_than (needed); } void |