@@ -35,7 +35,6 @@ extern char* heap_end;
3535namespace liu
3636{
3737static void resume_begin (storage_header&, std::string, LiveUpdate::resume_func);
38- static std::map<uint16_t , LiveUpdate::resume_func> resume_funcs;
3938
4039bool LiveUpdate::is_resumable ()
4140{
@@ -82,40 +81,19 @@ void resume_begin(storage_header& storage, std::string key, LiveUpdate::resume_f
8281 LPRINT (" * Resuming from partition %d at %p from %p\n " ,
8382 p, storage.begin (p), &storage);
8483
85- // / restore each entry one by one, calling registered handlers
86- for (auto * ptr = storage.begin (p); ptr->type != TYPE_END;)
87- {
88- auto * oldptr = ptr;
89- // resume wrapper
90- Restore wrapper {ptr};
91- // use registered functions when we can, otherwise, use normal
92- auto it = resume_funcs.find (ptr->id );
93- if (it != resume_funcs.end ())
94- {
95- it->second (wrapper);
96- } else {
97- func (wrapper);
98- }
99- // if we are already at the end due calls to go_next, break early
100- if (ptr->type == TYPE_END) break ;
101- // call next manually only when no one called go_next
102- if (oldptr == ptr) ptr = storage.next (ptr);
103- }
84+ // resume wrapper
85+ Restore wrapper (storage.begin (p));
86+ // use registered functions when we can, otherwise, use normal
87+ func (wrapper);
88+
10489 // wake all the slumbering IP stacks
10590 serialized_tcp::wakeup_ip_networks ();
106- // clear registered resume callbacks
107- resume_funcs.clear ();
10891 // zero out the partition for security reasons
10992 storage.zero_partition (p);
11093 // if there are no more partitions, clear everything
11194 storage.try_zero ();
11295}
11396
114- void LiveUpdate::on_resume (uint16_t id, resume_func func)
115- {
116- resume_funcs[id] = func;
117- }
118-
11997// / struct Restore
12098
12199bool Restore::is_end () const noexcept
@@ -136,13 +114,13 @@ int Restore::as_int() const
136114 // this type uses the length field directly as value to save space
137115 if (ent->type == TYPE_INTEGER)
138116 return ent->len ;
139- throw std::runtime_error (" Incorrect type: " + std::to_string (ent->type ));
117+ throw std::runtime_error (" LiveUpdate: Incorrect type " + std::to_string (ent->type ));
140118}
141119std::string Restore::as_string () const
142120{
143121 if (ent->type == TYPE_STRING)
144122 return std::string (ent->data (), ent->len );
145- throw std::runtime_error (" Incorrect type: " + std::to_string (ent->type ));
123+ throw std::runtime_error (" LiveUpdate: Incorrect type " + std::to_string (ent->type ));
146124}
147125buffer_t Restore::as_buffer () const
148126{
@@ -151,7 +129,7 @@ buffer_t Restore::as_buffer() const
151129 buffer.assign (ent->data (), ent->data () + ent->len );
152130 return buffer;
153131 }
154- throw std::runtime_error (" Incorrect type: " + std::to_string (ent->type ));
132+ throw std::runtime_error (" LiveUpdate: Incorrect type " + std::to_string (ent->type ));
155133}
156134Restore::Connection_ptr Restore::as_tcp_connection (net::TCP& tcp) const
157135{
@@ -177,19 +155,19 @@ const void* Restore::data() const noexcept
177155const void * Restore::get_segment (size_t size, size_t & count) const
178156{
179157 if (ent->type != TYPE_VECTOR)
180- throw std::runtime_error (" Incorrect type: " + std::to_string (ent->type ));
158+ throw std::runtime_error (" LiveUpdate: Incorrect type " + std::to_string (ent->type ));
181159
182160 auto & segs = ent->get_segs ();
183161 if (size != segs.esize )
184- throw std::runtime_error (" Incorrect type size: " + std::to_string (size) + " vs " + std::to_string (segs.esize ));
162+ throw std::runtime_error (" LiveUpdate: Incorrect type size " + std::to_string (size) + " vs " + std::to_string (segs.esize ));
185163
186164 count = segs.count ;
187165 return (const void *) segs.vla ;
188166}
189167std::vector<std::string> Restore::rebuild_string_vector () const
190168{
191169 if (ent->type != TYPE_STR_VECTOR)
192- throw std::runtime_error (" Incorrect type: " + std::to_string (ent->type ));
170+ throw std::runtime_error (" LiveUpdate: Incorrect type " + std::to_string (ent->type ));
193171 std::vector<std::string> retv;
194172 // reserve just enough room
195173 auto * begin = (varseg_begin*) ent->vla ;
@@ -210,7 +188,7 @@ std::vector<std::string> Restore::rebuild_string_vector() const
210188void Restore::go_next ()
211189{
212190 if (is_end ())
213- throw std::runtime_error (" Already reached end of storage " );
191+ throw std::out_of_range (" Already reached end of partition " );
214192 // increase the counter, so the resume loop skips entries properly
215193 ent = ent->next ();
216194}
@@ -236,18 +214,9 @@ void Restore::pop_marker(uint16_t id)
236214 && is_end () == false ) go_next ();
237215 if (is_marker ()) {
238216 if (get_id () != id)
239- throw std::runtime_error (" Ran past marker with another id: " + std::to_string (get_id ()));
217+ throw std::out_of_range (" Ran past marker with another id: " + std::to_string (get_id ()));
240218 go_next ();
241219 }
242220}
243221
244- void Restore::cancel ()
245- {
246- while (is_end () == false ) go_next ();
247- }
248-
249- // copy operator
250- Restore::Restore (const Restore& other)
251- : ent(other.ent) {}
252-
253- }
222+ } // liu
0 commit comments