(trunk libT) #4209 "Shortcut UDP tracker test" -- the goal of #4209 is to minimize the cost of the UDP event callback function, so apply the heap pruning eye to that by removing an unnecessary malloc/free call there.
Previously we allocated a 4096 character buffer each time; now we allocate it on the stack. It seems all the distros and OS flavors that Transmission runs on have multi-MB default stack sizes, so a hardwired 4K array should be safe.
This commit is contained in:
parent
e7c76b06ee
commit
ea3fe42ca3
|
@ -188,7 +188,7 @@ static void
|
|||
event_callback(int s, short type UNUSED, void *sv)
|
||||
{
|
||||
tr_session *ss = sv;
|
||||
unsigned char *buf;
|
||||
unsigned char buf[4096];
|
||||
struct sockaddr_storage from;
|
||||
socklen_t fromlen;
|
||||
int rc;
|
||||
|
@ -196,12 +196,6 @@ event_callback(int s, short type UNUSED, void *sv)
|
|||
assert(tr_isSession(sv));
|
||||
assert(type == EV_READ);
|
||||
|
||||
buf = malloc(4096);
|
||||
if(buf == NULL) {
|
||||
tr_nerr("UDP", "Couldn't allocate buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
fromlen = sizeof(from);
|
||||
rc = recvfrom(s, buf, 4096 - 1, 0,
|
||||
(struct sockaddr*)&from, &fromlen);
|
||||
|
@ -228,8 +222,6 @@ event_callback(int s, short type UNUSED, void *sv)
|
|||
tr_ndbg("UDP", "Unexpected UDP packet");
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue