blob: 6846bf500a7bf6126374c8f9c9c5c7a73fe06973 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GSocket: GIO Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GIO Reference Manual">
<link rel="up" href="networking.html" title="Low-level network support">
<link rel="prev" href="networking.html" title="Low-level network support">
<link rel="next" href="GDatagramBased.html" title="GDatagramBased">
<meta name="generator" content="GTK-Doc V1.25.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts">
<a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
<a href="#GSocket.description" class="shortcut">Description</a></span><span id="nav_hierarchy">  <span class="dim">|</span> 
<a href="#GSocket.object-hierarchy" class="shortcut">Object Hierarchy</a></span><span id="nav_interfaces">  <span class="dim">|</span> 
<a href="#GSocket.implemented-interfaces" class="shortcut">Implemented Interfaces</a></span><span id="nav_properties">  <span class="dim">|</span> 
<a href="#GSocket.properties" class="shortcut">Properties</a></span>
</td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="networking.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="networking.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="GDatagramBased.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="GSocket"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="GSocket.top_of_page"></a>GSocket</span></h2>
<p>GSocket — Low-level socket object</p>
</td>
<td class="gallery_image" valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="GSocket.functions"></a><h2>Functions</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="functions_return">
<col class="functions_name">
</colgroup>
<tbody>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<span class="c_punctuation">(</span><a class="link" href="GSocket.html#GSocketSourceFunc" title="GSocketSourceFunc ()">*GSocketSourceFunc</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-new" title="g_socket_new ()">g_socket_new</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-new-from-fd" title="g_socket_new_from_fd ()">g_socket_new_from_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()">g_socket_bind</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-listen" title="g_socket_listen ()">g_socket_listen</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()">g_socket_accept</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-connect" title="g_socket_connect ()">g_socket_connect</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-check-connect-result" title="g_socket_check_connect_result ()">g_socket_check_connect_result</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()">g_socket_receive</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-receive-from" title="g_socket_receive_from ()">g_socket_receive_from</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-receive-message" title="g_socket_receive_message ()">g_socket_receive_message</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-receive-messages" title="g_socket_receive_messages ()">g_socket_receive_messages</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-receive-with-blocking" title="g_socket_receive_with_blocking ()">g_socket_receive_with_blocking</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()">g_socket_send</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-send-to" title="g_socket_send_to ()">g_socket_send_to</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-send-message" title="g_socket_send_message ()">g_socket_send_message</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-send-messages" title="g_socket_send_messages ()">g_socket_send_messages</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-send-with-blocking" title="g_socket_send_with_blocking ()">g_socket_send_with_blocking</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-close" title="g_socket_close ()">g_socket_close</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-is-closed" title="g_socket_is_closed ()">g_socket_is_closed</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-shutdown" title="g_socket_shutdown ()">g_socket_shutdown</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-is-connected" title="g_socket_is_connected ()">g_socket_is_connected</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-The-Main-Event-Loop.html#GSource"><span class="returnvalue">GSource</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-create-source" title="g_socket_create_source ()">g_socket_create_source</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-IO-Channels.html#GIOCondition"><span class="returnvalue">GIOCondition</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-condition-check" title="g_socket_condition_check ()">g_socket_condition_check</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-condition-wait" title="g_socket_condition_wait ()">g_socket_condition_wait</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-condition-timed-wait" title="g_socket_condition_timed_wait ()">g_socket_condition_timed_wait</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-available-bytes" title="g_socket_get_available_bytes ()">g_socket_get_available_bytes</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-listen-backlog" title="g_socket_set_listen_backlog ()">g_socket_set_listen_backlog</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-listen-backlog" title="g_socket_get_listen_backlog ()">g_socket_get_listen_backlog</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-blocking" title="g_socket_get_blocking ()">g_socket_get_blocking</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-blocking" title="g_socket_set_blocking ()">g_socket_set_blocking</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-keepalive" title="g_socket_get_keepalive ()">g_socket_get_keepalive</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-keepalive" title="g_socket_set_keepalive ()">g_socket_set_keepalive</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-timeout" title="g_socket_get_timeout ()">g_socket_get_timeout</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-timeout" title="g_socket_set_timeout ()">g_socket_set_timeout</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-ttl" title="g_socket_set_ttl ()">g_socket_set_ttl</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-ttl" title="g_socket_get_ttl ()">g_socket_get_ttl</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-broadcast" title="g_socket_get_broadcast ()">g_socket_get_broadcast</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-broadcast" title="g_socket_set_broadcast ()">g_socket_set_broadcast</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-option" title="g_socket_get_option ()">g_socket_get_option</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-option" title="g_socket_set_option ()">g_socket_set_option</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocketAddress.html#GSocketFamily" title="enum GSocketFamily"><span class="returnvalue">GSocketFamily</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-family" title="g_socket_get_family ()">g_socket_get_family</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">int</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-fd" title="g_socket_get_fd ()">g_socket_get_fd</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="returnvalue">GSocketAddress</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-local-address" title="g_socket_get_local_address ()">g_socket_get_local_address</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol"><span class="returnvalue">GSocketProtocol</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-protocol" title="g_socket_get_protocol ()">g_socket_get_protocol</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="returnvalue">GSocketAddress</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-remote-address" title="g_socket_get_remote_address ()">g_socket_get_remote_address</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GSocket.html#GSocketType" title="enum GSocketType"><span class="returnvalue">GSocketType</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-socket-type" title="g_socket_get_socket_type ()">g_socket_get_socket_type</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-speaks-ipv4" title="g_socket_speaks_ipv4 ()">g_socket_speaks_ipv4</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a class="link" href="GCredentials.html" title="GCredentials"><span class="returnvalue">GCredentials</span></a> *
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-credentials" title="g_socket_get_credentials ()">g_socket_get_credentials</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-join-multicast-group" title="g_socket_join_multicast_group ()">g_socket_join_multicast_group</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-leave-multicast-group" title="g_socket_leave_multicast_group ()">g_socket_leave_multicast_group</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-multicast-loopback" title="g_socket_get_multicast_loopback ()">g_socket_get_multicast_loopback</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-multicast-loopback" title="g_socket_set_multicast_loopback ()">g_socket_set_multicast_loopback</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<a href="../glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-get-multicast-ttl" title="g_socket_get_multicast_ttl ()">g_socket_get_multicast_ttl</a> <span class="c_punctuation">()</span>
</td>
</tr>
<tr>
<td class="function_type">
<span class="returnvalue">void</span>
</td>
<td class="function_name">
<a class="link" href="GSocket.html#g-socket-set-multicast-ttl" title="g_socket_set_multicast_ttl ()">g_socket_set_multicast_ttl</a> <span class="c_punctuation">()</span>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="GSocket.properties"></a><h2>Properties</h2>
<div class="informaltable"><table class="informaltable" border="0">
<colgroup>
<col width="150px" class="properties_type">
<col width="300px" class="properties_name">
<col width="200px" class="properties_flags">
</colgroup>
<tbody>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--blocking" title="The “blocking” property">blocking</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--broadcast" title="The “broadcast” property">broadcast</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a class="link" href="GSocketAddress.html#GSocketFamily" title="enum GSocketFamily"><span class="type">GSocketFamily</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--family" title="The “family” property">family</a></td>
<td class="property_flags">Read / Write / Construct Only</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--fd" title="The “fd” property">fd</a></td>
<td class="property_flags">Read / Write / Construct Only</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--keepalive" title="The “keepalive” property">keepalive</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--listen-backlog" title="The “listen-backlog” property">listen-backlog</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type">
<a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *</td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--local-address" title="The “local-address” property">local-address</a></td>
<td class="property_flags">Read</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--multicast-loopback" title="The “multicast-loopback” property">multicast-loopback</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#guint"><span class="type">guint</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--multicast-ttl" title="The “multicast-ttl” property">multicast-ttl</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol"><span class="type">GSocketProtocol</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--protocol" title="The “protocol” property">protocol</a></td>
<td class="property_flags">Read / Write / Construct Only</td>
</tr>
<tr>
<td class="property_type">
<a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *</td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--remote-address" title="The “remote-address” property">remote-address</a></td>
<td class="property_flags">Read</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#guint"><span class="type">guint</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--timeout" title="The “timeout” property">timeout</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a href="../glib-Basic-Types.html#guint"><span class="type">guint</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--ttl" title="The “ttl” property">ttl</a></td>
<td class="property_flags">Read / Write</td>
</tr>
<tr>
<td class="property_type"><a class="link" href="GSocket.html#GSocketType" title="enum GSocketType"><span class="type">GSocketType</span></a></td>
<td class="property_name"><a class="link" href="GSocket.html#GSocket--type" title="The “type” property">type</a></td>
<td class="property_flags">Read / Write / Construct Only</td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="GSocket.other"></a><h2>Types and Values</h2>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="name">
<col class="description">
</colgroup>
<tbody>
<tr>
<td class="datatype_keyword"> </td>
<td class="function_name"><a class="link" href="GSocket.html#GSocket-struct" title="GSocket">GSocket</a></td>
</tr>
<tr>
<td class="datatype_keyword">enum</td>
<td class="function_name"><a class="link" href="GSocket.html#GSocketType" title="enum GSocketType">GSocketType</a></td>
</tr>
<tr>
<td class="datatype_keyword">enum</td>
<td class="function_name"><a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol">GSocketProtocol</a></td>
</tr>
<tr>
<td class="datatype_keyword">enum</td>
<td class="function_name"><a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags">GSocketMsgFlags</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="GSocket.html#GInputVector" title="struct GInputVector">GInputVector</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage">GInputMessage</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector">GOutputVector</a></td>
</tr>
<tr>
<td class="datatype_keyword">struct</td>
<td class="function_name"><a class="link" href="GSocket.html#GOutputMessage" title="struct GOutputMessage">GOutputMessage</a></td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect1">
<a name="GSocket.object-hierarchy"></a><h2>Object Hierarchy</h2>
<pre class="screen"> <a href="../gobject-The-Base-Object-Type.html#GObject-struct">GObject</a>
<span class="lineart">╰──</span> GSocket
</pre>
</div>
<div class="refsect1">
<a name="GSocket.implemented-interfaces"></a><h2>Implemented Interfaces</h2>
<p>
GSocket implements
<a class="link" href="GInitable.html" title="GInitable">GInitable</a> and <a class="link" href="GDatagramBased.html" title="GDatagramBased">GDatagramBased</a>.</p>
</div>
<div class="refsect1">
<a name="GSocket.includes"></a><h2>Includes</h2>
<pre class="synopsis">#include &lt;gio/gio.h&gt;
</pre>
</div>
<div class="refsect1">
<a name="GSocket.description"></a><h2>Description</h2>
<p>A <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> is a low-level networking primitive. It is a more or less
direct mapping of the BSD socket API in a portable GObject based API.
It supports both the UNIX socket implementations and winsock2 on Windows.</p>
<p><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> is the platform independent base upon which the higher level
network primitives are based. Applications are not typically meant to
use it directly, but rather through classes like <a class="link" href="GSocketClient.html" title="GSocketClient"><span class="type">GSocketClient</span></a>,
<a class="link" href="GSocketService.html" title="GSocketService"><span class="type">GSocketService</span></a> and <a class="link" href="GSocketConnection.html" title="GSocketConnection"><span class="type">GSocketConnection</span></a>. However there may be cases where
direct use of <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> is useful.</p>
<p><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> implements the <a class="link" href="GInitable.html" title="GInitable"><span class="type">GInitable</span></a> interface, so if it is manually constructed
by e.g. <a href="../gobject-The-Base-Object-Type.html#g-object-new"><code class="function">g_object_new()</code></a> you must call <a class="link" href="GInitable.html#g-initable-init" title="g_initable_init ()"><code class="function">g_initable_init()</code></a> and check the
results before using the object. This is done automatically in
<a class="link" href="GSocket.html#g-socket-new" title="g_socket_new ()"><code class="function">g_socket_new()</code></a> and <a class="link" href="GSocket.html#g-socket-new-from-fd" title="g_socket_new_from_fd ()"><code class="function">g_socket_new_from_fd()</code></a>, so these functions can return
<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</p>
<p>Sockets operate in two general modes, blocking or non-blocking. When
in blocking mode all operations (which don’t take an explicit blocking
parameter) block until the requested operation
is finished or there is an error. In non-blocking mode all calls that
would block return immediately with a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error.
To know when a call would successfully run you can call <a class="link" href="GSocket.html#g-socket-condition-check" title="g_socket_condition_check ()"><code class="function">g_socket_condition_check()</code></a>,
or <a class="link" href="GSocket.html#g-socket-condition-wait" title="g_socket_condition_wait ()"><code class="function">g_socket_condition_wait()</code></a>. You can also use <a class="link" href="GSocket.html#g-socket-create-source" title="g_socket_create_source ()"><code class="function">g_socket_create_source()</code></a> and
attach it to a <a href="../glib-The-Main-Event-Loop.html#GMainContext"><span class="type">GMainContext</span></a> to get callbacks when I/O is possible.
Note that all sockets are always set to non blocking mode in the system, and
blocking mode is emulated in GSocket.</p>
<p>When working in non-blocking mode applications should always be able to
handle getting a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error even when some other
function said that I/O was possible. This can easily happen in case
of a race condition in the application, but it can also happen for other
reasons. For instance, on Windows a socket is always seen as writable
until a write returns <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a>.</p>
<p><a href="GSocket.html#GSocket-struct"><span class="type">GSockets</span></a> can be either connection oriented or datagram based.
For connection oriented types you must first establish a connection by
either connecting to an address or accepting a connection from another
address. For connectionless socket types the target/source address is
specified or received in each I/O operation.</p>
<p>All socket file descriptors are set to be close-on-exec.</p>
<p>Note that creating a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> causes the signal <code class="literal">SIGPIPE</code> to be
ignored for the remainder of the program. If you are writing a
command-line utility that uses <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>, you may need to take into
account the fact that your program will not automatically be killed
if it tries to write to <code class="literal">stdout</code> after it has been closed.</p>
<p>Like most other APIs in GLib, <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> is not inherently thread safe. To use
a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> concurrently from multiple threads, you must implement your own
locking.</p>
</div>
<div class="refsect1">
<a name="GSocket.functions_details"></a><h2>Functions</h2>
<div class="refsect2">
<a name="GSocketSourceFunc"></a><h3>GSocketSourceFunc ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
<span class="c_punctuation">(</span>*GSocketSourceFunc<span class="c_punctuation">)</span> (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a href="../glib-IO-Channels.html#GIOCondition"><span class="type">GIOCondition</span></a> condition</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gpointer"><span class="type">gpointer</span></a> user_data</code></em>);</pre>
<p>This is the function type of the callback used for the <a href="../glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a>
returned by <a class="link" href="GSocket.html#g-socket-create-source" title="g_socket_create_source ()"><code class="function">g_socket_create_source()</code></a>.</p>
<div class="refsect3">
<a name="GSocketSourceFunc.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>the <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>condition</p></td>
<td class="parameter_description"><p>the current condition at the source fired.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>user_data</p></td>
<td class="parameter_description"><p>data passed in by the user.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="GSocketSourceFunc.returns"></a><h4>Returns</h4>
<p> it should return <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if the source should be removed.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-new"></a><h3>g_socket_new ()</h3>
<pre class="programlisting"><a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
g_socket_new (<em class="parameter"><code><a class="link" href="GSocketAddress.html#GSocketFamily" title="enum GSocketFamily"><span class="type">GSocketFamily</span></a> family</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GSocketType" title="enum GSocketType"><span class="type">GSocketType</span></a> type</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol"><span class="type">GSocketProtocol</span></a> protocol</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Creates a new <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> with the defined family, type and protocol.
If <em class="parameter"><code>protocol</code></em>
is 0 (<a class="link" href="GSocket.html#G-SOCKET-PROTOCOL-DEFAULT:CAPS"><code class="literal">G_SOCKET_PROTOCOL_DEFAULT</code></a>) the default protocol type
for the family and type is used.</p>
<p>The <em class="parameter"><code>protocol</code></em>
is a family and type specific int that specifies what
kind of protocol to use. <a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol"><span class="type">GSocketProtocol</span></a> lists several common ones.
Many families only support one protocol, and use 0 for this, others
support several and using 0 means to use the default protocol for
the family and type.</p>
<p>The protocol id is passed directly to the operating
system, so you can use protocols not listed in <a class="link" href="GSocket.html#GSocketProtocol" title="enum GSocketProtocol"><span class="type">GSocketProtocol</span></a> if you
know the protocol number used for it.</p>
<div class="refsect3">
<a name="g-socket-new.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>family</p></td>
<td class="parameter_description"><p>the socket family to use, e.g. <a class="link" href="GSocketAddress.html#G-SOCKET-FAMILY-IPV4:CAPS"><code class="literal">G_SOCKET_FAMILY_IPV4</code></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>type</p></td>
<td class="parameter_description"><p>the socket type to use.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>protocol</p></td>
<td class="parameter_description"><p>the id of the protocol to use, or 0 for default.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-new.returns"></a><h4>Returns</h4>
<p> a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.
Free the returned object with <a href="../gobject-The-Base-Object-Type.html#g-object-unref"><code class="function">g_object_unref()</code></a>.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-new-from-fd"></a><h3>g_socket_new_from_fd ()</h3>
<pre class="programlisting"><a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
g_socket_new_from_fd (<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> fd</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Creates a new <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> from a native file descriptor
or winsock SOCKET handle.</p>
<p>This reads all the settings from the file descriptor so that
all properties should work. Note that the file descriptor
will be set to non-blocking mode, independent on the blocking
mode of the <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>.</p>
<p>On success, the returned <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> takes ownership of <em class="parameter"><code>fd</code></em>
. On failure, the
caller must close <em class="parameter"><code>fd</code></em>
themselves.</p>
<p>Since GLib 2.46, it is no longer a fatal error to call this on a non-socket
descriptor. Instead, a GError will be set with code <a class="link" href="gio-GIOError.html#G-IO-ERROR-FAILED:CAPS"><code class="literal">G_IO_ERROR_FAILED</code></a></p>
<div class="refsect3">
<a name="g-socket-new-from-fd.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>fd</p></td>
<td class="parameter_description"><p>a native socket file descriptor.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-new-from-fd.returns"></a><h4>Returns</h4>
<p> a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.
Free the returned object with <a href="../gobject-The-Base-Object-Type.html#g-object-unref"><code class="function">g_object_unref()</code></a>.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-bind"></a><h3>g_socket_bind ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
g_socket_bind (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *address</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> allow_reuse</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>When a socket is created it is attached to an address family, but it
doesn't have an address in this family. <a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a> assigns the
address (sometimes called name) of the socket.</p>
<p>It is generally required to bind to a local address before you can
receive connections. (See <a class="link" href="GSocket.html#g-socket-listen" title="g_socket_listen ()"><code class="function">g_socket_listen()</code></a> and <a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()"><code class="function">g_socket_accept()</code></a> ).
In certain situations, you may also want to bind a socket that will be
used to initiate connections, though this is not normally required.</p>
<p>If <em class="parameter"><code>socket</code></em>
is a TCP socket, then <em class="parameter"><code>allow_reuse</code></em>
controls the setting
of the <code class="literal">SO_REUSEADDR</code> socket option; normally it should be <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for
server sockets (sockets that you will eventually call
<a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()"><code class="function">g_socket_accept()</code></a> on), and <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> for client sockets. (Failing to
set this flag on a server socket may cause <a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a> to return
<a class="link" href="gio-GIOError.html#G-IO-ERROR-ADDRESS-IN-USE:CAPS"><code class="literal">G_IO_ERROR_ADDRESS_IN_USE</code></a> if the server program is stopped and then
immediately restarted.)</p>
<p>If <em class="parameter"><code>socket</code></em>
is a UDP socket, then <em class="parameter"><code>allow_reuse</code></em>
determines whether or
not other UDP sockets can be bound to the same address at the same
time. In particular, you can have several UDP sockets bound to the
same address, and they will all receive all of the multicast and
broadcast packets sent to that address. (The behavior of unicast
UDP packets to an address with multiple listeners is not defined.)</p>
<div class="refsect3">
<a name="g-socket-bind.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> specifying the local address.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>allow_reuse</p></td>
<td class="parameter_description"><p>whether to allow reusing this address</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-bind.returns"></a><h4>Returns</h4>
<p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> on error.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-listen"></a><h3>g_socket_listen ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
g_socket_listen (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Marks the socket as a server socket, i.e. a socket that is used
to accept incoming requests using <a class="link" href="GSocket.html#g-socket-accept" title="g_socket_accept ()"><code class="function">g_socket_accept()</code></a>.</p>
<p>Before calling this the socket must be bound to a local address using
<a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a>.</p>
<p>To set the maximum amount of outstanding clients, use
<a class="link" href="GSocket.html#g-socket-set-listen-backlog" title="g_socket_set_listen_backlog ()"><code class="function">g_socket_set_listen_backlog()</code></a>.</p>
<div class="refsect3">
<a name="g-socket-listen.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-listen.returns"></a><h4>Returns</h4>
<p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> on error.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-accept"></a><h3>g_socket_accept ()</h3>
<pre class="programlisting"><a class="link" href="GSocket.html" title="GSocket"><span class="returnvalue">GSocket</span></a> *
g_socket_accept (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Accept incoming connections on a connection-based socket. This removes
the first outstanding connection request from the listening socket and
creates a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> object for it.</p>
<p>The <em class="parameter"><code>socket</code></em>
must be bound to a local address with <a class="link" href="GSocket.html#g-socket-bind" title="g_socket_bind ()"><code class="function">g_socket_bind()</code></a> and
must be listening for incoming connections (<a class="link" href="GSocket.html#g-socket-listen" title="g_socket_listen ()"><code class="function">g_socket_listen()</code></a>).</p>
<p>If there are no outstanding connections then the operation will block
or return <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> if non-blocking I/O is enabled.
To be notified of an incoming connection, wait for the <a href="../glib-IO-Channels.html#G-IO-IN:CAPS"><code class="literal">G_IO_IN</code></a> condition.</p>
<div class="refsect3">
<a name="g-socket-accept.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-accept.returns"></a><h4>Returns</h4>
<p> a new <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> on error.
Free the returned object with <a href="../gobject-The-Base-Object-Type.html#g-object-unref"><code class="function">g_object_unref()</code></a>. </p>
<p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-connect"></a><h3>g_socket_connect ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
g_socket_connect (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *address</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Connect the socket to the specified remote address.</p>
<p>For connection oriented socket this generally means we attempt to make
a connection to the <em class="parameter"><code>address</code></em>
. For a connection-less socket it sets
the default address for <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a> and discards all incoming datagrams
from other sources.</p>
<p>Generally connection oriented sockets can only connect once, but
connection-less sockets can connect multiple times to change the
default address.</p>
<p>If the connect call needs to do network I/O it will block, unless
non-blocking I/O is enabled. Then <a class="link" href="gio-GIOError.html#G-IO-ERROR-PENDING:CAPS"><code class="literal">G_IO_ERROR_PENDING</code></a> is returned
and the user can be notified of the connection finishing by waiting
for the G_IO_OUT condition. The result of the connection must then be
checked with <a class="link" href="GSocket.html#g-socket-check-connect-result" title="g_socket_check_connect_result ()"><code class="function">g_socket_check_connect_result()</code></a>.</p>
<div class="refsect3">
<a name="g-socket-connect.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a>.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> specifying the remote address.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-connect.returns"></a><h4>Returns</h4>
<p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if connected, <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> on error.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-check-connect-result"></a><h3>g_socket_check_connect_result ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>
g_socket_check_connect_result (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Checks and resets the pending connect error for the socket.
This is used to check for errors when <a class="link" href="GSocket.html#g-socket-connect" title="g_socket_connect ()"><code class="function">g_socket_connect()</code></a> is
used in non-blocking mode.</p>
<div class="refsect3">
<a name="g-socket-check-connect-result.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-check-connect-result.returns"></a><h4>Returns</h4>
<p> <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if no error, <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> otherwise, setting <em class="parameter"><code>error</code></em>
to the error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-receive"></a><h3>g_socket_receive ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_receive (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *buffer</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Receive data (up to <em class="parameter"><code>size</code></em>
bytes) from a socket. This is mainly used by
connection-oriented sockets; it is identical to <a class="link" href="GSocket.html#g-socket-receive-from" title="g_socket_receive_from ()"><code class="function">g_socket_receive_from()</code></a>
with <em class="parameter"><code>address</code></em>
set to <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</p>
<p>For <a class="link" href="GSocket.html#G-SOCKET-TYPE-DATAGRAM:CAPS"><code class="literal">G_SOCKET_TYPE_DATAGRAM</code></a> and <a class="link" href="GSocket.html#G-SOCKET-TYPE-SEQPACKET:CAPS"><code class="literal">G_SOCKET_TYPE_SEQPACKET</code></a> sockets,
<a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a> will always read either 0 or 1 complete messages from
the socket. If the received message is too large to fit in <em class="parameter"><code>buffer</code></em>
, then
the data beyond <em class="parameter"><code>size</code></em>
bytes will be discarded, without any explicit
indication that this has occurred.</p>
<p>For <a class="link" href="GSocket.html#G-SOCKET-TYPE-STREAM:CAPS"><code class="literal">G_SOCKET_TYPE_STREAM</code></a> sockets, <a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a> can return any
number of bytes, up to <em class="parameter"><code>size</code></em>
. If more than <em class="parameter"><code>size</code></em>
bytes have been
received, the additional data will be returned in future calls to
<a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a>.</p>
<p>If the socket is in blocking mode the call will block until there
is some data to receive, the connection is closed, or there is an
error. If there is no data available and the socket is in
non-blocking mode, a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error will be
returned. To be notified when data is available, wait for the
<a href="../glib-IO-Channels.html#G-IO-IN:CAPS"><code class="literal">G_IO_IN</code></a> condition.</p>
<p>On error -1 is returned and <em class="parameter"><code>error</code></em>
is set accordingly.</p>
<div class="refsect3">
<a name="g-socket-receive.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>buffer</p></td>
<td class="parameter_description"><p> a buffer to
read data into (which should be at least <em class="parameter"><code>size</code></em>
bytes long). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description"><p>the number of bytes you want to read from the socket</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-receive.returns"></a><h4>Returns</h4>
<p> Number of bytes read, or 0 if the connection was closed by
the peer, or -1 on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-receive-from"></a><h3>g_socket_receive_from ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_receive_from (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> **address</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *buffer</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Receive data (up to <em class="parameter"><code>size</code></em>
bytes) from a socket.</p>
<p>If <em class="parameter"><code>address</code></em>
is non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> then <em class="parameter"><code>address</code></em>
will be set equal to the
source address of the received packet.
<em class="parameter"><code>address</code></em>
is owned by the caller.</p>
<p>See <a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a> for additional information.</p>
<div class="refsect3">
<a name="g-socket-receive-from.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p> a pointer to a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a>
pointer, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>][<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>buffer</p></td>
<td class="parameter_description"><p> a buffer to
read data into (which should be at least <em class="parameter"><code>size</code></em>
bytes long). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description"><p>the number of bytes you want to read from the socket</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-receive-from.returns"></a><h4>Returns</h4>
<p> Number of bytes read, or 0 if the connection was closed by
the peer, or -1 on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-receive-message"></a><h3>g_socket_receive_message ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_receive_message (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> **address</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GInputVector" title="struct GInputVector"><span class="type">GInputVector</span></a> *vectors</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> num_vectors</code></em>,
<em class="parameter"><code><a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> ***messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> *num_messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> *flags</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Receive data from a socket. For receiving multiple messages, see
<a class="link" href="GSocket.html#g-socket-receive-messages" title="g_socket_receive_messages ()"><code class="function">g_socket_receive_messages()</code></a>; for easier use, see
<a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a> and <a class="link" href="GSocket.html#g-socket-receive-from" title="g_socket_receive_from ()"><code class="function">g_socket_receive_from()</code></a>.</p>
<p>If <em class="parameter"><code>address</code></em>
is non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> then <em class="parameter"><code>address</code></em>
will be set equal to the
source address of the received packet.
<em class="parameter"><code>address</code></em>
is owned by the caller.</p>
<p><em class="parameter"><code>vector</code></em>
must point to an array of <a class="link" href="GSocket.html#GInputVector" title="struct GInputVector"><span class="type">GInputVector</span></a> structs and
<em class="parameter"><code>num_vectors</code></em>
must be the length of this array. These structs
describe the buffers that received data will be scattered into.
If <em class="parameter"><code>num_vectors</code></em>
is -1, then <em class="parameter"><code>vectors</code></em>
is assumed to be terminated
by a <a class="link" href="GSocket.html#GInputVector" title="struct GInputVector"><span class="type">GInputVector</span></a> with a <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> buffer pointer.</p>
<p>As a special case, if <em class="parameter"><code>num_vectors</code></em>
is 0 (in which case, <em class="parameter"><code>vectors</code></em>
may of course be <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>), then a single byte is received and
discarded. This is to facilitate the common practice of sending a
single '\0' byte for the purposes of transferring ancillary data.</p>
<p><em class="parameter"><code>messages</code></em>
, if non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, will be set to point to a newly-allocated
array of <a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> instances or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if no such
messages was received. These correspond to the control messages
received from the kernel, one <a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> per message
from the kernel. This array is <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated and must be freed
by the caller using <a href="../glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a> after calling <a href="../gobject-The-Base-Object-Type.html#g-object-unref"><code class="function">g_object_unref()</code></a> on each
element. If <em class="parameter"><code>messages</code></em>
is <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, any control messages received will
be discarded.</p>
<p><em class="parameter"><code>num_messages</code></em>
, if non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, will be set to the number of control
messages received.</p>
<p>If both <em class="parameter"><code>messages</code></em>
and <em class="parameter"><code>num_messages</code></em>
are non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, then
<em class="parameter"><code>num_messages</code></em>
gives the number of <a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> instances
in <em class="parameter"><code>messages</code></em>
(ie: not including the <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> terminator).</p>
<p><em class="parameter"><code>flags</code></em>
is an in/out parameter. The commonly available arguments
for this are available in the <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too
(and <a class="link" href="GSocket.html#g-socket-receive-message" title="g_socket_receive_message ()"><code class="function">g_socket_receive_message()</code></a> may pass system-specific flags out).
Flags passed in to the parameter affect the receive operation; flags returned
out of it are relevant to the specific returned message.</p>
<p>As with <a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a>, data may be discarded if <em class="parameter"><code>socket</code></em>
is
<a class="link" href="GSocket.html#G-SOCKET-TYPE-DATAGRAM:CAPS"><code class="literal">G_SOCKET_TYPE_DATAGRAM</code></a> or <a class="link" href="GSocket.html#G-SOCKET-TYPE-SEQPACKET:CAPS"><code class="literal">G_SOCKET_TYPE_SEQPACKET</code></a> and you do not
provide enough buffer space to read a complete message. You can pass
<a class="link" href="GSocket.html#G-SOCKET-MSG-PEEK:CAPS"><code class="literal">G_SOCKET_MSG_PEEK</code></a> in <em class="parameter"><code>flags</code></em>
to peek at the current message without
removing it from the receive queue, but there is no portable way to find
out the length of the message other than by reading it into a
sufficiently-large buffer.</p>
<p>If the socket is in blocking mode the call will block until there
is some data to receive, the connection is closed, or there is an
error. If there is no data available and the socket is in
non-blocking mode, a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error will be
returned. To be notified when data is available, wait for the
<a href="../glib-IO-Channels.html#G-IO-IN:CAPS"><code class="literal">G_IO_IN</code></a> condition.</p>
<p>On error -1 is returned and <em class="parameter"><code>error</code></em>
is set accordingly.</p>
<div class="refsect3">
<a name="g-socket-receive-message.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p> a pointer to a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a>
pointer, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>][<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>vectors</p></td>
<td class="parameter_description"><p> an array of <a class="link" href="GSocket.html#GInputVector" title="struct GInputVector"><span class="type">GInputVector</span></a> structs. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=num_vectors]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>num_vectors</p></td>
<td class="parameter_description"><p>the number of elements in <em class="parameter"><code>vectors</code></em>
, or -1</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>messages</p></td>
<td class="parameter_description"><p> a pointer which
may be filled with an array of <a href="GSocketControlMessage.html#GSocketControlMessage-struct"><span class="type">GSocketControlMessages</span></a>, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=num_messages][<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>][<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>num_messages</p></td>
<td class="parameter_description"><p> a pointer which will be filled with the number of
elements in <em class="parameter"><code>messages</code></em>
, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>flags</p></td>
<td class="parameter_description"><p> a pointer to an int containing <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> flags. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for input and for returning results. Default is transfer full."><span class="acronym">inout</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p>a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p>a <a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> pointer, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-receive-message.returns"></a><h4>Returns</h4>
<p> Number of bytes read, or 0 if the connection was closed by
the peer, or -1 on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-receive-messages"></a><h3>g_socket_receive_messages ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a>
g_socket_receive_messages (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage"><span class="type">GInputMessage</span></a> *messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#guint"><span class="type">guint</span></a> num_messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> flags</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Receive multiple data messages from <em class="parameter"><code>socket</code></em>
in one go. This is the most
complicated and fully-featured version of this call. For easier use, see
<a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a>, <a class="link" href="GSocket.html#g-socket-receive-from" title="g_socket_receive_from ()"><code class="function">g_socket_receive_from()</code></a>, and <a class="link" href="GSocket.html#g-socket-receive-message" title="g_socket_receive_message ()"><code class="function">g_socket_receive_message()</code></a>.</p>
<p><em class="parameter"><code>messages</code></em>
must point to an array of <a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage"><span class="type">GInputMessage</span></a> structs and
<em class="parameter"><code>num_messages</code></em>
must be the length of this array. Each <a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage"><span class="type">GInputMessage</span></a>
contains a pointer to an array of <a class="link" href="GSocket.html#GInputVector" title="struct GInputVector"><span class="type">GInputVector</span></a> structs describing the
buffers that the data received in each message will be written to. Using
multiple <a href="GSocket.html#GInputVector"><span class="type">GInputVectors</span></a> is more memory-efficient than manually copying data
out of a single buffer to multiple sources, and more system-call-efficient
than making multiple calls to <a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a>, such as in scenarios where
a lot of data packets need to be received (e.g. high-bandwidth video
streaming over RTP/UDP).</p>
<p><em class="parameter"><code>flags</code></em>
modify how all messages are received. The commonly available
arguments for this are available in the <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too. These
flags affect the overall receive operation. Flags affecting individual
messages are returned in <a class="link" href="GSocket.html#GInputMessage.flags"><span class="type">GInputMessage.flags</span></a>.</p>
<p>The other members of <a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage"><span class="type">GInputMessage</span></a> are treated as described in its
documentation.</p>
<p>If <a class="link" href="GSocket.html#GSocket--blocking" title="The “blocking” property"><span class="type">“blocking”</span></a> is <a href="../glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> the call will block until <em class="parameter"><code>num_messages</code></em>
have
been received, or the end of the stream is reached.</p>
<p>If <a class="link" href="GSocket.html#GSocket--blocking" title="The “blocking” property"><span class="type">“blocking”</span></a> is <a href="../glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> the call will return up to <em class="parameter"><code>num_messages</code></em>
without blocking, or <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> if no messages are queued in the
operating system to be received.</p>
<p>In blocking mode, if <a class="link" href="GSocket.html#GSocket--timeout" title="The “timeout” property"><span class="type">“timeout”</span></a> is positive and is reached before any
messages are received, <a class="link" href="gio-GIOError.html#G-IO-ERROR-TIMED-OUT:CAPS"><code class="literal">G_IO_ERROR_TIMED_OUT</code></a> is returned, otherwise up to
<em class="parameter"><code>num_messages</code></em>
are returned. (Note: This is effectively the
behaviour of <code class="literal">MSG_WAITFORONE</code> with <code class="function">recvmmsg()</code>.)</p>
<p>To be notified when messages are available, wait for the
<a href="../glib-IO-Channels.html#G-IO-IN:CAPS"><code class="literal">G_IO_IN</code></a> condition. Note though that you may still receive
<a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> from <a class="link" href="GSocket.html#g-socket-receive-messages" title="g_socket_receive_messages ()"><code class="function">g_socket_receive_messages()</code></a> even if you were
previously notified of a <a href="../glib-IO-Channels.html#G-IO-IN:CAPS"><code class="literal">G_IO_IN</code></a> condition.</p>
<p>If the remote peer closes the connection, any messages queued in the
operating system will be returned, and subsequent calls to
<a class="link" href="GSocket.html#g-socket-receive-messages" title="g_socket_receive_messages ()"><code class="function">g_socket_receive_messages()</code></a> will return 0 (with no error set).</p>
<p>On error -1 is returned and <em class="parameter"><code>error</code></em>
is set accordingly. An error will only
be returned if zero messages could be received; otherwise the number of
messages successfully received before the error will be returned.</p>
<div class="refsect3">
<a name="g-socket-receive-messages.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>messages</p></td>
<td class="parameter_description"><p> an array of <a class="link" href="GSocket.html#GInputMessage" title="struct GInputMessage"><span class="type">GInputMessage</span></a> structs. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=num_messages]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>num_messages</p></td>
<td class="parameter_description"><p>the number of elements in <em class="parameter"><code>messages</code></em>
</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>flags</p></td>
<td class="parameter_description"><p>an int containing <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> flags for the overall operation</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-receive-messages.returns"></a><h4>Returns</h4>
<p> number of messages received, or -1 on error. Note that the number
of messages received may be smaller than <em class="parameter"><code>num_messages</code></em>
if in non-blocking
mode, if the peer closed the connection, or if <em class="parameter"><code>num_messages</code></em>
was larger than <code class="literal">UIO_MAXIOV</code> (1024), in which case the caller may re-try
to receive the remaining messages.</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-48.html#api-index-2.48">2.48</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-receive-with-blocking"></a><h3>g_socket_receive_with_blocking ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_receive_with_blocking (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *buffer</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> blocking</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>This behaves exactly the same as <a class="link" href="GSocket.html#g-socket-receive" title="g_socket_receive ()"><code class="function">g_socket_receive()</code></a>, except that
the choice of blocking or non-blocking behavior is determined by
the <em class="parameter"><code>blocking</code></em>
argument rather than by <em class="parameter"><code>socket</code></em>
's properties.</p>
<div class="refsect3">
<a name="g-socket-receive-with-blocking.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>buffer</p></td>
<td class="parameter_description"><p> a buffer to
read data into (which should be at least <em class="parameter"><code>size</code></em>
bytes long). </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description"><p>the number of bytes you want to read from the socket</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>blocking</p></td>
<td class="parameter_description"><p>whether to do blocking or non-blocking I/O</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-receive-with-blocking.returns"></a><h4>Returns</h4>
<p> Number of bytes read, or 0 if the connection was closed by
the peer, or -1 on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-26.html#api-index-2.26">2.26</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-send"></a><h3>g_socket_send ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_send (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code>const <a href="../glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *buffer</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Tries to send <em class="parameter"><code>size</code></em>
bytes from <em class="parameter"><code>buffer</code></em>
on the socket. This is
mainly used by connection-oriented sockets; it is identical to
<a class="link" href="GSocket.html#g-socket-send-to" title="g_socket_send_to ()"><code class="function">g_socket_send_to()</code></a> with <em class="parameter"><code>address</code></em>
set to <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</p>
<p>If the socket is in blocking mode the call will block until there is
space for the data in the socket queue. If there is no space available
and the socket is in non-blocking mode a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error
will be returned. To be notified when space is available, wait for the
<a href="../glib-IO-Channels.html#G-IO-OUT:CAPS"><code class="literal">G_IO_OUT</code></a> condition. Note though that you may still receive
<a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> from <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a> even if you were previously
notified of a <a href="../glib-IO-Channels.html#G-IO-OUT:CAPS"><code class="literal">G_IO_OUT</code></a> condition. (On Windows in particular, this is
very common due to the way the underlying APIs work.)</p>
<p>On error -1 is returned and <em class="parameter"><code>error</code></em>
is set accordingly.</p>
<div class="refsect3">
<a name="g-socket-send.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>buffer</p></td>
<td class="parameter_description"><p> the buffer
containing the data to send. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description"><p>the number of bytes to send</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-send.returns"></a><h4>Returns</h4>
<p> Number of bytes written (which may be less than <em class="parameter"><code>size</code></em>
), or -1
on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-send-to"></a><h3>g_socket_send_to ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_send_to (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *address</code></em>,
<em class="parameter"><code>const <a href="../glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *buffer</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Tries to send <em class="parameter"><code>size</code></em>
bytes from <em class="parameter"><code>buffer</code></em>
to <em class="parameter"><code>address</code></em>
. If <em class="parameter"><code>address</code></em>
is
<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> then the message is sent to the default receiver (set by
<a class="link" href="GSocket.html#g-socket-connect" title="g_socket_connect ()"><code class="function">g_socket_connect()</code></a>).</p>
<p>See <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a> for additional information.</p>
<div class="refsect3">
<a name="g-socket-send-to.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p> a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a>, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>buffer</p></td>
<td class="parameter_description"><p> the buffer
containing the data to send. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>size</p></td>
<td class="parameter_description"><p>the number of bytes to send</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-send-to.returns"></a><h4>Returns</h4>
<p> Number of bytes written (which may be less than <em class="parameter"><code>size</code></em>
), or -1
on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-send-message"></a><h3>g_socket_send_message ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a>
g_socket_send_message (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a> *address</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> *vectors</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> num_vectors</code></em>,
<em class="parameter"><code><a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> **messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> num_messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> flags</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Send data to <em class="parameter"><code>address</code></em>
on <em class="parameter"><code>socket</code></em>
. For sending multiple messages see
<a class="link" href="GSocket.html#g-socket-send-messages" title="g_socket_send_messages ()"><code class="function">g_socket_send_messages()</code></a>; for easier use, see
<a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a> and <a class="link" href="GSocket.html#g-socket-send-to" title="g_socket_send_to ()"><code class="function">g_socket_send_to()</code></a>.</p>
<p>If <em class="parameter"><code>address</code></em>
is <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> then the message is sent to the default receiver
(set by <a class="link" href="GSocket.html#g-socket-connect" title="g_socket_connect ()"><code class="function">g_socket_connect()</code></a>).</p>
<p><em class="parameter"><code>vectors</code></em>
must point to an array of <a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> structs and
<em class="parameter"><code>num_vectors</code></em>
must be the length of this array. (If <em class="parameter"><code>num_vectors</code></em>
is -1,
then <em class="parameter"><code>vectors</code></em>
is assumed to be terminated by a <a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> with a
<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> buffer pointer.) The <a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> structs describe the buffers
that the sent data will be gathered from. Using multiple
<a href="GSocket.html#GOutputVector"><span class="type">GOutputVectors</span></a> is more memory-efficient than manually copying
data from multiple sources into a single buffer, and more
network-efficient than making multiple calls to <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a>.</p>
<p><em class="parameter"><code>messages</code></em>
, if non-<a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, is taken to point to an array of <em class="parameter"><code>num_messages</code></em>
<a class="link" href="GSocketControlMessage.html" title="GSocketControlMessage"><span class="type">GSocketControlMessage</span></a> instances. These correspond to the control
messages to be sent on the socket.
If <em class="parameter"><code>num_messages</code></em>
is -1 then <em class="parameter"><code>messages</code></em>
is treated as a <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated
array.</p>
<p><em class="parameter"><code>flags</code></em>
modify how the message is sent. The commonly available arguments
for this are available in the <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too.</p>
<p>If the socket is in blocking mode the call will block until there is
space for the data in the socket queue. If there is no space available
and the socket is in non-blocking mode a <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error
will be returned. To be notified when space is available, wait for the
<a href="../glib-IO-Channels.html#G-IO-OUT:CAPS"><code class="literal">G_IO_OUT</code></a> condition. Note though that you may still receive
<a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> from <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a> even if you were previously
notified of a <a href="../glib-IO-Channels.html#G-IO-OUT:CAPS"><code class="literal">G_IO_OUT</code></a> condition. (On Windows in particular, this is
very common due to the way the underlying APIs work.)</p>
<p>On error -1 is returned and <em class="parameter"><code>error</code></em>
is set accordingly.</p>
<div class="refsect3">
<a name="g-socket-send-message.parameters"></a><h4>Parameters</h4>
<div class="informaltable"><table class="informaltable" width="100%" border="0">
<colgroup>
<col width="150px" class="parameters_name">
<col class="parameters_description">
<col width="200px" class="parameters_annotations">
</colgroup>
<tbody>
<tr>
<td class="parameter_name"><p>socket</p></td>
<td class="parameter_description"><p>a <a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a></p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>address</p></td>
<td class="parameter_description"><p> a <a class="link" href="GSocketAddress.html" title="GSocketAddress"><span class="type">GSocketAddress</span></a>, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>vectors</p></td>
<td class="parameter_description"><p> an array of <a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> structs. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=num_vectors]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>num_vectors</p></td>
<td class="parameter_description"><p>the number of elements in <em class="parameter"><code>vectors</code></em>
, or -1</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>messages</p></td>
<td class="parameter_description"><p> a pointer to an
array of <a href="GSocketControlMessage.html#GSocketControlMessage-struct"><span class="type">GSocketControlMessages</span></a>, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=num_messages][<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>num_messages</p></td>
<td class="parameter_description"><p>number of elements in <em class="parameter"><code>messages</code></em>
, or -1.</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>flags</p></td>
<td class="parameter_description"><p>an int containing <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> flags</p></td>
<td class="parameter_annotations"> </td>
</tr>
<tr>
<td class="parameter_name"><p>cancellable</p></td>
<td class="parameter_description"><p> a <a class="link" href="GCancellable.html" title="GCancellable"><code class="literal">GCancellable</code></a> or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. </p></td>
<td class="parameter_annotations"><span class="annotation">[<acronym title="NULL is OK, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span></td>
</tr>
<tr>
<td class="parameter_name"><p>error</p></td>
<td class="parameter_description"><p><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="../glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</p></td>
<td class="parameter_annotations"> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="refsect3">
<a name="g-socket-send-message.returns"></a><h4>Returns</h4>
<p> Number of bytes written (which may be less than <em class="parameter"><code>size</code></em>
), or -1
on error</p>
</div>
<p class="since">Since: <a class="link" href="api-index-2-22.html#api-index-2.22">2.22</a></p>
</div>
<hr>
<div class="refsect2">
<a name="g-socket-send-messages"></a><h3>g_socket_send_messages ()</h3>
<pre class="programlisting"><a href="../glib-Basic-Types.html#gint"><span class="returnvalue">gint</span></a>
g_socket_send_messages (<em class="parameter"><code><a class="link" href="GSocket.html" title="GSocket"><span class="type">GSocket</span></a> *socket</code></em>,
<em class="parameter"><code><a class="link" href="GSocket.html#GOutputMessage" title="struct GOutputMessage"><span class="type">GOutputMessage</span></a> *messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#guint"><span class="type">guint</span></a> num_messages</code></em>,
<em class="parameter"><code><a href="../glib-Basic-Types.html#gint"><span class="type">gint</span></a> flags</code></em>,
<em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
<em class="parameter"><code><a href="../glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>Send multiple data messages from <em class="parameter"><code>socket</code></em>
in one go. This is the most
complicated and fully-featured version of this call. For easier use, see
<a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a>, <a class="link" href="GSocket.html#g-socket-send-to" title="g_socket_send_to ()"><code class="function">g_socket_send_to()</code></a>, and <a class="link" href="GSocket.html#g-socket-send-message" title="g_socket_send_message ()"><code class="function">g_socket_send_message()</code></a>.</p>
<p><em class="parameter"><code>messages</code></em>
must point to an array of <a class="link" href="GSocket.html#GOutputMessage" title="struct GOutputMessage"><span class="type">GOutputMessage</span></a> structs and
<em class="parameter"><code>num_messages</code></em>
must be the length of this array. Each <a class="link" href="GSocket.html#GOutputMessage" title="struct GOutputMessage"><span class="type">GOutputMessage</span></a>
contains an address to send the data to, and a pointer to an array of
<a class="link" href="GSocket.html#GOutputVector" title="struct GOutputVector"><span class="type">GOutputVector</span></a> structs to describe the buffers that the data to be sent
for each message will be gathered from. Using multiple <a href="GSocket.html#GOutputVector"><span class="type">GOutputVectors</span></a> is
more memory-efficient than manually copying data from multiple sources
into a single buffer, and more network-efficient than making multiple
calls to <a class="link" href="GSocket.html#g-socket-send" title="g_socket_send ()"><code class="function">g_socket_send()</code></a>. Sending multiple messages in one go avoids the
overhead of making a lot of syscalls in scenarios where a lot of data
packets need to be sent (e.g. high-bandwidth video streaming over RTP/UDP),
or where the same data needs to be sent to multiple recipients.</p>
<p><em class="parameter"><code>flags</code></em>
modify how the message is sent. The commonly available arguments
for this are available in the <a class="link" href="GSocket.html#GSocketMsgFlags" title="enum GSocketMsgFlags"><span class="type">GSocketMsgFlags</span></a> enum, but the
values there are the same as the system values, and the flags
are passed in as-is, so you can pass in system-specific flags too.</p>
<p>