Version bump.
[stompngo.git] / deadline_data.go
blob7930bc8470cdf201bcd025ad492409b1936ccd45
1 //
2 // Copyright © 2017-2019 Guy M. Allard
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
17 package stompngo
19 import "time"
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)
53 c.dld.wdld = d
54 c.dld.wds = true
58 EnableWriteDeadline enables/disables the use of write deadlines.
60 func (c *Connection) EnableWriteDeadline(e bool) {
61 c.log("Enable Write Deadline", e)
62 c.dld.wde = e
66 ExpiredNotification sets the expired notification callback function.
68 func (c *Connection) ExpiredNotification(enf ExpiredNotification) {
69 c.log("Set ExpiredNotification")
70 c.dld.dlnotify = enf
71 c.dld.dns = true
75 IsWriteDeadlineEnabled returns the current value of write deadline
76 enablement.
78 func (c *Connection) IsWriteDeadlineEnabled() bool {
79 return c.dld.wde
83 ReadDeadline sets the write deadline duration.
85 func (c *Connection) ReadDeadline(d time.Duration) {
86 c.log("Read Deadline", d)
87 c.dld.rdld = d
88 c.dld.rds = true
92 EnableReadDeadline enables/disables the use of read deadlines.
94 func (c *Connection) EnableReadDeadline(e bool) {
95 c.log("Enable Read Deadline", e)
96 c.dld.rde = e
100 IsReadDeadlineEnabled returns the current value of write deadline
101 enablement.
103 func (c *Connection) IsReadDeadlineEnabled() bool {
104 return c.dld.rde
108 ShortWriteRecovery enables / disables short write recovery.
109 enablement.
111 func (c *Connection) ShortWriteRecovery(ro bool) {
112 c.dld.rfsw = ro // Set recovery option