title: Go net conn.SetWriteDeadline function usage
body: <p>I cannot understand how to use net <code>conn.SetWriteDeadline</code> function?</p>
  
  <pre><code>conn, err := net.DialTimeout("tcp", "10.1.10.1:2000", 3*time.Second)
      if err!=nil{
          fmt.Println("Error: ", err)
      }
  //waits as expected 3 seconds and returns error if dial not succeeded
  
  conn.SetWriteDeadline(time.Now().Add(5*time.Second))
      n, err:= conn.Write([]byte{0x00})
  
      if err != nil {
          fmt.Printf("Write: %v", err)
      }
  
      fmt.Println("Bytes wrote: ", n)
  //always returns n=1, no wait, no error if connection lost.
  </code></pre>
  
  <p>I expect that <code>conn.Write</code> must try to write data to port during 5 seconds and then it must return <code>n=0</code> and error if there is a trouble with connection. But, even if I unplug network cable, it returns no error and <code>n=1</code>.</p>
  
  <p>If I try to do something like this,</p>
  
  <pre><code>for {
          conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
          n, err = conn.Write(buffer)
          if err != nil {
              log.Println("Timeout error")            
          } else {
              break
          }
          if t.GetElapsed() &gt;= 30*time.Second {
              err = errors.New("Connection timeout")
              break
          }
      }
  </code></pre>
  
  <p>I expect that there will be several attempts to write data, with escaping from <code>FOR</code> if succeeded, or via timeout. But behaviour is the same - even if network is disconnected, there is no error, there is only <code>1</code> iteration.
  What am I doing wrong? How to use? How to understand if data has been really written to port? How to handle disconnection?</p>