diff --git a/src/pkg/exp/nacl/av/av.go b/src/pkg/exp/nacl/av/av.go index 9adc582fd48..4c63125527b 100644 --- a/src/pkg/exp/nacl/av/av.go +++ b/src/pkg/exp/nacl/av/av.go @@ -21,13 +21,13 @@ import ( "unsafe"; ) -var srpcEnabled = srpc.Enabled(); +var srpcEnabled = srpc.Enabled() // native_client/src/trusted/service_runtime/include/sys/audio_video.h // Subsystem values for Init. const ( - SubsystemVideo = 1< 0 { @@ -390,12 +392,12 @@ func (w *Window) readEvents() { buf := make([]byte, maxEventBytes); clean := false; var ( - ea *activeEvent; - ee *exposeEvent; - ke *keyboardEvent; - mme *mouseMotionEvent; - mbe *mouseButtonEvent; - qe *quitEvent; + ea *activeEvent; + ee *exposeEvent; + ke *keyboardEvent; + mme *mouseMotionEvent; + mbe *mouseButtonEvent; + qe *quitEvent; ) var m draw.Mouse; for { @@ -439,7 +441,7 @@ func (w *Window) readEvents() { // log.Stdoutf("%#v\n", e); switch buf[0] { case eventExpose: - w.resizec <- true + w.resizec <- true; case eventKeyDown: w.kbdc <- int(ke.Key); case eventKeyUp: @@ -454,14 +456,14 @@ func (w *Window) readEvents() { m.X = int(mbe.X); m.Y = int(mbe.Y); // TODO(rsc): Remove uint cast once 8g bug is fixed. - m.Buttons |= 1<>24; a |= a<<8; a |= a<<16; - r = (x>>16) & 0xFF; + r = (x>>16)&0xFF; r |= r<<8; r |= r<<16; - g = (x>>8) & 0xFF; + g = (x>>8)&0xFF; g |= g<<8; g |= g<<16; - b = x & 0xFF; + b = x&0xFF; b |= b<<8; b |= b<<16; return; @@ -91,5 +92,4 @@ func toColor(color image.Color) image.Color { } // ColorModel is the color model corresponding to the Native Client Color. -var ColorModel = image.ColorModelFunc(toColor); - +var ColorModel = image.ColorModelFunc(toColor) diff --git a/src/pkg/exp/nacl/srpc/client.go b/src/pkg/exp/nacl/srpc/client.go index 4c375fe2ae6..1a2d5fdc9c8 100644 --- a/src/pkg/exp/nacl/srpc/client.go +++ b/src/pkg/exp/nacl/srpc/client.go @@ -14,30 +14,30 @@ import ( // A Client represents the client side of an SRPC connection. type Client struct { - fd int; // fd to server - r msgReceiver; - s msgSender; - service map[string]srv; // services by name - out chan *msg; // send to out to write to connection + fd int; // fd to server + r msgReceiver; + s msgSender; + service map[string]srv; // services by name + out chan *msg; // send to out to write to connection - mu sync.Mutex; // protects pending, idGen - pending map[uint64]*RPC; - idGen uint64; // generator for request IDs + mu sync.Mutex; // protects pending, idGen + pending map[uint64]*RPC; + idGen uint64; // generator for request IDs } // A srv is a single method that the server offers. type srv struct { - num uint32; // method number - fmt string; // argument format + num uint32; // method number + fmt string; // argument format } // An RPC represents a single RPC issued by a client. type RPC struct { - Ret []interface{}; // Return values - Done chan *RPC; // Channel where notification of done arrives - Errno Errno; // Status code - c *Client; - id uint64; // request id + Ret []interface{}; // Return values + Done chan *RPC; // Channel where notification of done arrives + Errno Errno; // Status code + c *Client; + id uint64; // request id } // NewClient allocates a new client using the file descriptor fd. @@ -53,8 +53,8 @@ func NewClient(fd int) (c *Client, err os.Error) { m := &msg{ protocol: protocol, isReq: true, - Ret: []interface{}{ []byte(nil) }, - Size: []int{ 4000 }, + Ret: []interface{}{[]byte(nil)}, + Size: []int{4000}, }; m.packRequest(); c.s.send(m); @@ -72,7 +72,7 @@ func NewClient(fd int) (c *Client, err os.Error) { if i < 0 { continue; } - c.service[string(line[0:i])] = srv{uint32(n), string(line[i+1:len(line)])}; + c.service[string(line[0:i])] = srv{uint32(n), string(line[i+1 : len(line)])}; } c.out = make(chan *msg); @@ -159,11 +159,11 @@ func (r *RPC) Start(name string, arg []interface{}) { for srv.fmt[i] != ':' { i++; } - fmt := srv.fmt[i+1:len(srv.fmt)]; + fmt := srv.fmt[i+1 : len(srv.fmt)]; // Now the return prototypes. - m.Ret = make([]interface{}, len(fmt) - i); - m.Size = make([]int, len(fmt) - i); + m.Ret = make([]interface{}, len(fmt)-i); + m.Size = make([]int, len(fmt)-i); for i := 0; i < len(fmt); i++ { switch fmt[i] { default: diff --git a/src/pkg/exp/nacl/srpc/msg.go b/src/pkg/exp/nacl/srpc/msg.go index 27fe7212f80..b0c8041a53b 100644 --- a/src/pkg/exp/nacl/srpc/msg.go +++ b/src/pkg/exp/nacl/srpc/msg.go @@ -17,8 +17,9 @@ import ( // An Errno is an SRPC status code. type Errno uint32 + const ( - OK Errno = 256 + iota; + OK Errno = 256+iota; ErrBreak; ErrMessageTruncated; ErrNoMemory; @@ -33,27 +34,27 @@ const ( ErrAppError; ) -var errstr = [...]string { +var errstr = [...]string{ OK-OK: "ok", ErrBreak-OK: "break", - ErrMessageTruncated-OK: "message truncated", - ErrNoMemory-OK: "out of memory", - ErrProtocolMismatch-OK: "protocol mismatch", - ErrBadRPCNumber-OK: "invalid RPC method number", - ErrBadArgType-OK: "unexpected argument type", - ErrTooFewArgs-OK: "too few arguments", - ErrTooManyArgs-OK: "too many arguments", - ErrInArgTypeMismatch-OK: "input argument type mismatch", - ErrOutArgTypeMismatch-OK: "output argument type mismatch", - ErrInternalError-OK: "internal error", - ErrAppError-OK: "application error", + ErrMessageTruncated - OK: "message truncated", + ErrNoMemory - OK: "out of memory", + ErrProtocolMismatch - OK: "protocol mismatch", + ErrBadRPCNumber - OK: "invalid RPC method number", + ErrBadArgType - OK: "unexpected argument type", + ErrTooFewArgs - OK: "too few arguments", + ErrTooManyArgs - OK: "too many arguments", + ErrInArgTypeMismatch - OK: "input argument type mismatch", + ErrOutArgTypeMismatch - OK: "output argument type mismatch", + ErrInternalError - OK: "internal error", + ErrAppError - OK: "application error", } func (e Errno) String() string { if e < OK || int(e-OK) >= len(errstr) { - return "Errno(" + strconv.Itoa64(int64(e)) + ")" + return "Errno(" + strconv.Itoa64(int64(e)) + ")"; } - return errstr[e - OK]; + return errstr[e-OK]; } // A *msgHdr is the data argument to the imc_recvmsg @@ -61,45 +62,45 @@ func (e Errno) String() string { // counts trusted by the system calls, the data structure is unsafe // to expose to package clients. type msgHdr struct { - iov *iov; - niov int32; - desc *int32; - ndesc int32; - flags uint32; + iov *iov; + niov int32; + desc *int32; + ndesc int32; + flags uint32; } // A single region for I/O. Just as unsafe as msgHdr. type iov struct { - base *byte; - len int32; + base *byte; + len int32; } // A msg is the Go representation of a message. type msg struct { - rdata []byte; // data being consumed during message parsing - rdesc []int32; // file descriptors being consumed during message parsing - wdata []byte; // data being generated when replying + rdata []byte; // data being consumed during message parsing + rdesc []int32; // file descriptors being consumed during message parsing + wdata []byte; // data being generated when replying // parsed version of message - protocol uint32; - requestId uint64; - isReq bool; - rpcNumber uint32; - gotHeader bool; - status Errno; // error code sent in response - Arg []interface{}; // method arguments - Ret []interface{}; // method results - Size []int; // max sizes for arrays in method results - fmt string; // accumulated format string of arg+":"+ret + protocol uint32; + requestId uint64; + isReq bool; + rpcNumber uint32; + gotHeader bool; + status Errno; // error code sent in response + Arg []interface{}; // method arguments + Ret []interface{}; // method results + Size []int; // max sizes for arrays in method results + fmt string; // accumulated format string of arg+":"+ret } // A msgReceiver receives messages from a file descriptor. type msgReceiver struct { - fd int; - data [128*1024]byte; - desc [8]int32; - hdr msgHdr; - iov iov; + fd int; + data [128*1024]byte; + desc [8]int32; + hdr msgHdr; + iov iov; } func (r *msgReceiver) recv() (*msg, os.Error) { @@ -136,10 +137,9 @@ func (r *msgReceiver) recv() (*msg, os.Error) { // A msgSender sends messages on a file descriptor. type msgSender struct { - fd int; - hdr msgHdr; - iov iov; - + fd int; + hdr msgHdr; + iov iov; } func (s *msgSender) send(m *msg) os.Error { @@ -222,8 +222,8 @@ func (m *msg) grow(n int) []byte { bytes.Copy(a, m.wdata); m.wdata = a; } - m.wdata = m.wdata[0:i+n]; - return m.wdata[i:i+n]; + m.wdata = m.wdata[0 : i+n]; + return m.wdata[i : i+n]; } func (m *msg) wuint8(x uint8) { @@ -529,4 +529,3 @@ func (m *msg) packResponse() { m.wuint32(uint32(len(m.Ret))); m.packValues(m.Ret); } - diff --git a/src/pkg/exp/nacl/srpc/server.go b/src/pkg/exp/nacl/srpc/server.go index c4dc0a6c7df..984aebeea9d 100644 --- a/src/pkg/exp/nacl/srpc/server.go +++ b/src/pkg/exp/nacl/srpc/server.go @@ -22,13 +22,13 @@ import ( // It reads arguments from arg, checks size for array limits, // writes return values to ret, and returns an Errno status code. type Handler interface { - Run(arg, ret []interface{}, size []int) Errno + Run(arg, ret []interface{}, size []int) Errno; } type method struct { - name string; - fmt string; - handler Handler; + name string; + fmt string; + handler Handler; } var rpcMethod []method @@ -61,7 +61,7 @@ func Add(name, fmt string, handler Handler) { } rpcMethod = a; } - rpcMethod = rpcMethod[0:n+1]; + rpcMethod = rpcMethod[0 : n+1]; rpcMethod[n] = method{name, fmt, handler}; } @@ -175,7 +175,7 @@ func getFd() (fd int, err os.Error) { // Enabled returns true if SRPC is enabled in the Native Client runtime. func Enabled() bool { - _, err:= getFd(); + _, err := getFd(); return err == nil; } @@ -201,4 +201,3 @@ func (serviceDiscovery) Run(arg, ret []interface{}, size []int) Errno { func init() { Add("service_discovery", ":C", serviceDiscovery{}); } -