protocol.go (nsq-1.2.0) | : | protocol.go (nsq-1.2.1) | ||
---|---|---|---|---|
package protocol | package protocol | |||
import ( | import ( | |||
"encoding/binary" | "encoding/binary" | |||
"io" | "io" | |||
"net" | "net" | |||
) | ) | |||
type Client interface { | ||||
Close() error | ||||
} | ||||
// Protocol describes the basic behavior of any protocol in the system | // Protocol describes the basic behavior of any protocol in the system | |||
type Protocol interface { | type Protocol interface { | |||
IOLoop(conn net.Conn) error | NewClient(net.Conn) Client | |||
IOLoop(Client) error | ||||
} | } | |||
// SendResponse is a server side utility function to prefix data with a length h eader | // SendResponse is a server side utility function to prefix data with a length h eader | |||
// and write to the supplied Writer | // and write to the supplied Writer | |||
func SendResponse(w io.Writer, data []byte) (int, error) { | func SendResponse(w io.Writer, data []byte) (int, error) { | |||
err := binary.Write(w, binary.BigEndian, int32(len(data))) | err := binary.Write(w, binary.BigEndian, int32(len(data))) | |||
if err != nil { | if err != nil { | |||
return 0, err | return 0, err | |||
} | } | |||
End of changes. 2 change blocks. | ||||
1 lines changed or deleted | 6 lines changed or added |