<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ray Strode &#187; Programming</title>
	<atom:link href="http://blogs.gnome.org/halfline/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.gnome.org/halfline</link>
	<description>So...</description>
	<lastBuildDate>Tue, 17 Nov 2009 15:43:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Plymouth Multi-head support</title>
		<link>http://blogs.gnome.org/halfline/2009/09/29/plymouth-multi-head-support/</link>
		<comments>http://blogs.gnome.org/halfline/2009/09/29/plymouth-multi-head-support/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:03:27 +0000</pubDate>
		<dc:creator>halfline</dc:creator>
				<category><![CDATA[Graphical Boot]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/halfline/?p=52</guid>
		<description><![CDATA[So it&#8217;s been a while since I&#8217;ve blogged.
This is just a short blog post to say that I landed multi-head support on plymouth master yesterday.  More details here:
http://lists.freedesktop.org/archives/plymouth/2009-September/000188.html
What this means is the boot splash redraws itself once per monitor,  in a way that looks good for the native resolution each monitor.  Previously, we&#8217;d draw right [...]]]></description>
			<content:encoded><![CDATA[<p>So it&#8217;s been a while since I&#8217;ve blogged.</p>
<p>This is just a short blog post to say that I landed multi-head support on plymouth master yesterday.  More details here:</p>
<p>http://lists.freedesktop.org/archives/plymouth/2009-September/000188.html</p>
<p>What this means is the boot splash redraws itself once per monitor,  in a way that looks good for the native resolution each monitor.  Previously, we&#8217;d draw right on the fb console, which is cloned across all monitors.  That made the splash have large black margins on some monitors, or look stretched.</p>
<p>One implication of this change is we now use libdrm directly when possible instead of going through the /dev/fb interface.</p>
<p>We still don&#8217;t do any accelerated rendering.  We don&#8217;t really need it, since plymouth splashes are normally designed to be very simple (Think &#8220;cell phone splash&#8221; not &#8220;3D video grame&#8221;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/halfline/2009/09/29/plymouth-multi-head-support/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>calling i/o functions in a loop</title>
		<link>http://blogs.gnome.org/halfline/2007/07/25/calling-io-functions-in-a-loop/</link>
		<comments>http://blogs.gnome.org/halfline/2007/07/25/calling-io-functions-in-a-loop/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 03:31:06 +0000</pubDate>
		<dc:creator>halfline</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blogs.gnome.org/halfline/2007/07/25/calling-io-functions-in-a-loop/</guid>
		<description><![CDATA[So one common programming idiom you&#8217;ll find a lot if you sniff around code in random projects is a helper function that reads or writes in a loop. Something almost, but not completely unlike&#8230;

bool write_it_harder (int fd, void *buf, size_t size_of_buf)
{
while (there are still bytes to write) {
the_number_of_bytes_written = write (fd, buf, the_number_of_bytes_left_to_write);
/* check for [...]]]></description>
			<content:encoded><![CDATA[<p>So one common programming idiom you&#8217;ll find a lot if you sniff around code in random projects is a helper function that reads or writes in a loop. Something almost, but not completely unlike&#8230;</p>
<p><code><br />
bool write_it_harder (int fd, void *buf, size_t size_of_buf)<br />
{<br />
while (there are still bytes to write) {<br />
the_number_of_bytes_written = write (fd, buf, the_number_of_bytes_left_to_write);<br />
/* check for errors then figure out the_number_of_bytes_left_to_write */<br />
}<br />
return true;<br />
}<br />
</code></p>
<p>THIS IS WRONG.  It&#8217;s not a good idea to do in a gui program.  It means that your app will</p>
<p>1) block until all the bytes are written (which could be a while, if the thing getting written to is slow)<br />
2) will completely fall over on some devices</p>
<p>It&#8217;s really better (although harder to code) to treat read()/write() as one-shot operations.  You do them once, get a result, and then should go back to poll() and wait for it to report that the fd you are working with is readable or writable again.</p>
<p>Another common one is:</p>
<p><code><br />
again:<br />
bytes_read = read (fd, buf, sizeof (buf));</code></p>
<p>if (bytes_read &lt; 0 &amp;&amp; errno == EAGAIN)<br />
goto again;</p>
<p>Again, THIS IS WRONG.</p>
<p>1) you may get into a situation where read() will return EAGAIN over and over again in a tight, battery killing, cpu heating loop<br />
2) there is no guarantee that you&#8217;ll get EAGAIN on successive calls anyway.  pseudo-terminals for instance, will give you EAGAIN once, and then EIO for successive calls.</p>
<p>So, only every call read() or write() when poll() says its okay to call them, and realize that if poll() says its okay to call them, it&#8217;s only saying it&#8217;s okay to call them ONCE, and you need to ask poll() permission to call them again.</p>
<p><strong>update</strong><br />
I&#8217;ve put a sample program up <a href="http://people.redhat.com/rstrode/cat.c">here</a> to show what I mean.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.gnome.org/halfline/2007/07/25/calling-io-functions-in-a-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
