golang epoll发送消息后必须关闭套接字吗?

go func() {
    for req := range respChan {
        content := make([]byte, 0, 1024*32)
        content = append(content, []byte("HTTP1.1 200 OK
")...)
        for k, v := range req.Response.Headers {
            content = append(content, []byte(fmt.Sprintf("%s:%s
", k, v))...)
        }
        content = append(content, []byte("
")...)
        content = append(content, req.Response.Content...)
        fmt.Println(string(content[:]))
        _, err := syscall.Write(int(req.Fd), content)
        handleEpollError(err)
    }
}()

I try to implement a http server by linux epoll, eventhing is ok but browser always keep waiting after server finish sending by socket until I interrupt the process. Should I send some terminate characters or do other terminate operation? Above is only the code writing http response by socket.

There's a typo on the status line. Use

content = append(content, []byte("HTTP/1.1 200 OK
")...)

The server should do one of the following to terminate the request body:

  • Specify the Content-Length header with the length of the body.
  • Write a chunked response with a terminating chunk.
  • Specify Connection: close header and close connection after writing response.