mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 22:52:09 +01:00
GSocket: Add function to get the currently available bytes for reading
https://bugzilla.gnome.org/show_bug.cgi?id=668009
This commit is contained in:
parent
ffb5f8b101
commit
fbdb8128dc
@ -1806,6 +1806,7 @@ g_socket_is_connected
|
|||||||
g_socket_create_source
|
g_socket_create_source
|
||||||
g_socket_condition_check
|
g_socket_condition_check
|
||||||
g_socket_condition_wait
|
g_socket_condition_wait
|
||||||
|
g_socket_get_available_bytes
|
||||||
g_socket_set_listen_backlog
|
g_socket_set_listen_backlog
|
||||||
g_socket_get_listen_backlog
|
g_socket_get_listen_backlog
|
||||||
g_socket_get_blocking
|
g_socket_get_blocking
|
||||||
|
@ -949,6 +949,7 @@ g_socket_condition_check
|
|||||||
g_socket_condition_wait
|
g_socket_condition_wait
|
||||||
g_socket_connect
|
g_socket_connect
|
||||||
g_socket_create_source
|
g_socket_create_source
|
||||||
|
g_socket_get_available_bytes
|
||||||
g_socket_get_blocking
|
g_socket_get_blocking
|
||||||
g_socket_get_broadcast
|
g_socket_get_broadcast
|
||||||
g_socket_get_family
|
g_socket_get_family
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
# include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SYS_UIO_H
|
#ifdef HAVE_SYS_UIO_H
|
||||||
@ -2335,6 +2336,39 @@ g_socket_check_connect_result (GSocket *socket,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_socket_get_available_bytes:
|
||||||
|
* @socket: a #GSocket
|
||||||
|
*
|
||||||
|
* Get the amount of data pending in the OS input buffer.
|
||||||
|
*
|
||||||
|
* Returns: the number of bytes that can be read from the socket
|
||||||
|
* without blocking or -1 on error.
|
||||||
|
*
|
||||||
|
* Since: 2.32
|
||||||
|
*/
|
||||||
|
gssize
|
||||||
|
g_socket_get_available_bytes (GSocket *socket)
|
||||||
|
{
|
||||||
|
#ifndef G_OS_WIN32
|
||||||
|
gulong avail = 0;
|
||||||
|
#else
|
||||||
|
gint avail = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_return_val_if_fail (G_IS_SOCKET (socket), -1);
|
||||||
|
|
||||||
|
#ifndef G_OS_WIN32
|
||||||
|
if (ioctl (socket->priv->fd, FIONREAD, &avail) < 0)
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
if (ioctlsocket (socket->priv->fd, FIONREAD, &avail) == SOCKET_ERROR)
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return avail;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_socket_receive:
|
* g_socket_receive:
|
||||||
* @socket: a #GSocket
|
* @socket: a #GSocket
|
||||||
|
@ -137,6 +137,8 @@ gboolean g_socket_connect (GSocket
|
|||||||
gboolean g_socket_check_connect_result (GSocket *socket,
|
gboolean g_socket_check_connect_result (GSocket *socket,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gssize g_socket_get_available_bytes (GSocket *socket);
|
||||||
|
|
||||||
GIOCondition g_socket_condition_check (GSocket *socket,
|
GIOCondition g_socket_condition_check (GSocket *socket,
|
||||||
GIOCondition condition);
|
GIOCondition condition);
|
||||||
gboolean g_socket_condition_wait (GSocket *socket,
|
gboolean g_socket_condition_wait (GSocket *socket,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user