move handler to handlers

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
This commit is contained in:
Василий Толстов 2017-07-03 23:57:45 +03:00
parent 10414c41a1
commit 3aba31d655
3 changed files with 20 additions and 18 deletions

View File

@ -244,10 +244,6 @@ func (*DefaultClientMessageHandler) Handle(c Conn) error {
return nil return nil
} }
type ClientHandler interface {
Handle(Conn) error
}
// A ClientConfig structure is used to configure a ClientConn. After // A ClientConfig structure is used to configure a ClientConn. After
// one has been passed to initialize a connection, it must not be modified. // one has been passed to initialize a connection, it must not be modified.
type ClientConfig struct { type ClientConfig struct {

View File

@ -5,6 +5,10 @@ import (
"fmt" "fmt"
) )
type ClientHandler interface {
Handle(Conn) error
}
// ClientMessage is the interface // ClientMessage is the interface
type ClientMessage interface { type ClientMessage interface {
String() string String() string
@ -13,6 +17,10 @@ type ClientMessage interface {
Write(Conn) error Write(Conn) error
} }
type ServerHandler interface {
Handle(Conn) error
}
// ServerMessage is the interface // ServerMessage is the interface
type ServerMessage interface { type ServerMessage interface {
String() string String() string
@ -199,7 +207,7 @@ func (*DefaultServerSecurityHandler) Handle(c Conn) error {
sType, ok := secTypes[secType] sType, ok := secTypes[secType]
if !ok { if !ok {
return fmt.Errorf("server type %d not implemented") return fmt.Errorf("security type %d not implemented", secType)
} }
var authCode uint32 var authCode uint32
@ -251,14 +259,15 @@ func (*DefaultClientServerInitHandler) Handle(c Conn) error {
return err return err
} }
c.SetDesktopName(srvInit.NameText) c.SetDesktopName(srvInit.NameText)
c.SetWidth(srvInit.FBWidth)
c.SetHeight(srvInit.FBHeight)
if c.Protocol() == "aten" { if c.Protocol() == "aten" {
c.SetWidth(800)
c.SetHeight(600)
c.SetPixelFormat(NewPixelFormatAten()) c.SetPixelFormat(NewPixelFormatAten())
} else { } else {
c.SetWidth(srvInit.FBWidth)
c.SetHeight(srvInit.FBHeight)
c.SetPixelFormat(srvInit.PixelFormat) c.SetPixelFormat(srvInit.PixelFormat)
} }
if c.Protocol() == "aten" { if c.Protocol() == "aten" {
ikvm := struct { ikvm := struct {
_ [8]byte _ [8]byte
@ -280,14 +289,15 @@ func (*DefaultClientServerInitHandler) Handle(c Conn) error {
return err return err
} }
caps.ServerMessagesNum = uint16(16) caps.ServerMessagesNum = uint16(2)
var item [16]byte var item [16]byte
for i := uint16(0); i < caps.ServerMessagesNum; i++ { for i := uint16(0); i < caps.ServerMessagesNum; i++ {
if err := binary.Read(c, binary.BigEndian, &item); err != nil { if err := binary.Read(c, binary.BigEndian, &item); err != nil {
return err return err
} }
fmt.Printf("server message cap %v\n", item) fmt.Printf("server message cap %s\n", item)
} }
/* /*
for i := uint16(0); i < caps.ClientMessagesNum; i++ { for i := uint16(0); i < caps.ClientMessagesNum; i++ {
if err := binary.Read(c, binary.BigEndian, &item); err != nil { if err := binary.Read(c, binary.BigEndian, &item); err != nil {
@ -302,10 +312,10 @@ func (*DefaultClientServerInitHandler) Handle(c Conn) error {
fmt.Printf("encoding cap %s\n", item) fmt.Printf("encoding cap %s\n", item)
} }
*/ */
var pad [1]byte // var pad [1]byte
if err := binary.Read(c, binary.BigEndian, &pad); err != nil { // if err := binary.Read(c, binary.BigEndian, &pad); err != nil {
return err // return err
} // }
} }
return nil return nil
} }

View File

@ -135,10 +135,6 @@ type ServerConn struct {
quit chan struct{} quit chan struct{}
} }
type ServerHandler interface {
Handle(Conn) error
}
var ( var (
DefaultServerHandlers []ServerHandler = []ServerHandler{ DefaultServerHandlers []ServerHandler = []ServerHandler{
&DefaultServerVersionHandler{}, &DefaultServerVersionHandler{},