Example #1
0
func (c *conn) serve() {
	defer c.cancelAll()

	for {
		t, err := c.readBuf()
		if err != nil {
			if err != os.EOF {
				log.Println(err)
			}
			return
		}

		verb := pb.GetInt32((*int32)(t.Verb))
		f, ok := ops[verb]
		if !ok {
			var r R
			r.ErrCode = proto.NewResponse_Err(proto.Response_UNKNOWN_VERB)
			c.respond(t, Valid|Done, nil, &r)
			continue
		}

		tag := pb.GetInt32((*int32)(t.Tag))
		tx := newTxn()

		c.tl.Lock()
		c.tx[tag] = tx
		c.tl.Unlock()

		f(c, t, tx)
	}
}
Example #2
0
func (c *conn) redirect(t *T) {
	cals := c.s.cals()
	if len(cals) < 1 {
		c.respond(t, Valid|Done, nil, readonly)
		return
	}

	cal := cals[rand.Intn(len(cals))]
	parts, rev := c.s.St.Get("/ctl/node/" + cal + "/addr")
	if rev == store.Dir && rev == store.Missing {
		c.respond(t, Valid|Done, nil, readonly)
		return
	}

	r := &R{
		ErrCode:   proto.NewResponse_Err(proto.Response_REDIRECT),
		ErrDetail: &parts[0],
	}
	c.respond(t, Valid|Done, nil, r)
}
Example #3
0
func errResponse(e os.Error) *R {
	return &R{
		ErrCode:   proto.NewResponse_Err(proto.Response_OTHER),
		ErrDetail: pb.String(e.String()),
	}
}
Example #4
0
	"log"
	"math"
	"net"
	"os"
	"rand"
	"sync"
)

const packetSize = 3000

var (
	ErrPoisoned = os.NewError("poisoned")
)

var (
	badPath     = proto.NewResponse_Err(proto.Response_BAD_PATH)
	missingArg  = &R{ErrCode: proto.NewResponse_Err(proto.Response_MISSING_ARG)}
	tagInUse    = &R{ErrCode: proto.NewResponse_Err(proto.Response_TAG_IN_USE)}
	isDir       = &R{ErrCode: proto.NewResponse_Err(proto.Response_ISDIR)}
	notDir      = &R{ErrCode: proto.NewResponse_Err(proto.Response_NOTDIR)}
	noEnt       = &R{ErrCode: proto.NewResponse_Err(proto.Response_NOENT)}
	tooLate     = &R{ErrCode: proto.NewResponse_Err(proto.Response_TOO_LATE)}
	revMismatch = &R{ErrCode: proto.NewResponse_Err(proto.Response_REV_MISMATCH)}
	readonly    = &R{
		ErrCode:   proto.NewResponse_Err(proto.Response_OTHER),
		ErrDetail: pb.String("no known writeable addresses"),
	}
	badTag = &R{
		ErrCode:   proto.NewResponse_Err(proto.Response_OTHER),
		ErrDetail: pb.String("unknown tag"),
	}