mirror of
https://github.com/renorris/openfsd
synced 2026-04-13 04:35:41 +08:00
Compare commits
1 Commits
v1.0-beta.
...
v1.0-beta.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8affb6210e |
@@ -108,6 +108,8 @@ func (s *Server) eventLoop(client *Client) {
|
|||||||
go client.senderWorker()
|
go client.senderWorker()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
// Set deadline and attempt to read
|
||||||
|
client.conn.SetReadDeadline(getTimeBySecondsInFuture(s.cfg.ConnectionTimeoutSeconds))
|
||||||
if !client.scanner.Scan() {
|
if !client.scanner.Scan() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,11 @@ func (s *Server) handleConn(ctx context.Context, conn net.Conn) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
// Set timeout for login phase
|
||||||
|
conn.SetDeadline(getTimeBySecondsInFuture(s.cfg.ConnectionTimeoutSeconds))
|
||||||
|
|
||||||
if err := sendServerIdent(conn); err != nil {
|
if err := sendServerIdent(conn); err != nil {
|
||||||
fmt.Printf("Error sending server ident: %v\n", err)
|
fmt.Printf("Error sending server ident: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ type ServerConfig struct {
|
|||||||
NumMetarWorkers int `env:"NUM_METAR_WORKERS, default=4"` // Number of METAR fetch workers to run
|
NumMetarWorkers int `env:"NUM_METAR_WORKERS, default=4"` // Number of METAR fetch workers to run
|
||||||
|
|
||||||
ServiceHTTPListenAddr string `env:"SERVICE_HTTP_LISTEN_ADDR, default=:13618"`
|
ServiceHTTPListenAddr string `env:"SERVICE_HTTP_LISTEN_ADDR, default=:13618"`
|
||||||
|
|
||||||
|
// Seconds after which a connection will be closed for inactivity
|
||||||
|
ConnectionTimeoutSeconds int `env:"CONNECTION_TIMEOUT_SECONDS, default=30"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadServerConfig(ctx context.Context) (config *ServerConfig, err error) {
|
func loadServerConfig(ctx context.Context) (config *ServerConfig, err error) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FSD error codes
|
// FSD error codes
|
||||||
@@ -418,3 +419,8 @@ func sendSendFastPacket(client *Client, enabled bool) {
|
|||||||
|
|
||||||
client.send(builder.String())
|
client.send(builder.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getTimeBySecondsInFuture returns time.Now + seconds
|
||||||
|
func getTimeBySecondsInFuture(seconds int) time.Time {
|
||||||
|
return time.Now().Add(time.Duration(seconds) * time.Second)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user