servlib/bundling/BPQCacheEntry.cc
changeset 64 1296a0283271
parent 58 574358af597b
child 66 e1101c5d54a1
equal deleted inserted replaced
63:9a8be24c5037 64:1296a0283271
     1 /*
     1 /*
     2  *    Copyright 2004-2006 Intel Corporation
     2  *    Copyright 2010-2011 Trinity College Dublin
     3  *
     3  *
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
     5  *    you may not use this file except in compliance with the License.
     5  *    you may not use this file except in compliance with the License.
     6  *    You may obtain a copy of the License at
     6  *    You may obtain a copy of the License at
     7  *
     7  *
    22 int
    22 int
    23 BPQCacheEntry::add_response(Bundle* bundle)
    23 BPQCacheEntry::add_response(Bundle* bundle)
    24 {
    24 {
    25 	if ( ! bundle->is_fragment() ) {
    25 	if ( ! bundle->is_fragment() ) {
    26 		log_debug("add complete response to cache entry");
    26 		log_debug("add complete response to cache entry");
       
    27 
    27 		fragments_.insert_sorted(bundle, BundleList::SORT_FRAG_OFFSET);
    28 		fragments_.insert_sorted(bundle, BundleList::SORT_FRAG_OFFSET);
    28 		is_complete_ = true;
    29 		is_complete_ = true;
    29 
    30 
    30 	} else if ( bundle->is_fragment() && ! is_complete_ ) {
    31 	} else if ( bundle->is_fragment() && ! is_complete_ ) {
    31 		log_debug("add response fragment to cache entry");
    32 		log_debug("add response fragment to cache entry");
       
    33 
    32 		fragments_.insert_sorted(bundle, BundleList::SORT_FRAG_OFFSET);
    34 		fragments_.insert_sorted(bundle, BundleList::SORT_FRAG_OFFSET);
    33 		is_complete_ = check_complete();
    35 		is_complete_ = check_complete();
    34 
    36 
    35 	} else if ( bundle->is_fragment() && is_complete_ ) {
    37 	} else if ( bundle->is_fragment() && is_complete_ ) {
    36 		log_debug("ignoring response fragment as cache entry is complete");
    38 		log_debug("ignoring response fragment as cache entry is complete");
    37 
    39 
       
    40 	} else {
       
    41 		NOTREACHED;
    38 	}
    42 	}
    39 
    43 
    40 	return BP_SUCCESS;
    44 	return BP_SUCCESS;
    41 }
    45 }
    42 
    46 
    43 //----------------------------------------------------------------------
    47 //----------------------------------------------------------------------
    44 int
    48 int
    45 BPQCacheEntry::reassemble_fragments(){
    49 BPQCacheEntry::reassemble_fragments(Bundle* new_bundle, const Bundle* meta_bundle){
    46 	//TODO: implement this
    50 	//TODO: implement this
    47 	NOTIMPLEMENTED;
    51 	NOTIMPLEMENTED;
    48 	return BP_FAIL;
    52 	return BP_FAIL;
    49 }
    53 }
    50 
    54 
    60     size_t done_up_to = 0;  // running total of completed reassembly
    64     size_t done_up_to = 0;  // running total of completed reassembly
    61     size_t f_len;
    65     size_t f_len;
    62     size_t f_offset;
    66     size_t f_offset;
    63     size_t f_origlen;
    67     size_t f_origlen;
    64 
    68 
    65     size_t total_len = bundle_->payload().length();
    69 //    size_t total_len = bundle_->payload().length();
    66 
    70 
    67     int fragi = 0;
    71     int fragi = 0;
    68     int fragn = fragments_.size();
    72     int fragn = fragments_.size();
    69     (void)fragn; // in case NDEBUG is defined
    73     (void)fragn; // in case NDEBUG is defined
    70 
    74 
    78         f_offset = fragment->frag_offset();
    82         f_offset = fragment->frag_offset();
    79         f_origlen = fragment->orig_length();
    83         f_origlen = fragment->orig_length();
    80 
    84 
    81         ASSERT(fragment->is_fragment());
    85         ASSERT(fragment->is_fragment());
    82 
    86 
    83         if (f_origlen != total_len) {
    87         if (f_origlen != total_len_) {
    84             PANIC("check_completed: error fragment orig len %zu != total %zu",
    88             PANIC("check_completed: error fragment orig len %zu != total %zu",
    85                   f_origlen, total_len);
    89                   f_origlen, total_len_);
    86             // XXX/demmer deal with this
    90             // XXX/demmer deal with this
    87         }
    91         }
    88 
    92 
    89         if (done_up_to == f_offset) {
    93         if (done_up_to == f_offset) {
    90             /*
    94             /*
   144             // all cases should be covered above
   148             // all cases should be covered above
   145             NOTREACHED;
   149             NOTREACHED;
   146         }
   150         }
   147     }
   151     }
   148 
   152 
   149     if (done_up_to == total_len) {
   153     if (done_up_to == total_len_) {
   150         log_debug("check_completed reassembly complete!");
   154         log_debug("check_completed reassembly complete!");
   151         return true;
   155         return true;
   152     } else {
   156     } else {
   153         log_debug("check_completed reassembly not done (got %zu/%zu)",
   157         log_debug("check_completed reassembly not done (got %zu/%zu)",
   154                   done_up_to, total_len);
   158                   done_up_to, total_len_);
   155         return false;
   159         return false;
   156     }
   160     }
   157 }
   161 }
   158 
   162 
   159 
   163