Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* iss31: Initial implementation of optional write deadlines. Merge wire writes into one call per frame.
- Loading branch information
Showing
9 changed files
with
223 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright © 2017 Guy M. Allard | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed, an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package stompngo | ||
|
||
import "time" | ||
|
||
/* | ||
ExpiredNotification is a callback function, provided by the client | ||
and called when a deadline expires. The err parameter will contain | ||
the actual expired error. The rw parameter will be true if | ||
the notification is for a write, and false otherwise. | ||
*/ | ||
type ExpiredNotification func(err error, rw bool) | ||
|
||
/* | ||
DeadlineData controls the use of deadlines in network I/O. | ||
*/ | ||
type deadlineData struct { | ||
wde bool // Write deadline data enabled | ||
wdld time.Duration // Write deadline duration | ||
wds bool // True if duration has been set | ||
// | ||
dlnotify ExpiredNotification | ||
dns bool // True if dlnotify has been set | ||
} | ||
|
||
/* | ||
WriteDeadline sets the write deadline duration. | ||
*/ | ||
func (c *Connection) WriteDeadline(d time.Duration) { | ||
c.dld.wdld = d | ||
c.dld.wds = true | ||
} | ||
|
||
/* | ||
EnableWriteDeadline enables/disables the use of write deadlines. | ||
*/ | ||
func (c *Connection) EnableWriteDeadline(e bool) { | ||
c.dld.wde = e | ||
} | ||
|
||
/* | ||
ExpiredNotification sets the expired notification callback function. | ||
*/ | ||
func (c *Connection) ExpiredNotification(enf ExpiredNotification) { | ||
c.dld.dlnotify = enf | ||
c.dld.dns = true | ||
} | ||
|
||
/* | ||
IsWriteDeadlineEnabled returns the current value of write deadline | ||
enablement. | ||
*/ | ||
func (c *Connection) IsWriteDeadlineEnabled() bool { | ||
return c.dld.wde | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Copyright © 2017 Guy M. Allard | ||
// | ||
// Licensed under the Apache License, Veridon 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permisidons and | ||
// limitations under the License. | ||
// | ||
|
||
package stompngo | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
var _ = fmt.Println | ||
|
||
/* | ||
Test Deadline Enablement. | ||
*/ | ||
func TestDeadlineEnablement(t *testing.T) { | ||
n, _ = openConn(t) | ||
ch := login_headers | ||
conn, e = Connect(n, ch) | ||
if e != nil { | ||
t.Fatalf("TestDeadlineEnablement CONNECT expected nil, got %v\n", e) | ||
} | ||
// | ||
dle := conn.IsWriteDeadlineEnabled() | ||
if dle != wdleInit { | ||
t.Errorf("TestDeadlineEnablement expected false, got true\n") | ||
} | ||
checkReceived(t, conn) | ||
e = conn.Disconnect(empty_headers) | ||
checkDisconnectError(t, e) | ||
_ = closeConn(t, n) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters