Commit 3ae76ca8 authored by Yixin Wang's avatar Yixin Wang Committed by Commit Bot

Add SetMsgConfirm(bool) to udp_socket_posix and udp_socket_win

Bug: 818893
Change-Id: I58d04134464770368736cfb513a515d0debfead5
Reviewed-on: https://chromium-review.googlesource.com/956929Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Commit-Queue: Yixin Wang <wangyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543416}
parent ce5d0c20
...@@ -126,6 +126,8 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket { ...@@ -126,6 +126,8 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
int SetDoNotFragment() override { return net::OK; } int SetDoNotFragment() override { return net::OK; }
void SetMsgConfirm(bool confirm) override {}
void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) { void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) {
if (!recv_callback_.is_null()) { if (!recv_callback_.is_null()) {
int size = std::min(recv_size_, static_cast<int>(data.size())); int size = std::min(recv_size_, static_cast<int>(data.size()));
......
...@@ -79,6 +79,7 @@ class TestUDPClientSocket : public DatagramClientSocket { ...@@ -79,6 +79,7 @@ class TestUDPClientSocket : public DatagramClientSocket {
return NetworkChangeNotifier::kInvalidNetworkHandle; return NetworkChangeNotifier::kInvalidNetworkHandle;
} }
void ApplySocketTag(const SocketTag& tag) override {} void ApplySocketTag(const SocketTag& tag) override {}
void SetMsgConfirm(bool confirm) override {}
int Connect(const IPEndPoint& remote) override { int Connect(const IPEndPoint& remote) override {
if (connected_) if (connected_)
......
...@@ -45,6 +45,7 @@ class MockMDnsDatagramServerSocket : public DatagramServerSocket { ...@@ -45,6 +45,7 @@ class MockMDnsDatagramServerSocket : public DatagramServerSocket {
MOCK_METHOD1(SetReceiveBufferSize, int(int32_t size)); MOCK_METHOD1(SetReceiveBufferSize, int(int32_t size));
MOCK_METHOD1(SetSendBufferSize, int(int32_t size)); MOCK_METHOD1(SetSendBufferSize, int(int32_t size));
MOCK_METHOD0(SetDoNotFragment, int()); MOCK_METHOD0(SetDoNotFragment, int());
MOCK_METHOD1(SetMsgConfirm, void(bool confirm));
MOCK_METHOD0(Close, void()); MOCK_METHOD0(Close, void());
......
...@@ -45,6 +45,10 @@ class NET_EXPORT_PRIVATE DatagramSocket { ...@@ -45,6 +45,10 @@ class NET_EXPORT_PRIVATE DatagramSocket {
// return ERR_IO_PENDING. // return ERR_IO_PENDING.
virtual int SetDoNotFragment() = 0; virtual int SetDoNotFragment() = 0;
// If |confirm| is true, then the MSG_CONFIRM flag will be passed to
// subsequent writes if it's supported by the platform.
virtual void SetMsgConfirm(bool confirm) = 0;
// Gets the NetLog for this socket. // Gets the NetLog for this socket.
virtual const NetLogWithSource& NetLog() const = 0; virtual const NetLogWithSource& NetLog() const = 0;
}; };
......
...@@ -59,6 +59,7 @@ class FuzzedDatagramClientSocket : public DatagramClientSocket { ...@@ -59,6 +59,7 @@ class FuzzedDatagramClientSocket : public DatagramClientSocket {
int SetReceiveBufferSize(int32_t size) override; int SetReceiveBufferSize(int32_t size) override;
int SetSendBufferSize(int32_t size) override; int SetSendBufferSize(int32_t size) override;
int SetDoNotFragment() override; int SetDoNotFragment() override;
void SetMsgConfirm(bool confirm) override {}
private: private:
void OnReadComplete(const net::CompletionCallback& callback, int result); void OnReadComplete(const net::CompletionCallback& callback, int result);
......
...@@ -799,6 +799,7 @@ class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { ...@@ -799,6 +799,7 @@ class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
int ConnectUsingDefaultNetwork(const IPEndPoint& address) override; int ConnectUsingDefaultNetwork(const IPEndPoint& address) override;
NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override; NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override;
void ApplySocketTag(const SocketTag& tag) override; void ApplySocketTag(const SocketTag& tag) override;
void SetMsgConfirm(bool confirm) override {}
// AsyncSocket implementation. // AsyncSocket implementation.
void OnReadComplete(const MockRead& data) override; void OnReadComplete(const MockRead& data) override;
......
...@@ -119,6 +119,10 @@ int UDPClientSocket::SetDoNotFragment() { ...@@ -119,6 +119,10 @@ int UDPClientSocket::SetDoNotFragment() {
return socket_.SetDoNotFragment(); return socket_.SetDoNotFragment();
} }
void UDPClientSocket::SetMsgConfirm(bool confirm) {
socket_.SetMsgConfirm(confirm);
}
const NetLogWithSource& UDPClientSocket::NetLog() const { const NetLogWithSource& UDPClientSocket::NetLog() const {
return socket_.NetLog(); return socket_.NetLog();
} }
......
...@@ -49,6 +49,7 @@ class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket { ...@@ -49,6 +49,7 @@ class NET_EXPORT_PRIVATE UDPClientSocket : public DatagramClientSocket {
int SetReceiveBufferSize(int32_t size) override; int SetReceiveBufferSize(int32_t size) override;
int SetSendBufferSize(int32_t size) override; int SetSendBufferSize(int32_t size) override;
int SetDoNotFragment() override; int SetDoNotFragment() override;
void SetMsgConfirm(bool confirm) override;
const NetLogWithSource& NetLog() const override; const NetLogWithSource& NetLog() const override;
void EnableRecvOptimization() override; void EnableRecvOptimization() override;
......
...@@ -67,6 +67,10 @@ int UDPServerSocket::SetDoNotFragment() { ...@@ -67,6 +67,10 @@ int UDPServerSocket::SetDoNotFragment() {
return socket_.SetDoNotFragment(); return socket_.SetDoNotFragment();
} }
void UDPServerSocket::SetMsgConfirm(bool confirm) {
return socket_.SetMsgConfirm(confirm);
}
void UDPServerSocket::Close() { void UDPServerSocket::Close() {
socket_.Close(); socket_.Close();
} }
......
...@@ -39,6 +39,7 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket { ...@@ -39,6 +39,7 @@ class NET_EXPORT UDPServerSocket : public DatagramServerSocket {
int SetReceiveBufferSize(int32_t size) override; int SetReceiveBufferSize(int32_t size) override;
int SetSendBufferSize(int32_t size) override; int SetSendBufferSize(int32_t size) override;
int SetDoNotFragment() override; int SetDoNotFragment() override;
void SetMsgConfirm(bool confirm) override;
void Close() override; void Close() override;
int GetPeerAddress(IPEndPoint* address) const override; int GetPeerAddress(IPEndPoint* address) const override;
int GetLocalAddress(IPEndPoint* address) const override; int GetLocalAddress(IPEndPoint* address) const override;
......
...@@ -199,6 +199,7 @@ UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type, ...@@ -199,6 +199,7 @@ UDPSocketPosix::UDPSocketPosix(DatagramSocket::BindType bind_type,
addr_family_(0), addr_family_(0),
is_connected_(false), is_connected_(false),
socket_options_(SOCKET_OPTION_MULTICAST_LOOP), socket_options_(SOCKET_OPTION_MULTICAST_LOOP),
sendto_flags_(0),
multicast_interface_(0), multicast_interface_(0),
multicast_time_to_live_(1), multicast_time_to_live_(1),
bind_type_(bind_type), bind_type_(bind_type),
...@@ -649,6 +650,16 @@ int UDPSocketPosix::SetDoNotFragment() { ...@@ -649,6 +650,16 @@ int UDPSocketPosix::SetDoNotFragment() {
#endif #endif
} }
void UDPSocketPosix::SetMsgConfirm(bool confirm) {
#if !defined(OS_MACOSX) && !defined(OS_IOS)
if (confirm) {
sendto_flags_ |= MSG_CONFIRM;
} else {
sendto_flags_ &= ~MSG_CONFIRM;
}
#endif // !defined(OS_MACOSX) && !defined(OS_IOS)
}
int UDPSocketPosix::AllowAddressReuse() { int UDPSocketPosix::AllowAddressReuse() {
DCHECK_NE(socket_, kInvalidSocket); DCHECK_NE(socket_, kInvalidSocket);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
...@@ -867,12 +878,8 @@ int UDPSocketPosix::InternalSendTo(IOBuffer* buf, ...@@ -867,12 +878,8 @@ int UDPSocketPosix::InternalSendTo(IOBuffer* buf,
} }
} }
int result = HANDLE_EINTR(sendto(socket_, int result = HANDLE_EINTR(sendto(socket_, buf->data(), buf_len, sendto_flags_,
buf->data(), addr, storage.addr_len));
buf_len,
0,
addr,
storage.addr_len));
if (result < 0) if (result < 0)
result = MapSystemError(errno); result = MapSystemError(errno);
if (result != ERR_IO_PENDING) if (result != ERR_IO_PENDING)
......
...@@ -177,6 +177,10 @@ class NET_EXPORT UDPSocketPosix { ...@@ -177,6 +177,10 @@ class NET_EXPORT UDPSocketPosix {
// return ERR_IO_PENDING. // return ERR_IO_PENDING.
int SetDoNotFragment(); int SetDoNotFragment();
// If |confirm| is true, then the MSG_CONFIRM flag will be passed to
// subsequent writes if it's supported by the platform.
void SetMsgConfirm(bool confirm);
// Returns true if the socket is already connected or bound. // Returns true if the socket is already connected or bound.
bool is_connected() const { return is_connected_; } bool is_connected() const { return is_connected_; }
...@@ -354,6 +358,9 @@ class NET_EXPORT UDPSocketPosix { ...@@ -354,6 +358,9 @@ class NET_EXPORT UDPSocketPosix {
// options that should be applied to |socket_| before Bind(). // options that should be applied to |socket_| before Bind().
int socket_options_; int socket_options_;
// Flags passed to sendto().
int sendto_flags_;
// Multicast interface. // Multicast interface.
uint32_t multicast_interface_; uint32_t multicast_interface_;
......
...@@ -567,6 +567,8 @@ int UDPSocketWin::SetDoNotFragment() { ...@@ -567,6 +567,8 @@ int UDPSocketWin::SetDoNotFragment() {
return rv == 0 ? OK : MapSystemError(WSAGetLastError()); return rv == 0 ? OK : MapSystemError(WSAGetLastError());
} }
void UDPSocketWin::SetMsgConfirm(bool confirm) {}
int UDPSocketWin::AllowAddressReuse() { int UDPSocketWin::AllowAddressReuse() {
DCHECK_NE(socket_, INVALID_SOCKET); DCHECK_NE(socket_, INVALID_SOCKET);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......
...@@ -137,6 +137,9 @@ class NET_EXPORT UDPSocketWin : public base::win::ObjectWatcher::Delegate { ...@@ -137,6 +137,9 @@ class NET_EXPORT UDPSocketWin : public base::win::ObjectWatcher::Delegate {
// return ERR_IO_PENDING. // return ERR_IO_PENDING.
int SetDoNotFragment(); int SetDoNotFragment();
// This is a no-op on Windows.
void SetMsgConfirm(bool confirm);
// Returns true if the socket is already connected or bound. // Returns true if the socket is already connected or bound.
bool is_connected() const { return is_connected_; } bool is_connected() const { return is_connected_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment