title: Do I need a write buffer for socket in go?
body: <p>Suppose I had a Tcp server in linux, it would create a new goroutine for a new connnection. When I want to write data to the tcp connection, should I do it just like this </p>
  
  <pre><code>conn.Write(data)
  </code></pre>
  
  <p>or do it in a goroutine especially for writing, like this</p>
  
  <pre><code>func writeRoutine(sendChan chan []byte){
        for {
         select {
         case  msg := &lt;- sendChan :
            conn.Write(msg)
         }
        }
  }
  </code></pre>
  
  <p>just in case that the network was busy.</p>
  
  <p>In a short,  Did I need a write buffer in go just like in c/c++ when writing to a socket?</p>
  
  <p>PS   maybe I didn't exclaim the problem clearly. </p>
  
  <p>1     I talked of the server, meaning a tcp server runing in linux. It would create a new goroutine for a new connnection.  like this</p>
  
  <pre><code>   listener, err := net.ListenTCP("tcp", tcpAddr)
      if err != nil {
          log.Error(err.Error())
          os.Exit(-1)
      }
      for {
          conn, err := listener.AcceptTCP()
          if err != nil {
              continue
          }
          log.Debug("Accept a new connection ", conn.RemoteAddr())
          go handleClient(conn)
      }
  </code></pre>
  
  <p>2  I think my problem isn't much concerned with the code. As we know, when we use <code>size_t write(int fd, const void *buf, size_t count);</code> to write a socket fd in c/c++, for a tcp server, we need a write buffer for a socket in your code necessaryly, or maybe only some of the data is writen successfully. I mean, Do I have to do so in go ?</p>