<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,12 +1,12 @@
 -- Simple program to play an Internet radio stream using the GHC GStreamer
--- bindings. Most of the GStreamer boiler plate was copied from the demo app in
+-- bindings. Most of the GStreamer boilerplate was copied from the demo app in
 -- the gtk2hs source code.
 --
 -- For now, the steam must be of mpeg audio (i.e. mp3).
 
 import Network
 import System.IO
-import qualified Data.ByteString.Lazy as BSL
+import qualified Data.ByteString.Lazy as BS
 
 import System.Environment
 
@@ -48,7 +48,7 @@ makeHTTPRequest domain path = (
     ++ &quot;Hostname: &quot; ++ domain ++ &quot;\r\n&quot;
     ++ &quot;User-Agent: radio-player &lt;http://github.com/eklitzke/radio-player&gt;\r\n\r\n&quot; )
 
--- skip over the HTTP headers
+-- skip over HTTP headers
 skipResponseHeaders :: Handle -&gt; IO ()
 skipResponseHeaders hdl = do
     ln &lt;- hGetLine hdl
@@ -61,13 +61,17 @@ writeHTTPRequest sock s = do
     hPutStr sock s
     hFlush sock
 
+-- Read from a handle (lazily) and write it out to another handle (eagerly).
+-- This is meant to be called as a separate thread with forkIO
 writeToFifo :: Handle -&gt; Handle -&gt; IO ()
 writeToFifo sock out = do
-    s &lt;- BSL.hGetContents sock
-    BSL.hPutStr out $! s
+    s &lt;- BS.hGetContents sock
+    BS.hPutStr out s
 
 main = do
-
+    -- Parse the command line options. Two formats are accepted:
+    --  1) radio &lt;preset-name&gt;
+    --  2) radio &lt;domain&gt; &lt;path&gt; &lt;port&gt;
     args &lt;- getArgs
     [domain, path, port] &lt;- return $ case args of
         [s] -&gt; case s of
@@ -76,21 +80,27 @@ main = do
             &quot;kalx&quot; -&gt; [&quot;icecast.media.berkeley.edu&quot;, &quot;/kalx-128.mp3&quot;, &quot;8000&quot;]
         _ -&gt; args
 
+    -- Create a named pipe if it doesn't exist. For some reason, this doesn't
+    -- work right on my laptop (no matter what I do, the file created doesn't
+    -- have the fifo bit). For now, you just need to create it yourself with
+    -- mkfifo.
     exists &lt;- fileExist fifoName
     if exists
         then return $ Left ()
         else return $ Right $ createNamedPipe fifoName fifoMode
 
-    let httpReq = makeHTTPRequest domain path
-
+    -- Connect to the mpeg stream, and get ready to read mpeg data
     sock &lt;- connectTo domain $ PortNumber $ fromIntegral (read port :: Int)
-    writeHTTPRequest sock httpReq
+    writeHTTPRequest sock $ makeHTTPRequest domain path
     skipResponseHeaders sock
 
+    -- Open the named pipe in read/write mode
     fifo &lt;- openFile fifoName ReadWriteMode
 
+    -- Copy the contents of the socket to the named pipe in a separate &quot;thread&quot;
     myThreadId &lt;- forkIO $ writeToFifo sock fifo
 
+    -- GStreamer boilerplate
     Gst.init
     mainLoop &lt;- G.mainLoopNew Nothing True
 </diff>
      <filename>radio.hs</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>40eafa26a95f75c2aa38f2a53ed4aa9116688eb5</id>
    </parent>
  </parents>
  <author>
    <name>Evan Klitzke</name>
    <email>evan@eklitzke.org</email>
  </author>
  <url>http://github.com/eklitzke/radio-player/commit/45883714691267ac8bb6f6b6a62161d7d8a62501</url>
  <id>45883714691267ac8bb6f6b6a62161d7d8a62501</id>
  <committed-date>2008-10-18T00:21:42-07:00</committed-date>
  <authored-date>2008-10-18T00:21:42-07:00</authored-date>
  <message>comments</message>
  <tree>9d391b49abd96e60ee16dff8084f78eef41b2947</tree>
  <committer>
    <name>Evan Klitzke</name>
    <email>evan@eklitzke.org</email>
  </committer>
</commit>
