Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vsock: set read/write timeout on the accepted connection #4450

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pkg/pillar/cmd/vcomlink/vsocksrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ func startVcomServer(listener SocketListener) {
}
defer unix.Close(fd)

// Set read timeout and write timeout
err = unix.SetsockoptTimeval(fd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &unix.Timeval{Sec: readTimeout})
if err != nil {
log.Errorf("Error setting read timeout: %v", err)
return
}
err = unix.SetsockoptTimeval(fd, unix.SOL_SOCKET, unix.SO_SNDTIMEO, &unix.Timeval{Sec: writeTimeout})
if err != nil {
log.Errorf("Error setting write timeout: %v", err)
return
}

for {
conn, _, err := unix.Accept(fd)
if err != nil {
Expand All @@ -69,6 +57,18 @@ func startVcomServer(listener SocketListener) {
continue
}

// Set read timeout and write timeout
err = unix.SetsockoptTimeval(conn, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &unix.Timeval{Sec: readTimeout})
if err != nil {
log.Errorf("error setting read timeout: %v", err)
return
}
err = unix.SetsockoptTimeval(conn, unix.SOL_SOCKET, unix.SO_SNDTIMEO, &unix.Timeval{Sec: writeTimeout})
if err != nil {
log.Errorf("error setting write timeout: %v", err)
return
}

go handleConnection(conn)
}
}
Expand Down
Loading