Skip to content

Commit

Permalink
Use the threadpool for sending - posttask is too slow
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Nov 5, 2024
1 parent b6dc165 commit b8fff2a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions net/socket/udp_socket_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "net/socket/udp_socket_starboard.h"

#include <string.h>

#include "base/logging.h"
#include "base/rand_util.h"
#include "base/task/current_thread.h"
Expand Down Expand Up @@ -639,6 +641,22 @@ int UDPSocketStarboard::InternalSendTo(IOBuffer* buf,
return result;
}

if (!address) {
// Post a task to the threadpool to write the packet.
int result = OK;
scoped_refptr<IOBufferWithSize> packet =
base::MakeRefCounted<IOBufferWithSize>(buf_len);
memcpy(packet->data(), buf->data(), buf_len);
base::ThreadPool::PostTask(
FROM_HERE,
base::BindOnce(
[](SbSocket socket, scoped_refptr<IOBufferWithSize> packet) {
SbSocketSendTo(socket, packet->data(), packet->size(), nullptr);
},
socket_, packet));
return OK;
}
#endif
int result = SbSocketSendTo(socket_, buf->data(), buf_len,
address ? &sb_address : nullptr);

Expand Down

0 comments on commit b8fff2a

Please sign in to comment.