diff --git a/client.go b/client.go index ddd1f44..0252cc7 100644 --- a/client.go +++ b/client.go @@ -1,19 +1,19 @@ package socketio import ( - "websocket" - "io" "bytes" - "os" + "errors" + "io" "strconv" + "websocket" ) // Client is a toy interface. type Client interface { io.Closer - Dial(string, string) os.Error - Send(interface{}) os.Error + Dial(string, string) error + Send(interface{}) error OnDisconnect(func()) OnMessage(func(Message)) SessionID() SessionID @@ -38,7 +38,7 @@ func NewWebsocketClient(codec Codec) (wc *WebsocketClient) { return } -func (wc *WebsocketClient) Dial(rawurl string, origin string) (err os.Error) { +func (wc *WebsocketClient) Dial(rawurl string, origin string) (err error) { var messages []Message var nr int @@ -54,18 +54,18 @@ func (wc *WebsocketClient) Dial(rawurl string, origin string) (err os.Error) { buf := make([]byte, 2048) if nr, err = wc.ws.Read(buf); err != nil { wc.ws.Close() - return os.NewError("Dial: " + err.String()) + return errors.New("Dial: " + err.Error()) } wc.decBuf.Write(buf[0:nr]) if messages, err = wc.dec.Decode(); err != nil { wc.ws.Close() - return os.NewError("Dial: " + err.String()) + return errors.New("Dial: " + err.Error()) } if len(messages) != 1 { wc.ws.Close() - return os.NewError("Dial: expected exactly 1 message, but got " + strconv.Itoa(len(messages))) + return errors.New("Dial: expected exactly 1 message, but got " + strconv.Itoa(len(messages))) } // TODO: Fix me: The original Socket.IO codec does not have a special encoding for handshake @@ -75,14 +75,14 @@ func (wc *WebsocketClient) Dial(rawurl string, origin string) (err os.Error) { if _, ok := wc.codec.(SIOCodec); !ok { if messages[0].Type() != MessageHandshake { wc.ws.Close() - return os.NewError("Dial: expected handshake, but got " + messages[0].Data()) + return errors.New("Dial: expected handshake, but got " + messages[0].Data()) } } wc.sessionid = SessionID(messages[0].Data()) if wc.sessionid == "" { wc.ws.Close() - return os.NewError("Dial: received empty sessionid") + return errors.New("Dial: received empty sessionid") } wc.connected = true @@ -96,7 +96,7 @@ func (wc *WebsocketClient) SessionID() SessionID { } func (wc *WebsocketClient) reader() { - var err os.Error + var err error var nr int var messages []Message buf := make([]byte, 2048) @@ -133,7 +133,7 @@ func (wc *WebsocketClient) OnMessage(f func(Message)) { wc.onMessage = f } -func (wc *WebsocketClient) Send(payload interface{}) os.Error { +func (wc *WebsocketClient) Send(payload interface{}) error { if wc.ws == nil { return ErrNotConnected } @@ -141,7 +141,7 @@ func (wc *WebsocketClient) Send(payload interface{}) os.Error { return wc.enc.Encode(wc.ws, payload) } -func (wc *WebsocketClient) Close() os.Error { +func (wc *WebsocketClient) Close() error { if !wc.connected { return ErrNotConnected } diff --git a/codec.go b/codec.go index af00c4e..d71fddd 100644 --- a/codec.go +++ b/codec.go @@ -1,13 +1,13 @@ package socketio import ( - "io" - "os" "bytes" + "errors" + "io" ) var ( - ErrMalformedPayload = os.NewError("malformed payload") + ErrMalformedPayload = errors.New("malformed payload") ) // A Codec wraps Encode and Decode methods. @@ -21,10 +21,10 @@ type Codec interface { } type Decoder interface { - Decode() ([]Message, os.Error) + Decode() ([]Message, error) Reset() } type Encoder interface { - Encode(io.Writer, interface{}) os.Error + Encode(io.Writer, interface{}) error } diff --git a/codec_sio.go b/codec_sio.go index 75cc8dc..cc67aff 100644 --- a/codec_sio.go +++ b/codec_sio.go @@ -2,12 +2,12 @@ package socketio import ( "bytes" + "encoding/json" + "errors" "fmt" "io" - "json" - "os" "strconv" - "utf8" + "unicode/utf8" ) // The various delimiters used for framing in the socket.io protocol. @@ -118,7 +118,7 @@ func (sc SIOCodec) NewEncoder() Encoder { // of the following: a heartbeat, a handshake, []byte, string, int or anything // than can be marshalled by the default json package. If payload can't be // encoded or the writing fails, an error will be returned. -func (enc *sioEncoder) Encode(dst io.Writer, payload interface{}) (err os.Error) { +func (enc *sioEncoder) Encode(dst io.Writer, payload interface{}) (err error) { enc.elem.Reset() switch t := payload.(type) { @@ -203,9 +203,9 @@ func (dec *sioDecoder) Reset() { dec.length = 0 } -func (dec *sioDecoder) Decode() (messages []Message, err os.Error) { +func (dec *sioDecoder) Decode() (messages []Message, err error) { messages = make([]Message, 0, 1) - var c int + var c rune L: for { @@ -226,7 +226,7 @@ L: if dec.buf.Len() == len(sioFrameDelim) { if !bytes.Equal(dec.buf.Bytes(), sioFrameDelim) { dec.Reset() - return nil, os.NewError("Malformed header") + return nil, errors.New("Malformed header") } dec.state = sioDecodeStateLength @@ -257,7 +257,7 @@ L: if !bytes.Equal(dec.buf.Bytes(), sioFrameDelim) { dec.Reset() - return nil, os.NewError("Malformed header") + return nil, errors.New("Malformed header") } dec.state = sioDecodeStateData @@ -308,7 +308,7 @@ L: dec.buf.WriteRune(c) } - if err == os.EOF { + if err == io.EOF { err = nil } diff --git a/codec_sio_test.go b/codec_sio_test.go index 724e2a8..4f604ce 100644 --- a/codec_sio_test.go +++ b/codec_sio_test.go @@ -1,11 +1,10 @@ package socketio import ( - "testing" - "utf8" - "fmt" "bytes" - "os" + "fmt" + "testing" + "unicode/utf8" ) func frame(data string, json bool) string { @@ -68,7 +67,6 @@ var encodeTests = []encodeTest{ }, } - type decodeTestMessage struct { messageType uint8 data string @@ -139,7 +137,7 @@ func TestDecode(t *testing.T) { buf := new(bytes.Buffer) dec := codec.NewDecoder(buf) var messages []Message - var err os.Error + var err error for _, test := range decodeTests { t.Logf("in=%s out=%v", test.in, test.out) @@ -176,7 +174,7 @@ func TestDecode(t *testing.T) { func TestDecodeStreaming(t *testing.T) { var messages []Message - var err os.Error + var err error codec := SIOCodec{} buf := new(bytes.Buffer) dec := codec.NewDecoder(buf) diff --git a/codec_siostreaming.go b/codec_siostreaming.go index 3a2dc2e..9f4b513 100644 --- a/codec_siostreaming.go +++ b/codec_siostreaming.go @@ -2,12 +2,12 @@ package socketio import ( "bytes" + "encoding/json" + "errors" "fmt" "io" - "json" - "os" "strconv" - "utf8" + "unicode/utf8" ) // SIOStreamingCodec is the codec used by the official Socket.IO client by LearnBoost @@ -26,7 +26,7 @@ func (sc SIOStreamingCodec) NewEncoder() Encoder { // of the following: a heartbeat, a handshake, []byte, string, int or anything // than can be marshalled by the default json package. If payload can't be // encoded or the writing fails, an error will be returned. -func (enc *sioStreamingEncoder) Encode(dst io.Writer, payload interface{}) (err os.Error) { +func (enc *sioStreamingEncoder) Encode(dst io.Writer, payload interface{}) (err error) { enc.elem.Reset() switch t := payload.(type) { @@ -115,10 +115,10 @@ func (dec *sioStreamingDecoder) Reset() { dec.length = 0 } -func (dec *sioStreamingDecoder) Decode() (messages []Message, err os.Error) { +func (dec *sioStreamingDecoder) Decode() (messages []Message, err error) { messages = make([]Message, 0, 1) - var c int - var typ uint + var c rune + var typ uint64 L: for { @@ -136,7 +136,7 @@ L: switch dec.state { case sioStreamingDecodeStateType: if c == ':' { - if typ, err = strconv.Atoui(dec.buf.String()); err != nil { + if typ, err = strconv.ParseUint(dec.buf.String(), 10, 0); err != nil { dec.Reset() return nil, err } @@ -186,7 +186,7 @@ L: case '\n': if dec.buf.Len() == 0 { dec.Reset() - return nil, os.NewError("expecting key, but got...") + return nil, errors.New("expecting key, but got...") } dec.key = dec.buf.String() if dec.msg.annotations == nil { @@ -251,14 +251,14 @@ L: continue } else { dec.Reset() - return nil, os.NewError("Expecting trailer but got... " + string(c)) + return nil, errors.New("Expecting trailer but got... " + string(c)) } } dec.buf.WriteRune(c) } - if err == os.EOF { + if err == io.EOF { err = nil } diff --git a/codec_siostreaming_test.go b/codec_siostreaming_test.go index 7ee606b..df41200 100644 --- a/codec_siostreaming_test.go +++ b/codec_siostreaming_test.go @@ -1,12 +1,11 @@ package socketio import ( - "testing" - "utf8" - "fmt" "bytes" + "fmt" + "testing" + "unicode/utf8" "unsafe" - "os" ) func streamingFrame(data string, typ int, json bool) string { @@ -77,7 +76,6 @@ var streamingEncodeTests = []streamingEncodeTest{ }, } - type streamingDecodeTestMessage struct { messageType uint8 data string @@ -148,7 +146,7 @@ func TestStreamingDecode(t *testing.T) { buf := new(bytes.Buffer) dec := codec.NewDecoder(buf) var messages []Message - var err os.Error + var err error for _, test := range streamingDecodeTests { t.Logf("in=%s out=%v", test.in, test.out) @@ -185,7 +183,7 @@ func TestStreamingDecode(t *testing.T) { func TestStreamingDecodeStreaming(t *testing.T) { var messages []Message - var err os.Error + var err error codec := SIOStreamingCodec{} buf := new(bytes.Buffer) dec := codec.NewDecoder(buf) diff --git a/config.go b/config.go index 169eb99..b7869c5 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,9 @@ package socketio -import "log" +import ( + "log" + "time" +) // Config represents a set of configurable settings used by the server type Config struct { @@ -16,11 +19,11 @@ type Config struct { ReadBufferSize int // The interval between heartbeats - HeartbeatInterval int64 + HeartbeatInterval time.Duration // Period in ns during which the client must reconnect or it is considered // disconnected. - ReconnectTimeout int64 + ReconnectTimeout time.Duration // Origins to allow for cross-domain requests. // For example: ["localhost:8080", "myblog.com:*"]. @@ -43,8 +46,8 @@ var DefaultConfig = Config{ MaxConnections: 0, QueueLength: 10, ReadBufferSize: 2048, - HeartbeatInterval: 10e9, - ReconnectTimeout: 10e9, + HeartbeatInterval: time.Duration(10 * time.Second), + ReconnectTimeout: time.Duration(10 * time.Second), Origins: nil, Transports: DefaultTransports, Codec: SIOCodec{}, diff --git a/connection.go b/connection.go index 9285724..e5ec8ac 100644 --- a/connection.go +++ b/connection.go @@ -1,23 +1,24 @@ package socketio import ( - "http" - "os" - "net" "bytes" - "time" + "errors" "fmt" + "net" + "net/http" + "os" "sync" + "time" ) var ( // ErrDestroyed is used when the connection has been disconnected (i.e. can't be used anymore). - ErrDestroyed = os.NewError("connection is disconnected") + ErrDestroyed = errors.New("connection is disconnected") // ErrQueueFull is used when the send queue is full. - ErrQueueFull = os.NewError("send queue is full") + ErrQueueFull = errors.New("send queue is full") - errMissingPostData = os.NewError("Missing HTTP post data-field") + errMissingPostData = errors.New("Missing HTTP post data-field") ) // Conn represents a single session and handles its handshaking, @@ -28,8 +29,8 @@ type Conn struct { sio *SocketIO // The server. sessionid SessionID online bool - lastConnected int64 - lastDisconnected int64 + lastConnected time.Time + lastDisconnected time.Time lastHeartbeat heartbeat numHeartbeats int ticker *time.Ticker @@ -47,7 +48,7 @@ type Conn struct { // NewConn creates a new connection for the sio. It generates the session id and // prepares the internal structure for usage. -func newConn(sio *SocketIO) (c *Conn, err os.Error) { +func newConn(sio *SocketIO) (c *Conn, err error) { var sessionid SessionID if sessionid, err = NewSessionID(); err != nil { sio.Log("sio/newConn: newSessionID:", err) @@ -68,7 +69,6 @@ func newConn(sio *SocketIO) (c *Conn, err os.Error) { return } - // String returns a string representation of the connection and implements the // fmt.Stringer interface. func (c *Conn) String() string { @@ -85,7 +85,7 @@ func (c *Conn) RemoteAddr() string { // it must be otherwise marshallable by the standard json package. If the send queue // has reached sio.config.QueueLength or the connection has been disconnected, // then the data is dropped and a an error is returned. -func (c *Conn) Send(data interface{}) (err os.Error) { +func (c *Conn) Send(data interface{}) (err error) { c.mutex.Lock() defer c.mutex.Unlock() @@ -102,7 +102,7 @@ func (c *Conn) Send(data interface{}) (err os.Error) { return nil } -func (c *Conn) Close() os.Error { +func (c *Conn) Close() error { c.mutex.Lock() if c.disconnected { @@ -122,7 +122,7 @@ func (c *Conn) Close() os.Error { // message and the request is dropped. If the method is GET then a new socket encapsulating // the request is created and a new connection is establised (or the connection will be // reconnected). Finally, handle will wake up the reader and the flusher. -func (c *Conn) handle(t Transport, w http.ResponseWriter, req *http.Request) (err os.Error) { +func (c *Conn) handle(t Transport, w http.ResponseWriter, req *http.Request) (err error) { c.mutex.Lock() if c.disconnected { @@ -154,7 +154,7 @@ func (c *Conn) handle(t Transport, w http.ResponseWriter, req *http.Request) (er } c.socket = s c.online = true - c.lastConnected = time.Nanoseconds() + c.lastConnected = time.Now() if !c.handshaked { // the connection has not been handshaked yet. @@ -203,11 +203,10 @@ func (c *Conn) handle(t Transport, w http.ResponseWriter, req *http.Request) (er } // Handshake sends the handshake to the socket. -func (c *Conn) handshake() os.Error { +func (c *Conn) handshake() error { return c.enc.Encode(c.socket, handshake(c.sessionid)) } - func (c *Conn) disconnect() { c.sio.Log("sio/conn: disconnected:", c) c.socket.Close() @@ -251,7 +250,7 @@ Loop: return } - if (!c.online && t-c.lastDisconnected > c.sio.config.ReconnectTimeout) || int(c.lastHeartbeat) < c.numHeartbeats { + if (!c.online && t.Sub(c.lastDisconnected) > c.sio.config.ReconnectTimeout) || int(c.lastHeartbeat) < c.numHeartbeats { c.disconnect() c.mutex.Unlock() break @@ -286,7 +285,7 @@ Loop: // simultaneously. func (c *Conn) flusher() { buf := new(bytes.Buffer) - var err os.Error + var err error var msg interface{} var n int @@ -370,7 +369,7 @@ func (c *Conn) reader() { } c.mutex.Lock() - c.lastDisconnected = time.Nanoseconds() + c.lastDisconnected = time.Now() socket.Close() if c.socket == socket { c.online = false diff --git a/example/example.go b/example/example.go index 38edd4c..db73592 100644 --- a/example/example.go +++ b/example/example.go @@ -2,8 +2,8 @@ package main import ( "container/vector" - "http" "log" + "net/http" "socketio" "sync" ) diff --git a/servemux.go b/servemux.go index b1c891f..e9af8b7 100644 --- a/servemux.go +++ b/servemux.go @@ -1,8 +1,8 @@ package socketio import ( + "net/http" "strings" - "http" ) type ServeMux struct { diff --git a/session.go b/session.go index 6feea78..4a89ab2 100644 --- a/session.go +++ b/session.go @@ -1,9 +1,8 @@ package socketio import ( - "io" "crypto/rand" - "os" + "io" ) // SessionID is just a string for now. @@ -19,7 +18,7 @@ const ( // NewSessionID creates a new ~random session id that is SessionIDLength long and // consists of random characters from the SessionIDCharset. -func NewSessionID() (sid SessionID, err os.Error) { +func NewSessionID() (sid SessionID, err error) { b := make([]byte, SessionIDLength) if _, err = io.ReadFull(rand.Reader, b); err != nil { diff --git a/socketio.go b/socketio.go index f130857..0f54558 100644 --- a/socketio.go +++ b/socketio.go @@ -3,13 +3,13 @@ package socketio import ( "bytes" "fmt" - "http" "io" "net" + "net/http" + "net/url" "os" "strings" "sync" - "url" ) // SocketIO handles transport abstraction and provide the user @@ -91,7 +91,7 @@ func (sio *SocketIO) ServeMux() *ServeMux { // OnConnect sets f to be invoked when a new session is established. It passes // the established connection as an argument to the callback. -func (sio *SocketIO) OnConnect(f func(*Conn)) os.Error { +func (sio *SocketIO) OnConnect(f func(*Conn)) error { sio.callbacks.onConnect = f return nil } @@ -99,7 +99,7 @@ func (sio *SocketIO) OnConnect(f func(*Conn)) os.Error { // OnDisconnect sets f to be invoked when a session is considered to be lost. It passes // the established connection as an argument to the callback. After disconnection // the connection is considered to be destroyed, and it should not be used anymore. -func (sio *SocketIO) OnDisconnect(f func(*Conn)) os.Error { +func (sio *SocketIO) OnDisconnect(f func(*Conn)) error { sio.callbacks.onDisconnect = f return nil } @@ -107,7 +107,7 @@ func (sio *SocketIO) OnDisconnect(f func(*Conn)) os.Error { // OnMessage sets f to be invoked when a message arrives. It passes // the established connection along with the received message as arguments // to the callback. -func (sio *SocketIO) OnMessage(f func(*Conn, Message)) os.Error { +func (sio *SocketIO) OnMessage(f func(*Conn, Message)) error { sio.callbacks.onMessage = f return nil } @@ -116,7 +116,7 @@ func (sio *SocketIO) OnMessage(f func(*Conn, Message)) os.Error { // the http.Request as an argument to the callback. // The callback should return true if the connection is authorized or false if it // should be dropped. Not setting this callback results in a default pass-through. -func (sio *SocketIO) SetAuthorization(f func(*http.Request) bool) os.Error { +func (sio *SocketIO) SetAuthorization(f func(*http.Request) bool) error { sio.callbacks.isAuthorized = f return nil } @@ -145,7 +145,7 @@ func (sio *SocketIO) Logf(format string, v ...interface{}) { func (sio *SocketIO) handle(t Transport, w http.ResponseWriter, req *http.Request) { var parts []string var c *Conn - var err os.Error + var err error if !sio.isAuthorized(req) { sio.Log("sio/handle: unauthorized request:", req) @@ -201,7 +201,7 @@ func (sio *SocketIO) handle(t Transport, w http.ResponseWriter, req *http.Reques // we should now have a connection if c == nil { - sio.Log("sio/handle: unable to map request to connection:", req.RawURL) + sio.Log("sio/handle: unable to map request to connection:", req.URL.Raw) w.WriteHeader(http.StatusBadRequest) return } @@ -230,7 +230,7 @@ func (sio *SocketIO) onConnect(c *Conn) { // to be lost. It removes the connection and calls the user's OnDisconnect callback. func (sio *SocketIO) onDisconnect(c *Conn) { sio.sessionsLock.Lock() - sio.sessions[c.sessionid] = nil, false + delete(sio.sessions, c.sessionid) sio.sessionsLock.Unlock() if sio.callbacks.onDisconnect != nil { @@ -326,7 +326,7 @@ func (sio *SocketIO) generatePolicyFile() []byte { return buf.Bytes() } -func (sio *SocketIO) ListenAndServeFlashPolicy(laddr string) os.Error { +func (sio *SocketIO) ListenAndServeFlashPolicy(laddr string) error { var listener net.Listener listener, err := net.Listen("tcp", laddr) diff --git a/socketio_test.go b/socketio_test.go index 839ca36..1fb6379 100644 --- a/socketio_test.go +++ b/socketio_test.go @@ -1,10 +1,10 @@ package socketio import ( - "http" + "fmt" + "net/http" "testing" "time" - "fmt" ) const ( @@ -49,7 +49,6 @@ func echoServer(addr string, config *Config) <-chan *event { return events } - func TestWebsocket(t *testing.T) { finished := make(chan bool, 1) clientMessage := make(chan Message) diff --git a/transport.go b/transport.go index 2106549..5f649f9 100644 --- a/transport.go +++ b/transport.go @@ -1,20 +1,20 @@ package socketio import ( + "errors" "fmt" - "http" "io" - "os" + "net/http" ) var ( // ErrNotConnected is used when some action required the connection to be online, // but it wasn't. - ErrNotConnected = os.NewError("not connected") + ErrNotConnected = errors.New("not connected") // ErrConnected is used when some action required the connection to be offline, // but it wasn't. - ErrConnected = os.NewError("already connected") + ErrConnected = errors.New("already connected") emptyResponse = []byte{} okResponse = []byte("ok") @@ -53,5 +53,5 @@ type socket interface { fmt.Stringer Transport() Transport - accept(http.ResponseWriter, *http.Request, func()) os.Error + accept(http.ResponseWriter, *http.Request, func()) error } diff --git a/transport_flashsocket.go b/transport_flashsocket.go index 3881fb4..1f87ad3 100644 --- a/transport_flashsocket.go +++ b/transport_flashsocket.go @@ -1,9 +1,6 @@ package socketio -import ( - "http" - "os" -) +import "net/http" // The flashsocket transport. type flashsocketTransport struct { @@ -45,18 +42,18 @@ func (s *flashsocketSocket) String() string { // proceed if succesfull. // // TODO: Remove the ugly channels and timeouts. They should not be needed! -func (s *flashsocketSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *flashsocketSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { return s.s.accept(w, req, proceed) } -func (s *flashsocketSocket) Read(p []byte) (int, os.Error) { +func (s *flashsocketSocket) Read(p []byte) (int, error) { return s.s.Read(p) } -func (s *flashsocketSocket) Write(p []byte) (int, os.Error) { +func (s *flashsocketSocket) Write(p []byte) (int, error) { return s.s.Write(p) } -func (s *flashsocketSocket) Close() os.Error { +func (s *flashsocketSocket) Close() error { return s.s.Close() } diff --git a/transport_htmlfile.go b/transport_htmlfile.go index 89b0678..ffabc19 100644 --- a/transport_htmlfile.go +++ b/transport_htmlfile.go @@ -1,14 +1,13 @@ package socketio import ( - "http" - "os" - "io" "bytes" - "strings" - "json" - "net" + "encoding/json" "fmt" + "io" + "net" + "net/http" + "strings" ) var htmlfileHeader = "" + strings.Repeat(" ", 244) @@ -53,7 +52,7 @@ func (s *htmlfileSocket) Transport() Transport { // Accepts a http connection & request pair. It hijacks the connection, sends headers and calls // proceed if succesfull. -func (s *htmlfileSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *htmlfileSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { if s.connected { return ErrConnected } @@ -86,7 +85,7 @@ func (s *htmlfileSocket) accept(w http.ResponseWriter, req *http.Request, procee return } -func (s *htmlfileSocket) Read(p []byte) (n int, err os.Error) { +func (s *htmlfileSocket) Read(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -94,9 +93,8 @@ func (s *htmlfileSocket) Read(p []byte) (n int, err os.Error) { return s.rwc.Read(p) } - // Write sends a single multipart message to the wire. -func (s *htmlfileSocket) Write(p []byte) (n int, err os.Error) { +func (s *htmlfileSocket) Write(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -111,7 +109,7 @@ func (s *htmlfileSocket) Write(p []byte) (n int, err os.Error) { return fmt.Fprintf(s.rwc, "%x\r\n%s\r\n", buf.Len(), buf.String()) } -func (s *htmlfileSocket) Close() os.Error { +func (s *htmlfileSocket) Close() error { if !s.connected { return ErrNotConnected } diff --git a/transport_jsonppolling.go b/transport_jsonppolling.go index b86385e..7d29f38 100644 --- a/transport_jsonppolling.go +++ b/transport_jsonppolling.go @@ -1,13 +1,12 @@ package socketio import ( - "http" - "os" + "encoding/json" + "fmt" "io" "net" + "net/http" "strconv" - "json" - "fmt" ) // The jsonp-polling transport. @@ -51,7 +50,7 @@ func (s *jsonpPollingSocket) Transport() Transport { // Accepts a http connection & request pair. It hijacks the connection and calls // proceed if succesfull. -func (s *jsonpPollingSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *jsonpPollingSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { if s.connected { return ErrConnected } @@ -73,7 +72,7 @@ func (s *jsonpPollingSocket) accept(w http.ResponseWriter, req *http.Request, pr return } -func (s *jsonpPollingSocket) Read(p []byte) (n int, err os.Error) { +func (s *jsonpPollingSocket) Read(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -82,7 +81,7 @@ func (s *jsonpPollingSocket) Read(p []byte) (n int, err os.Error) { } // Write sends a single message to the wire and closes the connection. -func (s *jsonpPollingSocket) Write(p []byte) (n int, err os.Error) { +func (s *jsonpPollingSocket) Write(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -100,7 +99,7 @@ func (s *jsonpPollingSocket) Write(p []byte) (n int, err os.Error) { len(jsonp), jsonp) } -func (s *jsonpPollingSocket) Close() os.Error { +func (s *jsonpPollingSocket) Close() error { if !s.connected { return ErrNotConnected } diff --git a/transport_websocket.go b/transport_websocket.go index 10002eb..f0a8c49 100644 --- a/transport_websocket.go +++ b/transport_websocket.go @@ -1,12 +1,12 @@ package socketio import ( - "http" - "os" + "errors" + "net/http" "websocket" ) -var errWebsocketHandshake = os.NewError("websocket handshake error") +var errWebsocketHandshake = errors.New("websocket handshake error") // The websocket transport. type websocketTransport struct { @@ -51,7 +51,7 @@ func (s *websocketSocket) String() string { // proceed if succesfull. // // TODO: Remove the ugly channels and timeouts. They should not be needed! -func (s *websocketSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *websocketSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { if s.connected { return ErrConnected } @@ -76,7 +76,7 @@ func (s *websocketSocket) accept(w http.ResponseWriter, req *http.Request, proce return } -func (s *websocketSocket) Read(p []byte) (int, os.Error) { +func (s *websocketSocket) Read(p []byte) (int, error) { if !s.connected { return 0, ErrNotConnected } @@ -84,7 +84,7 @@ func (s *websocketSocket) Read(p []byte) (int, os.Error) { return s.ws.Read(p) } -func (s *websocketSocket) Write(p []byte) (int, os.Error) { +func (s *websocketSocket) Write(p []byte) (int, error) { if !s.connected { return 0, ErrNotConnected } @@ -92,7 +92,7 @@ func (s *websocketSocket) Write(p []byte) (int, os.Error) { return s.ws.Write(p) } -func (s *websocketSocket) Close() os.Error { +func (s *websocketSocket) Close() error { if !s.connected { return ErrNotConnected } diff --git a/transport_xhrmultipart.go b/transport_xhrmultipart.go index 56400aa..badceac 100644 --- a/transport_xhrmultipart.go +++ b/transport_xhrmultipart.go @@ -1,12 +1,11 @@ package socketio import ( - "http" - "os" - "io" "bytes" - "net" "fmt" + "io" + "net" + "net/http" ) // The xhr-multipart transport. @@ -49,7 +48,7 @@ func (s *xhrMultipartSocket) Transport() Transport { // Accepts a http connection & request pair. It hijacks the connection, sends headers and calls // proceed if succesfull. -func (s *xhrMultipartSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *xhrMultipartSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { if s.connected { return ErrConnected } @@ -84,7 +83,7 @@ func (s *xhrMultipartSocket) accept(w http.ResponseWriter, req *http.Request, pr return } -func (s *xhrMultipartSocket) Read(p []byte) (n int, err os.Error) { +func (s *xhrMultipartSocket) Read(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -93,7 +92,7 @@ func (s *xhrMultipartSocket) Read(p []byte) (n int, err os.Error) { } // Write sends a single multipart message to the wire. -func (s *xhrMultipartSocket) Write(p []byte) (n int, err os.Error) { +func (s *xhrMultipartSocket) Write(p []byte) (n int, err error) { if !s.connected { return 0, ErrNotConnected } @@ -101,7 +100,7 @@ func (s *xhrMultipartSocket) Write(p []byte) (n int, err os.Error) { return fmt.Fprintf(s.rwc, "Content-Type: text/plain\r\n\r\n%s\n--socketio\n", p) } -func (s *xhrMultipartSocket) Close() os.Error { +func (s *xhrMultipartSocket) Close() error { if !s.connected { return ErrNotConnected } diff --git a/transport_xhrpolling.go b/transport_xhrpolling.go index 6d0b130..b6883e1 100644 --- a/transport_xhrpolling.go +++ b/transport_xhrpolling.go @@ -1,12 +1,11 @@ package socketio import ( - "http" "bytes" - "os" + "fmt" "io" "net" - "fmt" + "net/http" ) // The xhr-polling transport. @@ -50,7 +49,7 @@ func (s *xhrPollingSocket) Transport() Transport { // Accepts a http connection & request pair. It hijacks the connection and calls // proceed if succesfull. -func (s *xhrPollingSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err os.Error) { +func (s *xhrPollingSocket) accept(w http.ResponseWriter, req *http.Request, proceed func()) (err error) { if s.connected { return ErrConnected } @@ -66,7 +65,7 @@ func (s *xhrPollingSocket) accept(w http.ResponseWriter, req *http.Request, proc return } -func (s *xhrPollingSocket) Read(p []byte) (int, os.Error) { +func (s *xhrPollingSocket) Read(p []byte) (int, error) { if !s.connected { return 0, ErrNotConnected } @@ -75,7 +74,7 @@ func (s *xhrPollingSocket) Read(p []byte) (int, os.Error) { } // Write sends a single message to the wire and closes the connection. -func (s *xhrPollingSocket) Write(p []byte) (int, os.Error) { +func (s *xhrPollingSocket) Write(p []byte) (int, error) { if !s.connected { return 0, ErrNotConnected } @@ -100,7 +99,7 @@ func (s *xhrPollingSocket) Write(p []byte) (int, os.Error) { return int(nr), err } -func (s *xhrPollingSocket) Close() os.Error { +func (s *xhrPollingSocket) Close() error { if !s.connected { return ErrNotConnected } diff --git a/util.go b/util.go index eb6355b..26afd15 100644 --- a/util.go +++ b/util.go @@ -7,7 +7,7 @@ import ( type nopWriter struct{} -func (nw nopWriter) Write(p []byte) (n int, err os.Error) { +func (nw nopWriter) Write(p []byte) (n int, err error) { return len(p), nil }