⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 giochannel.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 5 页
字号:
    g_return_val_if_fail (channel != NULL, 0);  source = g_io_create_watch (channel, condition);  if (priority != G_PRIORITY_DEFAULT)    g_source_set_priority (source, priority);  g_source_set_callback (source, (GSourceFunc)func, user_data, notify);  id = g_source_attach (source, NULL);  g_source_unref (source);  return id;}guint //usedg_io_add_watch (GIOChannel    *channel,		GIOCondition   condition,		GIOFunc        func,		gpointer       user_data){  return g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, condition, func, user_data, NULL);}/** * g_io_channel_get_buffer_condition: * @channel: A #GIOChannel * * This function returns a #GIOCondition depending on whether there * is data to be read/space to write data in the * internal buffers in the #GIOChannel. Only the flags %G_IO_IN and * %G_IO_OUT may be set. * * Return value: A #GIOCondition **/GIOConditiong_io_channel_get_buffer_condition (GIOChannel *channel){  GIOCondition condition = 0;  if (channel->encoding)    {      if (channel->encoded_read_buf && (channel->encoded_read_buf->len > 0))        condition |= G_IO_IN; /* Only return if we have full characters */    }  else    {      if (channel->read_buf && (channel->read_buf->len > 0))        condition |= G_IO_IN;    }  if (channel->write_buf && (channel->write_buf->len < channel->buf_size))    condition |= G_IO_OUT;  return condition;}/** * g_io_channel_error_from_errno: * @en: an <literal>errno</literal> error number, e.g. %EINVAL. * * Converts an <literal>errno</literal> error number to a #GIOChannelError. * * Return value: a #GIOChannelError error number, e.g. %G_IO_CHANNEL_ERROR_INVAL. **/GIOChannelErrorg_io_channel_error_from_errno (gint en){#ifdef EAGAIN  g_return_val_if_fail (en != EAGAIN, G_IO_CHANNEL_ERROR_FAILED);#endif#ifdef EINTR  g_return_val_if_fail (en != EINTR, G_IO_CHANNEL_ERROR_FAILED);#endif  switch (en)    {#ifdef EBADF    case EBADF:      g_warning("Invalid file descriptor.\n");      return G_IO_CHANNEL_ERROR_FAILED;#endif#ifdef EFAULT    case EFAULT:      g_warning("File descriptor outside valid address space.\n");      return G_IO_CHANNEL_ERROR_FAILED;#endif#ifdef EFBIG    case EFBIG:      return G_IO_CHANNEL_ERROR_FBIG;#endif#ifdef EINVAL    case EINVAL:      return G_IO_CHANNEL_ERROR_INVAL;#endif#ifdef EIO    case EIO:      return G_IO_CHANNEL_ERROR_IO;#endif#ifdef EISDIR    case EISDIR:      return G_IO_CHANNEL_ERROR_ISDIR;#endif#ifdef ENOSPC    case ENOSPC:      return G_IO_CHANNEL_ERROR_NOSPC;#endif#ifdef ENXIO    case ENXIO:      return G_IO_CHANNEL_ERROR_NXIO;#endif#ifdef EOVERFLOW    case EOVERFLOW:      return G_IO_CHANNEL_ERROR_OVERFLOW;#endif#ifdef EPIPE    case EPIPE:      return G_IO_CHANNEL_ERROR_PIPE;#endif    default:      return G_IO_CHANNEL_ERROR_FAILED;    }}/** * g_io_channel_set_buffer_size: * @channel: a #GIOChannel * @size: the size of the buffer. 0 == pick a good size * * Sets the buffer size. **/  #ifdef changebysunnyvoidg_io_channel_set_buffer_size (GIOChannel	*channel,                              gsize		 size){  g_return_if_fail (channel != NULL);  if (size == 0)    size = G_IO_NICE_BUF_SIZE;  if (size < MAX_CHAR_SIZE)    size = MAX_CHAR_SIZE;  channel->buf_size = size;}#endif/** * g_io_channel_get_buffer_size: * @channel: a #GIOChannel * * Gets the buffer size. * * Return value: the size of the buffer. **/  #ifdef changebysunnygsizeg_io_channel_get_buffer_size (GIOChannel	*channel){  g_return_val_if_fail (channel != NULL, 0);  return channel->buf_size;}#endif/** * g_io_channel_set_line_term: * @channel: a #GIOChannel * @line_term: The line termination string. Use %NULL for auto detect. *             Auto detection breaks on "\n", "\r\n", "\r", "\0", and *             the Unicode paragraph separator. Auto detection should *             not be used for anything other than file-based channels. * @length: The length of the termination string. If -1 is passed, the *          string is assumed to be nul-terminated. This option allows *          termination strings with embeded nuls. * * This sets the string that #GIOChannel uses to determine * where in the file a line break occurs. **//** * g_io_channel_set_flags: * @channel: a #GIOChannel. * @flags: the flags to set on the IO channel. * @error: A location to return an error of type #GIOChannelError. * * Sets the (writeable) flags in @channel to (@flags & %G_IO_CHANNEL_SET_MASK). * * Return value: the status of the operation.  **/GIOStatus //usedg_io_channel_set_flags (GIOChannel *channel,                        GIOFlags    flags,                        GError    **error){  g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);  g_return_val_if_fail ((error == NULL) || (*error == NULL),			G_IO_STATUS_ERROR);  return (* channel->funcs->io_set_flags)(channel,					  flags & G_IO_FLAG_SET_MASK,					  error);}/** * g_io_channel_get_flags: * @channel: a #GIOChannel * * Gets the current flags for a #GIOChannel, including read-only * flags such as %G_IO_FLAG_IS_READABLE. * * The values of the flags %G_IO_FLAG_IS_READABLE and %G_IO_FLAG_IS_WRITEABLE * are cached for internal use by the channel when it is created. * If they should change at some later point (e.g. partial shutdown * of a socket with the UNIX <function>shutdown()</function> function), the user * should immediately call g_io_channel_get_flags () to update * the internal values of these flags. * * Return value: the flags which are set on the channel **/GIOFlags //usedg_io_channel_get_flags (GIOChannel *channel){  GIOFlags flags;  g_return_val_if_fail (channel != NULL, 0);  flags = (* channel->funcs->io_get_flags) (channel);  /* Cross implementation code */  if (channel->is_seekable)    flags |= G_IO_FLAG_IS_SEEKABLE;  if (channel->is_readable)    flags |= G_IO_FLAG_IS_READABLE;  if (channel->is_writeable)    flags |= G_IO_FLAG_IS_WRITEABLE;  return flags;}/** * g_io_channel_flush: * @channel: a #GIOChannel * @error: location to store an error of type #GIOChannelError * * Flushes the write buffer for the GIOChannel. * * Return value: the status of the operation: One of *   #G_IO_CHANNEL_NORMAL, #G_IO_CHANNEL_AGAIN, or *   #G_IO_CHANNEL_ERROR. **/GIOStatus //usedg_io_channel_flush (GIOChannel	*channel,		    GError     **error){  GIOStatus status;  gsize this_time = 1, bytes_written = 0;  g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);  g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);  if (channel->write_buf == NULL || channel->write_buf->len == 0)    return G_IO_STATUS_NORMAL;  do    {      g_assert (this_time > 0);      status = channel->funcs->io_write (channel,					 channel->write_buf->str + bytes_written,					 channel->write_buf->len - bytes_written,					 &this_time, error);      bytes_written += this_time;    }  while ((bytes_written < channel->write_buf->len)         && (status == G_IO_STATUS_NORMAL));  g_string_erase (channel->write_buf, 0, bytes_written);  return status;}#ifdef changebysunnyvoidg_io_channel_set_line_term (GIOChannel	*channel,                            const gchar	*line_term,			    gint         length){  g_return_if_fail (channel != NULL);  g_return_if_fail (line_term == NULL || length != 0); /* Disallow "" */  if (line_term == NULL)    length = 0;  else if (length < 0)    length = strlen (line_term);  if (channel->line_term)    g_free (channel->line_term);  channel->line_term = line_term ? g_memdup (line_term, length) : NULL;  channel->line_term_len = length;}/** * g_io_channel_get_line_term: * @channel: a #GIOChannel * @length: a location to return the length of the line terminator * * This returns the string that #GIOChannel uses to determine * where in the file a line break occurs. A value of %NULL * indicates auto detection. * * Return value: The line termination string. This value *   is owned by GLib and must not be freed. **/G_CONST_RETURN gchar*g_io_channel_get_line_term (GIOChannel	*channel,			    gint        *length){  g_return_val_if_fail (channel != NULL, 0);  if (length)    *length = channel->line_term_len;  return channel->line_term;}/** * g_io_channel_set_close_on_unref: * @channel: a #GIOChannel * @do_close: Whether to close the channel on the final unref of *            the GIOChannel data structure. The default value of *            this is %TRUE for channels created by g_io_channel_new_file (), *            and %FALSE for all other channels. * * Setting this flag to %TRUE for a channel you have already closed * can cause problems. **/voidg_io_channel_set_close_on_unref	(GIOChannel *channel,				 gboolean    do_close){  g_return_if_fail (channel != NULL);  channel->close_on_unref = do_close;}/** * g_io_channel_get_close_on_unref: * @channel: a #GIOChannel. * * Returns whether the file/socket/whatever associated with @channel * will be closed when @channel receives its final unref and is * destroyed. The default value of this is %TRUE for channels created * by g_io_channel_new_file (), and %FALSE for all other channels. * * Return value: Whether the channel will be closed on the final unref of *               the GIOChannel data structure. **/gbooleang_io_channel_get_close_on_unref	(GIOChannel *channel){  g_return_val_if_fail (channel != NULL, FALSE);  return channel->close_on_unref;}/** * g_io_channel_seek_position: * @channel: a #GIOChannel * @offset: The offset in bytes from the position specified by @type * @type: a #GSeekType. The type %G_SEEK_CUR is only allowed in those *                      cases where a call to g_io_channel_set_encoding () *                      is allowed. See the documentation for *                      g_io_channel_set_encoding () for details. * @error: A location to return an error of type #GIOChannelError * * Replacement for g_io_channel_seek() with the new API. * * Return value: the status of the operation. **/GIOStatusg_io_channel_seek_position	(GIOChannel* channel,				 gint64      offset,				 GSeekType   type,				 GError    **error){  GIOStatus status;  /* For files, only one of the read and write buffers can contain data.   * For sockets, both can contain data.   */  g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);  g_return_val_if_fail ((error == NULL) || (*error == NULL),			G_IO_STATUS_ERROR);  g_return_val_if_fail (channel->is_seekable, G_IO_STATUS_ERROR);  switch (type)    {      case G_SEEK_CUR: /* The user is seeking relative to the head of the buffer */        if (channel->use_buffer)          {            if (channel->do_encode && channel->encoded_read_buf                && channel->encoded_read_buf->len > 0)              {                g_warning ("Seek type G_SEEK_CUR not allowed for this"                  " channel's encoding.\n");                return G_IO_STATUS_ERROR;              }          if (channel->read_buf)            offset -= channel->read_buf->len;          if (channel->encoded_read_buf)            {              g_assert (channel->encoded_read_buf->len == 0 || !channel->do_encode);              /* If there's anything here, it's because the encoding is UTF-8,               * so we can just subtract the buffer length, the same as for               * the unencoded data.               */              offset -= channel->encoded_read_buf->len;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -