* Small optimization for set_timer(): now only removes the timer from the list

if it won't be added anymore.
* Small fix for set_timer(): now set the timer->due field back to 0 when a
  timer is removed - this prevented a timer from being correctly readded later
  (possible crash)!
* net_buffer's append_cloned_data() now does some more checks to prevent unnecessary
  work and detect wrong arguments.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19375 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-11-26 23:18:36 +00:00
parent 8449c78396
commit fc8c0ec946
2 changed files with 11 additions and 5 deletions

View File

@ -845,12 +845,15 @@ status_t
append_cloned_data(net_buffer *_buffer, net_buffer *_source, uint32 offset, append_cloned_data(net_buffer *_buffer, net_buffer *_source, uint32 offset,
size_t bytes) size_t bytes)
{ {
if (bytes == 0)
return B_OK;
net_buffer_private *buffer = (net_buffer_private *)_buffer; net_buffer_private *buffer = (net_buffer_private *)_buffer;
net_buffer_private *source = (net_buffer_private *)_source; net_buffer_private *source = (net_buffer_private *)_source;
TRACE(("append_cloned_data(buffer %p, source %p, offset = %ld, bytes = %ld)\n", TRACE(("append_cloned_data(buffer %p, source %p, offset = %ld, bytes = %ld)\n",
buffer, source, offset, bytes)); buffer, source, offset, bytes));
if (source->size < offset + bytes) if (source->size < offset + bytes || source->size < offset)
return B_BAD_VALUE; return B_BAD_VALUE;
// find data_node to start with from the source buffer // find data_node to start with from the source buffer

View File

@ -300,15 +300,18 @@ set_timer(net_timer *timer, bigtime_t delay)
{ {
BenaphoreLocker locker(sTimerLock); BenaphoreLocker locker(sTimerLock);
if (timer->due > 0) { if (timer->due > 0 && delay < 0) {
// this timer is already scheduled, cancel it // this timer is scheduled, cancel it
list_remove_item(&sTimers, timer); list_remove_item(&sTimers, timer);
timer->due = 0;
} }
if (delay >= 0) { if (delay >= 0) {
// add this timer // reschedule or add this timer
if (timer->due <= 0)
list_add_item(&sTimers, timer);
timer->due = system_time() + delay; timer->due = system_time() + delay;
list_add_item(&sTimers, timer);
// notify timer about the change if necessary // notify timer about the change if necessary
if (sTimerTimeout > timer->due) if (sTimerTimeout > timer->due)