Rework writer deadline handling.
[stompngo.git] / deadline_data.go
blobebe27f4e0b1db8f64c1dbada109e563d7e026e39
1 //
2 // Copyright © 2017 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
46 WriteDeadline sets the write deadline duration.
48 func (c *Connection) WriteDeadline(d time.Duration) {
49 c.log("Write Deadline", d)
50 c.dld.wdld = d
51 c.dld.wds = true
55 EnableWriteDeadline enables/disables the use of write deadlines.
57 func (c *Connection) EnableWriteDeadline(e bool) {
58 c.log("Enable Write Deadline", e)
59 c.dld.wde = e
63 ExpiredNotification sets the expired notification callback function.
65 func (c *Connection) ExpiredNotification(enf ExpiredNotification) {
66 c.log("Set ExpiredNotification")
67 c.dld.dlnotify = enf
68 c.dld.dns = true
72 IsWriteDeadlineEnabled returns the current value of write deadline
73 enablement.
75 func (c *Connection) IsWriteDeadlineEnabled() bool {
76 return c.dld.wde
80 ReadDeadline sets the write deadline duration.
82 func (c *Connection) ReadDeadline(d time.Duration) {
83 c.log("Read Deadline", d)
84 c.dld.rdld = d
85 c.dld.rds = true
89 EnableReadDeadline enables/disables the use of read deadlines.
91 func (c *Connection) EnableReadDeadline(e bool) {
92 c.log("Enable Read Deadline", e)
93 c.dld.rde = e
97 IsReadDeadlineEnabled returns the current value of write deadline
98 enablement.
100 func (c *Connection) IsReadDeadlineEnabled() bool {
101 return c.dld.rde