flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.19k stars 27.49k forks source link

How to set socket option name SO_RCVBUF? #89160

Closed YowFung closed 3 years ago

YowFung commented 3 years ago

Only the tcpNoDelay is supported? How do I set other socket option names such as SO_RCVBUF?


In file <Flutter SDK>/bin/cache/pkg/sky_engine/lib/io/socket.dart

/// An option for a socket which is configured using [Socket.setOption].
///
/// The [SocketOption] is used as a parameter to [Socket.setOption] and
/// [RawSocket.setOption] to customize the behaviour of the underlying
/// socket.
class SocketOption {
  /// Enable or disable no-delay on the socket. If tcpNoDelay is enabled, the
  /// socket will not buffer data internally, but instead write each data chunk
  /// as an individual TCP packet.
  ///
  /// tcpNoDelay is disabled by default.
  static const SocketOption tcpNoDelay = const SocketOption._(0);
  @Deprecated("Use tcpNoDelay instead")
  static const SocketOption TCP_NODELAY = tcpNoDelay;

  static const SocketOption _ipMulticastLoop = const SocketOption._(1);
  static const SocketOption _ipMulticastHops = const SocketOption._(2);
  static const SocketOption _ipMulticastIf = const SocketOption._(3);
  static const SocketOption _ipBroadcast = const SocketOption._(4);

  final _value;

  const SocketOption._(this._value);
}
// Must be kept in sync with enum in socket.cc
enum _RawSocketOptions {
  SOL_SOCKET, // 0
  IPPROTO_IP, // 1
  IP_MULTICAST_IF, // 2
  IPPROTO_IPV6, // 3
  IPV6_MULTICAST_IF, // 4
  IPPROTO_TCP, // 5
  IPPROTO_UDP, // 6
}
mraleph commented 3 years ago

You can set arbitrary socket options through setRawOption which takes an instance of RawSocketOption, you just need to use correct values for level and option, e.g. on Android I think this will be RawSocketOption.fromInt(/*SOL_SOCKET*/ 1, /*SO_RCVBUF*/ 8, bufSize) on iOS that would be RawSocketOption.fromInt(/*SOL_SOCKET*/ 0xFFFF, /*SO_RCVBUF*/ 0x1002, bufSize) (but you should double check respective socket.h headers on each of those platforms).

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.