since: 2.36


g_socket_set_option (
  GSocket* socket,
  gint level,
  gint optname,
  gint value,
  GError** error


Sets the value of an integer-valued option on socket, as with setsockopt(). (If you need to set a non-integer-valued option, you will need to call setsockopt() directly.)

The [][gio-gnetworking.h] header pulls in system headers that will define most of the standard/portable socket options. For unusual socket protocols or platform-dependent options, you may need to include additional headers.

Available since: 2.36



Type: gint

The “API level” of the option (eg, SOL_SOCKET)


Type: gint

The “name” of the option (eg, SO_BROADCAST)


Type: gint

The value to set the option to.


Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will left initialized to NULL by the method if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: gboolean

Success or failure. On failure, error will be set, and the system error value (errno or WSAGetLastError()) will still be set to the result of the setsockopt() call.