aboutsummaryrefslogtreecommitdiff
path: root/nexgb/cookie.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-10 17:01:42 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-05-10 17:01:42 -0400
commit0c50dc6241fa21712e041cfa2bfb9db4ccaef10a (patch)
tree90a3200414c8ad6df8e7983a8e73fedfbe2b324e /nexgb/cookie.go
parente239bb3c68a4981a3916534203c2fbd6b96f593c (diff)
downloadhaven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.tar.gz
haven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.tar.xz
haven-0c50dc6241fa21712e041cfa2bfb9db4ccaef10a.zip
a huge commit. splitting extensions into their own sub-packages.
Diffstat (limited to 'nexgb/cookie.go')
-rw-r--r--nexgb/cookie.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/nexgb/cookie.go b/nexgb/cookie.go
index 8c0774d..0f32990 100644
--- a/nexgb/cookie.go
+++ b/nexgb/cookie.go
@@ -4,11 +4,11 @@ import (
"errors"
)
-// cookie is the internal representation of a cookie, where one is generated
+// Cookie is the internal representation of a cookie, where one is generated
// for *every* request sent by XGB.
// 'cookie' is most frequently used by embedding it into a more specific
// kind of cookie, i.e., 'GetInputFocusCookie'.
-type cookie struct {
+type Cookie struct {
conn *Conn
Sequence uint16
replyChan chan []byte
@@ -22,8 +22,10 @@ type cookie struct {
// function for more info on those.)
// Note that a sequence number is not set until just before the request
// corresponding to this cookie is sent over the wire.
-func (c *Conn) newCookie(checked, reply bool) *cookie {
- cookie := &cookie{
+// This function should not be used. It is exported for use in the extension
+// sub-packages.
+func (c *Conn) NewCookie(checked, reply bool) *Cookie {
+ cookie := &Cookie{
conn: c,
Sequence: 0, // we add the sequence id just before sending a request
replyChan: nil,
@@ -60,21 +62,23 @@ func (c *Conn) newCookie(checked, reply bool) *cookie {
return cookie
}
-// reply detects whether this is a checked or unchecked cookie, and calls
+// Reply detects whether this is a checked or unchecked cookie, and calls
// 'replyChecked' or 'replyUnchecked' appropriately.
-func (c cookie) reply() ([]byte, error) {
+// This should not be used. It is exported for use in extension sub-packages.
+func (c Cookie) Reply() ([]byte, error) {
// checked
if c.errorChan != nil {
- return c.replyChecked()
+ return c.ReplyChecked()
}
- return c.replyUnchecked()
+ return c.ReplyUnchecked()
}
-// replyChecked waits for a response on either the replyChan or errorChan
+// ReplyChecked waits for a response on either the replyChan or errorChan
// channels. If the former arrives, the bytes are returned with a nil error.
// If the latter arrives, no bytes are returned (nil) and the error received
// is returned.
-func (c cookie) replyChecked() ([]byte, error) {
+// This should not be used. It is exported for use in extension sub-packages.
+func (c Cookie) ReplyChecked() ([]byte, error) {
if c.replyChan == nil {
return nil, errors.New("Cannot call 'replyChecked' on a cookie that " +
"is not expecting a *reply* or an error.")
@@ -93,13 +97,14 @@ func (c cookie) replyChecked() ([]byte, error) {
panic("unreachable")
}
-// replyChecked waits for a response on either the replyChan or pingChan
+// ReplyChecked waits for a response on either the replyChan or pingChan
// channels. If the former arrives, the bytes are returned with a nil error.
// If the latter arrives, no bytes are returned (nil) and a nil error
// is returned. (In the latter case, the corresponding error can be retrieved
// from (Wait|Poll)ForEvent asynchronously.)
// In all honesty, you *probably* don't want to use this method.
-func (c cookie) replyUnchecked() ([]byte, error) {
+// This should not be used. It is exported for use in extension sub-packages.
+func (c Cookie) ReplyUnchecked() ([]byte, error) {
if c.replyChan == nil {
return nil, errors.New("Cannot call 'replyUnchecked' on a cookie " +
"that is not expecting a *reply*.")
@@ -114,7 +119,7 @@ func (c cookie) replyUnchecked() ([]byte, error) {
panic("unreachable")
}
-// check is used for checked requests that have no replies. It is a mechanism
+// Check is used for checked requests that have no replies. It is a mechanism
// by which to report "success" or "error" in a synchronous fashion. (Therefore,
// unchecked requests without replies cannot use this method.)
// If the request causes an error, it is sent to this cookie's errorChan.
@@ -122,7 +127,8 @@ func (c cookie) replyUnchecked() ([]byte, error) {
// Thus, pingChan is sent a value when the *next* reply is read.
// If no more replies are being processed, we force a round trip request with
// GetInputFocus.
-func (c cookie) check() error {
+// This should not be used. It is exported for use in extension sub-packages.
+func (c Cookie) Check() error {
if c.replyChan != nil {
return errors.New("Cannot call 'Check' on a cookie that is " +
"expecting a *reply*. Use 'Reply' instead.")
@@ -142,7 +148,7 @@ func (c cookie) check() error {
}
// Now force a round trip and try again, but block this time.
- c.conn.GetInputFocus().Reply()
+ c.conn.Sync()
select {
case err := <-c.errorChan:
return err