2 // Copyright © 2017-2019 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed, an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 ExpiredNotification is a callback function, provided by the client
23 and called when a deadline expires. The err parameter will contain
24 the actual expired error. The rw parameter will be true if
25 the notification is for a write, and false otherwise.
27 type ExpiredNotification
func(err error
, rw
bool)
30 DeadlineData controls the use of deadlines in network I/O.
32 type deadlineData
struct {
33 wde
bool // Write deadline data enabled
34 wdld time
.Duration
// Write deadline duration
35 wds
bool // True if write duration has been set
37 dlnotify ExpiredNotification
38 dns
bool // True if dlnotify has been set
40 rde
bool // Read deadline data enabled
41 rdld time
.Duration
// Read deadline duration
42 rds
bool // True if read duration has been set
43 t0 time
.Time
// 0 value of Time
45 rfsw
bool // Attempt to recover from short writes
49 WriteDeadline sets the write deadline duration.
51 func (c
*Connection
) WriteDeadline(d time
.Duration
) {
52 c
.log("Write Deadline", d
)
58 EnableWriteDeadline enables/disables the use of write deadlines.
60 func (c
*Connection
) EnableWriteDeadline(e
bool) {
61 c
.log("Enable Write Deadline", e
)
66 ExpiredNotification sets the expired notification callback function.
68 func (c
*Connection
) ExpiredNotification(enf ExpiredNotification
) {
69 c
.log("Set ExpiredNotification")
75 IsWriteDeadlineEnabled returns the current value of write deadline
78 func (c
*Connection
) IsWriteDeadlineEnabled() bool {
83 ReadDeadline sets the write deadline duration.
85 func (c
*Connection
) ReadDeadline(d time
.Duration
) {
86 c
.log("Read Deadline", d
)
92 EnableReadDeadline enables/disables the use of read deadlines.
94 func (c
*Connection
) EnableReadDeadline(e
bool) {
95 c
.log("Enable Read Deadline", e
)
100 IsReadDeadlineEnabled returns the current value of write deadline
103 func (c
*Connection
) IsReadDeadlineEnabled() bool {
108 ShortWriteRecovery enables / disables short write recovery.
111 func (c
*Connection
) ShortWriteRecovery(ro
bool) {
112 c
.dld
.rfsw
= ro
// Set recovery option