Add flock implementation for spool file locking, should be race free now.

Need to move generic buffering code into Server.hs.