add proper read & write timeouts
This commit is contained in:
parent
0a124def84
commit
cfcbbb0962
17
server.go
17
server.go
|
@ -19,6 +19,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const readTimeout = 10 // seconds
|
||||||
|
const writeTimeout = 10 // seconds
|
||||||
|
|
||||||
type tlsConnectionInfo struct {
|
type tlsConnectionInfo struct {
|
||||||
TlsVersion uint16 `json:"tls_version"`
|
TlsVersion uint16 `json:"tls_version"`
|
||||||
CipherSuite uint16 `json:"cipher_suite"`
|
CipherSuite uint16 `json:"cipher_suite"`
|
||||||
|
@ -236,12 +239,24 @@ func main() {
|
||||||
log.Println("Server started")
|
log.Println("Server started")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
// Wait for a connection.
|
||||||
conn, err := ln.Accept()
|
conn, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error accepting: ", err.Error())
|
log.Println("Error accepting: ", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
conn.SetReadDeadline(time.Now().Add(5 * time.Second)) // timeout
|
// Set connection timeouts.
|
||||||
|
err = conn.SetReadDeadline(time.Now().Add(readTimeout * time.Second))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("SetReadDeadline error: ", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = conn.SetWriteDeadline(time.Now().Add(writeTimeout * time.Second))
|
||||||
|
if err != nil {
|
||||||
|
log.Println("SetWriteDeadline error: ", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Process the request.
|
||||||
go peek(conn, &tlsConfig)
|
go peek(conn, &tlsConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue