Skip to content

Commit 9e22147

Browse files
committed
Added the usb-send-delay-threshold quirk
This quirk limits usb-send-delay effect only to requests which size exceeds the threshold. See #95 for discussion and details.
1 parent 5f859ac commit 9e22147

4 files changed

Lines changed: 60 additions & 40 deletions

File tree

ipp-usb.8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ Don't use more that N USB interfaces, even if more is available\.
320320
.br
321321
Delay between low\-level USB send\-to\-device requests (this is not the same as \fBrequest\-delay\fR, which inserts delays between the whole HTTP\-level requests)\.
322322
.IP "\(bu" 4
323+
\fBusb\-send\-delay\-threshold = DELAY\fR
324+
.br
325+
\fBusb\-send\-delay\fR only applied if USB send\-to\-device request size exceeds this threshold\.
326+
.IP "\(bu" 4
323327
\fBzlp\-recv\-hack = true | false\fR
324328
.br
325329
Some enterprise\-level HP devices, during the initialization phase (which can last several minutes), may respond with an HTTP 503 status or similar, which is expected\. However, the response body may be truncated (typically, the terminating '\en' is lost)\. In such cases, \fBipp\-usb\fR will wait indefinitely for a response to maintain synchronization with the device\.

ipp-usb.8.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ The following parameters are defined:
407407
the same as `request-delay`, which inserts delays between the
408408
whole HTTP-level requests).
409409

410+
* `usb-send-delay-threshold = DELAY`<br>
411+
`usb-send-delay` only applied if USB send-to-device request size
412+
exceeds this threshold.
413+
410414
* `zlp-recv-hack = true | false`<br>
411415
Some enterprise-level HP devices, during the initialization phase
412416
(which can last several minutes), may respond with an HTTP 503

quirks.go

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,55 +35,58 @@ type Quirk struct {
3535
// Quirk names. Use these constants instead of literal strings,
3636
// so compiler will catch a mistake:
3737
const (
38-
QuirkNmBlacklist = "blacklist"
39-
QuirkNmBuggyIppResponses = "buggy-ipp-responses"
40-
QuirkNmDisableFax = "disable-fax"
41-
QuirkNmIgnoreIppStatus = "ignore-ipp-status"
42-
QuirkNmInitDelay = "init-delay"
43-
QuirkNmInitReset = "init-reset"
44-
QuirkNmInitRetryPartial = "init-retry-partial"
45-
QuirkNmInitTimeout = "init-timeout"
46-
QuirkNmRequestDelay = "request-delay"
47-
QuirkNmUsbMaxInterfaces = "usb-max-interfaces"
48-
QuirkNmUsbSendDelay = "usb-send-delay"
49-
QuirkNmZlpRecvHack = "zlp-recv-hack"
50-
QuirkNmZlpSend = "zlp-send"
38+
QuirkNmBlacklist = "blacklist"
39+
QuirkNmBuggyIppResponses = "buggy-ipp-responses"
40+
QuirkNmDisableFax = "disable-fax"
41+
QuirkNmIgnoreIppStatus = "ignore-ipp-status"
42+
QuirkNmInitDelay = "init-delay"
43+
QuirkNmInitReset = "init-reset"
44+
QuirkNmInitRetryPartial = "init-retry-partial"
45+
QuirkNmInitTimeout = "init-timeout"
46+
QuirkNmRequestDelay = "request-delay"
47+
QuirkNmUsbMaxInterfaces = "usb-max-interfaces"
48+
QuirkNmUsbSendDelayThreshold = "usb-send-delay-threshold"
49+
QuirkNmUsbSendDelay = "usb-send-delay"
50+
QuirkNmZlpRecvHack = "zlp-recv-hack"
51+
QuirkNmZlpSend = "zlp-send"
5152
)
5253

5354
// quirkParse maps quirk names into appropriate parsing methods,
5455
// which defines value syntax and resulting type.
5556
var quirkParse = map[string]func(*Quirk) error{
56-
QuirkNmBlacklist: (*Quirk).parseBool,
57-
QuirkNmBuggyIppResponses: (*Quirk).parseQuirkBuggyIppRsp,
58-
QuirkNmDisableFax: (*Quirk).parseBool,
59-
QuirkNmIgnoreIppStatus: (*Quirk).parseBool,
60-
QuirkNmInitDelay: (*Quirk).parseDuration,
61-
QuirkNmInitReset: (*Quirk).parseQuirkResetMethod,
62-
QuirkNmInitRetryPartial: (*Quirk).parseBool,
63-
QuirkNmInitTimeout: (*Quirk).parseDuration,
64-
QuirkNmRequestDelay: (*Quirk).parseDuration,
65-
QuirkNmUsbMaxInterfaces: (*Quirk).parseUint,
66-
QuirkNmUsbSendDelay: (*Quirk).parseDuration,
67-
QuirkNmZlpRecvHack: (*Quirk).parseBool,
68-
QuirkNmZlpSend: (*Quirk).parseBool,
57+
QuirkNmBlacklist: (*Quirk).parseBool,
58+
QuirkNmBuggyIppResponses: (*Quirk).parseQuirkBuggyIppRsp,
59+
QuirkNmDisableFax: (*Quirk).parseBool,
60+
QuirkNmIgnoreIppStatus: (*Quirk).parseBool,
61+
QuirkNmInitDelay: (*Quirk).parseDuration,
62+
QuirkNmInitReset: (*Quirk).parseQuirkResetMethod,
63+
QuirkNmInitRetryPartial: (*Quirk).parseBool,
64+
QuirkNmInitTimeout: (*Quirk).parseDuration,
65+
QuirkNmRequestDelay: (*Quirk).parseDuration,
66+
QuirkNmUsbMaxInterfaces: (*Quirk).parseUint,
67+
QuirkNmUsbSendDelayThreshold: (*Quirk).parseUint,
68+
QuirkNmUsbSendDelay: (*Quirk).parseDuration,
69+
QuirkNmZlpRecvHack: (*Quirk).parseBool,
70+
QuirkNmZlpSend: (*Quirk).parseBool,
6971
}
7072

7173
// quirkDefaultStrings contains default values for quirks, in
7274
// a string form.
7375
var quirkDefaultStrings = map[string]string{
74-
QuirkNmBlacklist: "false",
75-
QuirkNmBuggyIppResponses: "reject",
76-
QuirkNmDisableFax: "false",
77-
QuirkNmIgnoreIppStatus: "false",
78-
QuirkNmInitDelay: "0",
79-
QuirkNmInitRetryPartial: "false",
80-
QuirkNmInitReset: "none",
81-
QuirkNmInitTimeout: DevInitTimeout.String(),
82-
QuirkNmRequestDelay: "0",
83-
QuirkNmUsbMaxInterfaces: "0",
84-
QuirkNmUsbSendDelay: "0",
85-
QuirkNmZlpRecvHack: "false",
86-
QuirkNmZlpSend: "false",
76+
QuirkNmBlacklist: "false",
77+
QuirkNmBuggyIppResponses: "reject",
78+
QuirkNmDisableFax: "false",
79+
QuirkNmIgnoreIppStatus: "false",
80+
QuirkNmInitDelay: "0",
81+
QuirkNmInitRetryPartial: "false",
82+
QuirkNmInitReset: "none",
83+
QuirkNmInitTimeout: DevInitTimeout.String(),
84+
QuirkNmRequestDelay: "0",
85+
QuirkNmUsbMaxInterfaces: "0",
86+
QuirkNmUsbSendDelayThreshold: "0",
87+
QuirkNmUsbSendDelay: "0",
88+
QuirkNmZlpRecvHack: "false",
89+
QuirkNmZlpSend: "false",
8790
}
8891

8992
// quirkDefault contains default values for quirks, precompiled.
@@ -362,6 +365,12 @@ func (quirks Quirks) GetUsbMaxInterfaces() uint {
362365
return quirks.Get(QuirkNmUsbMaxInterfaces).Parsed.(uint)
363366
}
364367

368+
// GetUsbSendDelayThreshold returns effective "usb-send-delay-threshold"
369+
// parameter taking the whole set into consideration.
370+
func (quirks Quirks) GetUsbSendDelayThreshold() uint {
371+
return quirks.Get(QuirkNmUsbSendDelay).Parsed.(uint)
372+
}
373+
365374
// GetUsbSendDelay returns effective "usb-send-delay" parameter
366375
// taking the whole set into consideration.
367376
func (quirks Quirks) GetUsbSendDelay() time.Duration {

usbio_libusb.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,10 @@ func (iface *UsbInterface) Send(ctx context.Context,
811811

812812
// Introduce inter-URB send delay, if configured
813813
if delay := iface.quirks.GetUsbSendDelay(); delay != 0 {
814-
time.Sleep(delay)
814+
threshold := int(iface.quirks.GetUsbSendDelayThreshold())
815+
if n > threshold {
816+
time.Sleep(delay)
817+
}
815818
}
816819

817820
return

0 commit comments

Comments
 (0)