Make HostBountEndpoint.SetBoundSocketFD take ownership of bound socket FD.

Earlier SetBoundSocketFD() was taking ownership of bound socket FD only on
success. Having it take ownership unconditionally is cleaner.

PiperOrigin-RevId: 516903597
This commit is contained in:
Ayush Ranjan
2023-03-15 12:53:27 -07:00
committed by gVisor bot
parent 4c5803c47f
commit 6669003321
4 changed files with 7 additions and 8 deletions
@@ -595,10 +595,11 @@ func (e *connectionedEndpoint) OnSetSendBufferSize(v int64) (newSz int64) {
func (e *connectionedEndpoint) WakeupWriters() {}
// SetBoundSocketFD implement HostBountEndpoint.SetBoundSocketFD.
func (e *connectionedEndpoint) SetBoundSocketFD(bsFD BoundSocketFD) error {
func (e *connectionedEndpoint) SetBoundSocketFD(ctx context.Context, bsFD BoundSocketFD) error {
e.Lock()
defer e.Unlock()
if e.path != "" || e.boundSocketFD != nil {
bsFD.Close(ctx)
return syserr.ErrAlreadyBound.ToError()
}
e.boundSocketFD = bsFD
+3 -3
View File
@@ -269,9 +269,9 @@ type BoundEndpoint interface {
type HostBoundEndpoint interface {
// SetBoundSocketFD will be called on supporting endpoints after
// binding a socket on the host filesystem. Implementations should
// delegate Listen and Accept calls to the BoundSocketFD. On success,
// the ownership of bsFD is transferred to the endpoint.
SetBoundSocketFD(bsFD BoundSocketFD) error
// delegate Listen and Accept calls to the BoundSocketFD. The ownership
// of bsFD is transferred to the endpoint.
SetBoundSocketFD(ctx context.Context, bsFD BoundSocketFD) error
// ResetBoundSocketFD cleans up the BoundSocketFD set by the last successful
// SetBoundSocketFD call.