   let debugAsyncWrites = false
   
   func asyncWrite<T>(buffer: T[], length: Int? = nil) -> Bool {
-    if !isValid { // ps: awesome error handling
-      println("Socket closed, can't do async writes anymore")
+    if !isValid {
+      assert(isValid, "Socket closed, can't do async writes anymore")
+      return false
+    }
+    if closeRequested {
+      assert(!closeRequested, "Socket is being shutdown already!")
       return false
     }
     

    
    sendCount++
    if debugAsyncWrites {
      println("sending data \(sendCount) size \(bufsize)")
    }
    
    // in here we capture self, which I think is right.
    dispatch_write(fd!, asyncData, queue) { asyncData, error in
      self.sendCount = self.sendCount - 1 // -- fails?
      if self.debugAsyncWrites {
        println("did send data \(self.sendCount) error \(error)")
      }
      
      if self.sendCount == 0 && self.closeRequested {
        self.close()
        self.closeRequested = false
      }
    }
    
    return true
  }

  func send(buffer: CChar[], length: Int? = nil) -> Int {
    var writeCount : Int = 0
    let bufsize    = length ? UInt(length!) : UInt(buffer.count)
    let fd         = self.fd!

  var encoding: UInt { return NSUTF8StringEncoding }
  
  func write(string: String) {
    // FIXME: this actually requires Foundation ...
    // can also do this using String encoding
    if let buffer = string.cStringUsingEncoding(encoding) {
      if buffer.count > 1 { // remove \0 terminator
        self.asyncWrite(buffer, length: buffer.count - 1)
      }
    }
  }
