Changeset 0093ab6 in mainline for uspace/srv/net/tl/tcp/segment.c
- Timestamp:
- 2011-09-21T19:56:41Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 032bbe7
- Parents:
- 4c55a64
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/segment.c
r4c55a64 r0093ab6 35 35 */ 36 36 37 #include <mem.h> 37 38 #include <stdlib.h> 38 39 #include "segment.h" … … 79 80 } 80 81 81 size_t tcp_segment_data_len(tcp_segment_t *seg) 82 /** Trim segment to the specified interval. 83 * 84 * Trim any text or control whose sequence number is outside of [lo, hi) 85 * interval. 86 */ 87 void tcp_segment_trim(tcp_segment_t *seg, uint32_t left, uint32_t right) 88 { 89 uint32_t t_size; 90 91 assert(left + right <= seg->len); 92 93 /* Special case, entire segment trimmed from left */ 94 if (left == seg->len) { 95 seg->seq = seg->seq + seg->len; 96 seg->len = 0; 97 return; 98 } 99 100 /* Special case, entire segment trimmed from right */ 101 if (right == seg->len) { 102 seg->len = 0; 103 return; 104 } 105 106 /* General case */ 107 108 t_size = tcp_segment_text_size(seg); 109 110 if (left > 0 && (seg->ctrl & CTL_SYN) != 0) { 111 /* Trim SYN */ 112 seg->ctrl &= ~CTL_SYN; 113 seg->seq++; 114 seg->len--; 115 left--; 116 } 117 118 if (right > 0 && (seg->ctrl & CTL_FIN) != 0) { 119 /* Trim FIN */ 120 seg->ctrl &= ~CTL_FIN; 121 seg->len--; 122 right--; 123 } 124 125 if (left > 0 || right > 0) { 126 /* Trim segment text */ 127 assert(left + right <= t_size); 128 129 seg->data += left; 130 seg->len -= left + right; 131 } 132 } 133 134 /** Copy out text data from segment. 135 * 136 */ 137 void tcp_segment_text_copy(tcp_segment_t *seg, void *buf, size_t size) 138 { 139 assert(size <= tcp_segment_text_size(seg)); 140 memcpy(buf, seg->data, size); 141 } 142 143 /** Return number of bytes in segment text. */ 144 size_t tcp_segment_text_size(tcp_segment_t *seg) 82 145 { 83 146 return seg->len - seq_no_control_len(seg->ctrl);
Note:
See TracChangeset
for help on using the changeset viewer.