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

📄 glib-io-channels.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
manner using <a class="link" href="glib-IO-Channels.html#g-io-channel-new-file"><code class="function">g_io_channel_new_file()</code></a>.</p><p>Once a <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> has been created, it can be used in a generic mannerwith the functions <a class="link" href="glib-IO-Channels.html#g-io-channel-read-chars"><code class="function">g_io_channel_read_chars()</code></a>, <a class="link" href="glib-IO-Channels.html#g-io-channel-write-chars"><code class="function">g_io_channel_write_chars()</code></a>,<a class="link" href="glib-IO-Channels.html#g-io-channel-seek-position"><code class="function">g_io_channel_seek_position()</code></a>, and <a class="link" href="glib-IO-Channels.html#g-io-channel-shutdown"><code class="function">g_io_channel_shutdown()</code></a>.</p><p>To add a <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> to the <a class="link" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop">main event loop</a>use <a class="link" href="glib-IO-Channels.html#g-io-add-watch"><code class="function">g_io_add_watch()</code></a> or <a class="link" href="glib-IO-Channels.html#g-io-add-watch-full"><code class="function">g_io_add_watch_full()</code></a>. Here you specify which eventsyou are interested in on the <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>, and provide a function to becalled whenever these events occur.</p><p><a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> instances are created with an initial reference count of 1.<a class="link" href="glib-IO-Channels.html#g-io-channel-ref"><code class="function">g_io_channel_ref()</code></a> and <a class="link" href="glib-IO-Channels.html#g-io-channel-unref"><code class="function">g_io_channel_unref()</code></a> can be used to increment ordecrement the reference count respectively. When the reference count fallsto 0, the <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> is freed. (Though it isn't closed automatically,unless it was created using <code class="function">g_io_channel_new_from_file()</code>.)Using <a class="link" href="glib-IO-Channels.html#g-io-add-watch"><code class="function">g_io_add_watch()</code></a> or <a class="link" href="glib-IO-Channels.html#g-io-add-watch-full"><code class="function">g_io_add_watch_full()</code></a> increments a channel'sreference count.</p><p>The new functions <a class="link" href="glib-IO-Channels.html#g-io-channel-read-chars"><code class="function">g_io_channel_read_chars()</code></a>, <a class="link" href="glib-IO-Channels.html#g-io-channel-read-line"><code class="function">g_io_channel_read_line()</code></a>,<a class="link" href="glib-IO-Channels.html#g-io-channel-read-line-string"><code class="function">g_io_channel_read_line_string()</code></a>, <a class="link" href="glib-IO-Channels.html#g-io-channel-read-to-end"><code class="function">g_io_channel_read_to_end()</code></a>,<a class="link" href="glib-IO-Channels.html#g-io-channel-write-chars"><code class="function">g_io_channel_write_chars()</code></a>, <a class="link" href="glib-IO-Channels.html#g-io-channel-seek-position"><code class="function">g_io_channel_seek_position()</code></a>,and <a class="link" href="glib-IO-Channels.html#g-io-channel-flush"><code class="function">g_io_channel_flush()</code></a> should not be mixed with thedeprecated functions <a class="link" href="glib-IO-Channels.html#g-io-channel-read"><code class="function">g_io_channel_read()</code></a>, <a class="link" href="glib-IO-Channels.html#g-io-channel-write"><code class="function">g_io_channel_write()</code></a>,and <a class="link" href="glib-IO-Channels.html#g-io-channel-seek"><code class="function">g_io_channel_seek()</code></a> on the same channel.</p></div><div class="refsect1" lang="en"><a name="id2929359"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2929369"></a><h3><a name="GIOChannel"></a>GIOChannel</h3><a class="indexterm" name="id2929382"></a><pre class="programlisting">typedef struct {} GIOChannel;</pre><p>A data structure representing an IO Channel. The fields should be consideredprivate and should only be accessed with the following functions.</p></div><hr><div class="refsect2" lang="en"><a name="id2929399"></a><h3><a name="g-io-channel-unix-new"></a>g_io_channel_unix_new ()</h3><a class="indexterm" name="id2929413"></a><pre class="programlisting"><a class="link" href="glib-IO-Channels.html#GIOChannel">GIOChannel</a>*         g_io_channel_unix_new               (int fd);</pre><p>Creates a new <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> given a file descriptor.On UNIX systems this works for plain files, pipes, and sockets.</p><p>The returned <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> has a reference count of 1.</p><p>The default encoding for <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> is UTF-8. If your applicationis reading output from a command using via pipe, you may need toset the encoding to the encoding of the current locale (see<a class="link" href="glib-Character-Set-Conversion.html#g-get-charset"><code class="function">g_get_charset()</code></a>) with the <a class="link" href="glib-IO-Channels.html#g-io-channel-set-encoding"><code class="function">g_io_channel_set_encoding()</code></a> function.</p><p>If you want to read raw binary data without interpretation, thencall the <a class="link" href="glib-IO-Channels.html#g-io-channel-set-encoding"><code class="function">g_io_channel_set_encoding()</code></a> function with <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> for theencoding argument.</p><p>This function is available in GLib on Windows, too, but you shouldavoid using it on Windows. The domain of file descriptors and socketsoverlap. There is no way for GLib to know which one you mean in casethe argument you pass to this function happens to be both a valid filedescriptor and socket. If that happens a warning is issued, and GLibassumes that it is the file descriptor you mean.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>fd</code></em>&#160;:</span></p></td><td>a file descriptor.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>a new <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2929572"></a><h3><a name="g-io-channel-unix-get-fd"></a>g_io_channel_unix_get_fd ()</h3><a class="indexterm" name="id2929585"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a>                g_io_channel_unix_get_fd            (<a class="link" href="glib-IO-Channels.html#GIOChannel">GIOChannel</a> *channel);</pre><p>Returns the file descriptor of the <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>.</p><p>On Windows this function returns the file descriptor or socket of the <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>channel</code></em>&#160;:</span></p></td><td>a <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>, created with <a class="link" href="glib-IO-Channels.html#g-io-channel-unix-new"><code class="function">g_io_channel_unix_new()</code></a>.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>the file descriptor of the <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2929690"></a><h3><a name="g-io-channel-win32-new-fd"></a>g_io_channel_win32_new_fd ()</h3><a class="indexterm" name="id2929704"></a><pre class="programlisting"><a class="link" href="glib-IO-Channels.html#GIOChannel">GIOChannel</a>*         g_io_channel_win32_new_fd           (<a class="link" href="glib-Basic-Types.html#gint">gint</a> fd);</pre><p>Creates a new <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> given a file descriptor on Windows. This works for file descriptors from the C runtime.</p><p>This function works for file descriptors as returned by the <code class="function">open()</code>,<code class="function">creat()</code>, <code class="function">pipe()</code> and <code class="function">fileno()</code> calls in the Microsoft C runtime. Inorder to meaningfully use this function your code should use the sameC runtime as GLib uses, which is msvcrt.dll. Note that in currentMicrosoft compilers it is near impossible to convince it to build codethat would use msvcrt.dll. The last Microsoft compiler version thatsupported using msvcrt.dll as the C runtime was version 6. The GNUcompiler and toolchain for Windows, also known as Mingw, fullysupports msvcrt.dll.</p><p>If you have created a <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> for a file descriptor and startedwatching (polling) it, you shouldn't call <code class="function">read()</code> on the filedescriptor. This is because adding polling for a file descriptor isimplemented in GLib on Windows by starting a thread that sits blockedin a <code class="function">read()</code> from the file descriptor most of the time. All reads fromthe file descriptor should be done by this internal GLib thread. Yourcode should call only <a class="link" href="glib-IO-Channels.html#g-io-channel-read"><code class="function">g_io_channel_read()</code></a>.</p><p>This function is available only in GLib on Windows.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>fd</code></em>&#160;:</span></p></td><td>a C library file descriptor.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td>a new <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2927428"></a><h3><a name="g-io-channel-win32-new-socket"></a>g_io_channel_win32_new_socket ()</h3><a class="indexterm" name="id2927441"></a><pre class="programlisting"><a class="link" href="glib-IO-Channels.html#GIOChannel">GIOChannel</a>*         g_io_channel_win32_new_socket       (<a class="link" href="glib-Basic-Types.html#gint">gint</a> socket);</pre><p>Creates a new <a class="link" href="glib-IO-Channels.html#GIOChannel"><span class="type">GIOChannel</span></a> given a socket on Windows.</p><p>This function works for sockets created by Winsock. It's available only in GLib on Windows.</p><p>Polling a <a class="link" href="glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> created to watch a channel for a socket puts the socket in non-blocking mode. This is a side-effect of the implementation and unavoidable.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>socket</code></em>&#160;:</span></p></td>

⌨️ 快捷键说明

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