diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-02-27 10:27:16 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-02-27 10:27:16 +0000 |
commit | f632382b95605adb705bc7df830e016ed1f7735a (patch) | |
tree | 59796ed314dd4b49981cdf5b603421bb5a0078bb /src/stream/stream_api.c | |
parent | 65b12e6421b3b3f3733855b338aa09e36d09e44f (diff) | |
download | gnunet-f632382b95605adb705bc7df830e016ed1f7735a.tar.gz gnunet-f632382b95605adb705bc7df830e016ed1f7735a.zip |
-fixed relative boundaries in stream read
Diffstat (limited to 'src/stream/stream_api.c')
-rw-r--r-- | src/stream/stream_api.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 41bae2da5..6ae3dbefe 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -2056,6 +2056,8 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
2056 | { | 2056 | { |
2057 | unsigned int packet; | 2057 | unsigned int packet; |
2058 | struct GNUNET_STREAM_IOReadHandle *read_handle; | 2058 | struct GNUNET_STREAM_IOReadHandle *read_handle; |
2059 | uint32_t offset_increase; | ||
2060 | uint32_t sequence_increase; | ||
2059 | 2061 | ||
2060 | /* Return NULL if there is already a read handle; the user has to cancel that | 2062 | /* Return NULL if there is already a read handle; the user has to cancel that |
2061 | first before continuing or has to wait until it is completed */ | 2063 | first before continuing or has to wait until it is completed */ |
@@ -2080,26 +2082,47 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
2080 | break; | 2082 | break; |
2081 | } | 2083 | } |
2082 | 2084 | ||
2083 | if (0 == packet) /* The first packet is still missing */ | 2085 | sequence_increase = packet; |
2086 | |||
2087 | if (0 == sequence_increase) /* The first packet is still missing */ | ||
2084 | { | 2088 | { |
2085 | /* We can't do anything until it arrives */ | 2089 | /* We can't do anything until it arrives */ |
2086 | } | 2090 | } |
2087 | else | 2091 | else |
2088 | { | 2092 | { |
2089 | /* Copy data to copy buffer */ | 2093 | /* Copy data to copy buffer */ |
2094 | GNUNET_assert (0 < socket->receive_buffer_boundaries[sequence_increase-1]); | ||
2090 | socket->copy_buffer = | 2095 | socket->copy_buffer = |
2091 | GNUNET_malloc (socket->receive_buffer_boundaries[packet-1]); | 2096 | GNUNET_malloc (socket->receive_buffer_boundaries[sequence_increase-1]); |
2097 | |||
2098 | /* Shift the data in the receive buffer */ | ||
2099 | memmove (socket->receive_buffer, | ||
2100 | socket->receive_buffer | ||
2101 | + socket->receive_buffer_boundaries[sequence_increase-1], | ||
2102 | socket->receive_buffer_size - socket->receive_buffer_boundaries[sequence_increase-1]); | ||
2092 | 2103 | ||
2093 | /* Shift the bitmap */ | 2104 | /* Shift the bitmap */ |
2094 | socket->ack_bitmap << packet; | 2105 | socket->ack_bitmap = socket->ack_bitmap >> sequence_increase; |
2095 | 2106 | ||
2096 | /* Set read_sequence_number */ | 2107 | /* Set read_sequence_number */ |
2097 | socket->read_sequence_number += packet; | 2108 | socket->read_sequence_number += sequence_increase; |
2098 | 2109 | ||
2099 | /* Set read_offset */ | 2110 | /* Set read_offset */ |
2100 | socket->read_offset += packet; | 2111 | offset_increase = socket->receive_buffer_boundaries[sequence_increase-1]; |
2101 | 2112 | socket->read_offset += offset_increase; | |
2102 | /* FIXME: Fix relative calucations in receive buffer management */ | 2113 | |
2114 | /* Fix relative boundaries */ | ||
2115 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) | ||
2116 | { | ||
2117 | if (packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH - sequence_increase) | ||
2118 | { | ||
2119 | socket->receive_buffer_boundaries[packet] = | ||
2120 | socket->receive_buffer_boundaries[packet + sequence_increase] | ||
2121 | - offset_increase; | ||
2122 | } | ||
2123 | else | ||
2124 | socket->receive_buffer_boundaries[packet] = 0; | ||
2125 | } | ||
2103 | } | 2126 | } |
2104 | 2127 | ||
2105 | return read_handle; | 2128 | return read_handle; |