cec39eb00c
Collapse ServerService and ClientService to one definition each by hiding Linux vs Darwin behind ExportHost, ImportHost, and Export seams. Along the way, extract three state machines that previously lived as scattered fields on the service structs: - LeaseManager owns its own mutex and closes the availability-vs-insert TOCTOU by checking export busy inside Issue under the same lock as the insert. - DataSession gives the three per-import data-plane implementations (Linux kernel handoff, Darwin server data session, Darwin virtual controller) a uniform Done/Err/Close interface. - clientAssignment encapsulates the matched/import-all target state and exposes ApplyMatched/ApplyAll diffs to ClientService, which keeps worker goroutine lifecycle. Service busy tracking moves off the per-platform serverExport struct onto ServerService.busy, since it follows the lease/import lifecycle rather than physical claim/release. linux_test.go is migrated to construct ServerService and ClientService through the new host interfaces.
26 lines
1.1 KiB
Go
26 lines
1.1 KiB
Go
package usbip
|
|
|
|
// DataSession is the per-import data-plane lifecycle. Once an import
|
|
// handshake succeeds, the server hands the wire connection off to a
|
|
// DataSession that runs until the device detaches or the caller closes
|
|
// it. Three concrete implementations exist:
|
|
//
|
|
// - kernelHandoffSession (Linux): writes the socket fd to usbip_sockfd
|
|
// and lets the kernel drive the data plane; monitors the dup'd fd
|
|
// for hang-up.
|
|
// - darwinServerDataSession (Darwin server): reads USB/IP commands,
|
|
// dispatches them to an IOUSBHost-backed device, writes replies back.
|
|
// - darwinVirtualController (Darwin client): synthesizes an
|
|
// IOUSBHostControllerInterface and translates IOKit traffic into
|
|
// USB/IP frames on the wire.
|
|
//
|
|
// Implementations MUST close the channel returned by Done when the
|
|
// session terminates for any reason. Err is only valid after Done is
|
|
// closed; it returns nil for a clean detach. Close is idempotent and
|
|
// safe to call from any goroutine.
|
|
type DataSession interface {
|
|
Done() <-chan struct{}
|
|
Err() error
|
|
Close() error
|
|
}
|