forked from premiere/premiere-libtorrent
merged utp fix from RC_0_16
This commit is contained in:
parent
5b3a075387
commit
ecc42c0a78
|
@ -10,6 +10,7 @@
|
||||||
* fix uTP edge case where udp socket buffer fills up
|
* fix uTP edge case where udp socket buffer fills up
|
||||||
* fix nagle implementation in uTP
|
* fix nagle implementation in uTP
|
||||||
|
|
||||||
|
* fix potential packet allocation alignment issue in utp
|
||||||
* make 'close_redudnant_connections' cover more cases
|
* make 'close_redudnant_connections' cover more cases
|
||||||
* set_piece_deadline() also unfilters the piece (if its priority is 0)
|
* set_piece_deadline() also unfilters the piece (if its priority is 0)
|
||||||
* add work-around for bug in windows vista and earlier in GetOverlappedResult
|
* add work-around for bug in windows vista and earlier in GetOverlappedResult
|
||||||
|
|
|
@ -54,6 +54,10 @@ namespace libtorrent
|
||||||
// in strict ansi mode
|
// in strict ansi mode
|
||||||
char* allocate_string_copy(char const* str);
|
char* allocate_string_copy(char const* str);
|
||||||
|
|
||||||
|
// returns p + x such that the pointer is 8 bytes aligned
|
||||||
|
// x cannot be greater than 7
|
||||||
|
void* align_pointer(void* p);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -130,5 +130,18 @@ namespace libtorrent
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 8-byte align pointer
|
||||||
|
void* align_pointer(void* p)
|
||||||
|
{
|
||||||
|
int offset = uintptr_t(p) & 0x7;
|
||||||
|
// if we're already aligned, don't do anything
|
||||||
|
if (offset == 0) return p;
|
||||||
|
|
||||||
|
// offset is how far passed the last aligned address
|
||||||
|
// we are. We need to go forward to the next aligned
|
||||||
|
// one. Since aligned addresses are 8 bytes apart, add
|
||||||
|
// 8 - offset.
|
||||||
|
return static_cast<char*>(p) + (8 - offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1682,9 +1682,11 @@ bool utp_socket_impl::send_pkt(int flags)
|
||||||
stack_alloced = true;
|
stack_alloced = true;
|
||||||
#endif
|
#endif
|
||||||
TORRENT_ASSERT(force);
|
TORRENT_ASSERT(force);
|
||||||
// TODO: 3 this alloca() statement won't necessarily produce
|
// this alloca() statement won't necessarily produce
|
||||||
// correctly aligned memory. do something about that
|
// correctly aligned memory. That's why we ask for 7 more bytes
|
||||||
p = (packet*)TORRENT_ALLOCA(char, sizeof(packet) + packet_size);
|
// and adjust our pointer to be aligned later
|
||||||
|
p = (packet*)TORRENT_ALLOCA(char, sizeof(packet) + packet_size + 7);
|
||||||
|
p = (packet*)align_pointer(p);
|
||||||
UTP_LOGV("%8p: allocating %d bytes on the stack\n", this, packet_size);
|
UTP_LOGV("%8p: allocating %d bytes on the stack\n", this, packet_size);
|
||||||
p->allocated = packet_size;
|
p->allocated = packet_size;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue