summaryrefslogtreecommitdiff
path: root/ot_iovec.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_iovec.c')
-rw-r--r--ot_iovec.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/ot_iovec.c b/ot_iovec.c
index a098733..f71d4d7 100644
--- a/ot_iovec.c
+++ b/ot_iovec.c
@@ -34,23 +34,36 @@ void iovec_free( int *iovec_entries, struct iovec **iovector ) {
34 *iovec_entries = 0; 34 *iovec_entries = 0;
35} 35}
36 36
37void iovec_fixlast( int *iovec_entries, struct iovec **iovector, size_t new_alloc ) { 37void iovec_fixlast( int *iovec_entries, struct iovec **iovector, void *last_ptr ) {
38 int page_size = getpagesize(); 38 int page_size = getpagesize();
39 size_t old_alloc, old_pages, new_pages; 39 size_t old_alloc, new_alloc, old_pages, new_pages;
40 char * base = (char*)((*iovector)[ *iovec_entries - 1 ]).iov_base;
40 41
41 if( !*iovec_entries ) return; 42 if( !*iovec_entries ) return;
42 43
43 old_alloc = ((*iovector)[ *iovec_entries - 1 ]).iov_len; 44 old_alloc = ((*iovector)[ *iovec_entries - 1 ]).iov_len;
45 new_alloc = ((char*)last_ptr) - base;
44 old_pages = 1 + old_alloc / page_size; 46 old_pages = 1 + old_alloc / page_size;
45 new_pages = 1 + new_alloc / page_size; 47 new_pages = 1 + new_alloc / page_size;
46 48
47 if( old_pages != new_pages ) { 49 if( old_pages != new_pages ) {
48 munmap( ((char*)((*iovector)[ *iovec_entries - 1 ]).iov_base ) + new_pages * page_size, 50 munmap( base + new_pages * page_size, old_alloc - new_pages * page_size );
49 old_alloc - new_pages * page_size );
50 } 51 }
51 ((*iovector)[*iovec_entries - 1 ]).iov_len = new_alloc; 52 ((*iovector)[*iovec_entries - 1 ]).iov_len = new_alloc;
52} 53}
53 54
55void *iovec_fix_increase_or_free( int *iovec_entries, struct iovec **iovector, void *last_ptr, size_t new_alloc ) {
56 void *new_ptr;
57
58 iovec_fixlast( iovec_entries, iovector, last_ptr );
59
60 if( !( new_ptr = iovec_increase( iovec_entries, iovector, new_alloc ) ) )
61 iovec_free( iovec_entries, iovector );
62
63 return new_ptr;
64}
65
66
54size_t iovec_length( int *iovec_entries, struct iovec **iovector ) { 67size_t iovec_length( int *iovec_entries, struct iovec **iovector ) {
55 size_t length = 0; 68 size_t length = 0;
56 int i; 69 int i;