removed debug

This commit is contained in:
xdrm-brackets 2018-05-02 22:43:05 +02:00
parent 5837c1cdb9
commit a887bcd0b9
2 changed files with 5 additions and 49 deletions

View File

@ -24,9 +24,6 @@ func Read(socket net.Conn) (*T, error){
m.Final = bool( buffer[0] & 0x80 == 0x80 ) m.Final = bool( buffer[0] & 0x80 == 0x80 )
m.Type = byte( buffer[0] & 0x0f ) m.Type = byte( buffer[0] & 0x0f )
fmt.Printf(" + read\n")
fmt.Printf(" - final: %t\n", m.Final)
fmt.Printf(" - Type: %x\n", m.Type)
/* (3) Byte 2: Mask and Length[0] */ /* (3) Byte 2: Mask and Length[0] */
buffer = make([]byte, 1) buffer = make([]byte, 1)
@ -38,11 +35,9 @@ func Read(socket net.Conn) (*T, error){
if buffer[0] & 0x80 == 0x80 { if buffer[0] & 0x80 == 0x80 {
mask = make([]byte, 0) mask = make([]byte, 0)
} }
fmt.Printf(" - has mask ? %t\n", mask != nil)
// payload length // payload length
m.Size = uint( buffer[0] & 0x7f ) m.Size = uint( buffer[0] & 0x7f )
fmt.Printf(" - size/flag: %d\n", m.Size)
/* (4) Extended payload */ /* (4) Extended payload */
if m.Size == 127 { if m.Size == 127 {
@ -63,8 +58,6 @@ func Read(socket net.Conn) (*T, error){
} }
fmt.Printf(" - final size: %d\n", m.Size)
/* (5) Masking key */ /* (5) Masking key */
if mask != nil { if mask != nil {
@ -76,7 +69,6 @@ func Read(socket net.Conn) (*T, error){
copy(mask, buffer) copy(mask, buffer)
} }
fmt.Printf(" - mask: %x\n", mask)
/* (6) Read payload */ /* (6) Read payload */
buffer = make([]byte, int(m.Size)) buffer = make([]byte, int(m.Size))
@ -84,7 +76,6 @@ func Read(socket net.Conn) (*T, error){
if err != nil { return nil, fmt.Errorf("Cannot read payload (%s)", err) } if err != nil { return nil, fmt.Errorf("Cannot read payload (%s)", err) }
m.Data = make([]byte, 0, m.Size) m.Data = make([]byte, 0, m.Size)
fmt.Printf(" - raw data: '%s'\n", buffer)
/* (7) Unmask payload */ /* (7) Unmask payload */
if len(mask) == 4 { if len(mask) == 4 {
@ -99,9 +90,6 @@ func Read(socket net.Conn) (*T, error){
} }
fmt.Printf(" - unmasked data: '%s'\n", m.Data)
return m, nil return m, nil
} }
@ -112,25 +100,15 @@ func Read(socket net.Conn) (*T, error){
// Send sends a frame over a socket // Send sends a frame over a socket
func (m T) Send(socket net.Conn) error { func (m T) Send(socket net.Conn) error {
var bi uint = 0;
buffer := make([]byte, 0) buffer := make([]byte, 0)
fmt.Printf(" + write\n")
fmt.Printf(" - final: %t\n", m.Final)
fmt.Printf(" - type: %x\n", m.Type)
/* (1) Byte 0 : FIN + opcode */ /* (1) Byte 0 : FIN + opcode */
buffer = append(buffer, 0x80 | TEXT ) buffer = append(buffer, 0x80 | TEXT )
fmt.Printf(" > byte[%d]: '%x'\n", bi, 0x80 | TEXT); bi++
fmt.Printf(" ? '%x'\n", buffer[bi-1]);
/* (2) Get payload length */ /* (2) Get payload length */
if m.Size < 126 { // simple if m.Size < 126 { // simple
buffer = append(buffer, byte(m.Size) ) buffer = append(buffer, byte(m.Size) )
fmt.Printf(" - size: %d\n", m.Size)
fmt.Printf(" > byte[%d]: '%.2x'\n", bi, m.Size); bi++
fmt.Printf(" ? '%.2x'\n", buffer[bi-1]);
} else if m.Size < 0xffff { // extended: 16 bits } else if m.Size < 0xffff { // extended: 16 bits
@ -139,12 +117,6 @@ func (m T) Send(socket net.Conn) error {
buf := make([]byte, 2) buf := make([]byte, 2)
binary.BigEndian.PutUint16(buf, uint16(m.Size)) binary.BigEndian.PutUint16(buf, uint16(m.Size))
buffer = append(buffer, buf...) buffer = append(buffer, buf...)
fmt.Printf(" - size flag: %d\n", 126)
fmt.Printf(" > byte[%d]: '%.2x'\n", bi, 126); bi++
fmt.Printf(" ? '%x'\n", buffer[bi-1]);
fmt.Printf(" - size: %d\n", m.Size)
fmt.Printf(" > byte[%d.%d]: '%4.x'\n", bi, bi+2-1, m.Size); bi+=2
fmt.Printf(" ? '%.4x'\n", buffer[bi-2:bi]);
} else if m.Size < 0xffffffffffffffff { // extended: 64 bits } else if m.Size < 0xffffffffffffffff { // extended: 64 bits
@ -153,30 +125,14 @@ func (m T) Send(socket net.Conn) error {
buf := make([]byte, 8) buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, uint64(m.Size)) binary.BigEndian.PutUint64(buf, uint64(m.Size))
buffer = append(buffer, buf...) buffer = append(buffer, buf...)
fmt.Printf(" - size flag: %d\n", 127)
fmt.Printf(" > byte[%d]: '%.2x'\n", bi, 127); bi++
fmt.Printf(" ? '%x'\n", buffer[bi-1]);
fmt.Printf(" - size: %d\n", m.Size)
fmt.Printf(" > byte[%d.%d]: '%16.x'\n", bi, bi+8-1, m.Size); bi+=8
fmt.Printf(" ? '%.16x'\n", buffer[bi-8:bi]);
} }
/* (3) Write header */ /* (3) Add payload */
// fmt.Printf(" - header: %x\n", buffer)
// _, err := socket.Write(buffer)
// if err != nil { return err }
/* (4) Add payload */
buffer = append(buffer, m.Data...) buffer = append(buffer, m.Data...)
fmt.Printf(" - data: '%s'\n", m.Data)
fmt.Printf(" - data: %x\n", m.Data)
fmt.Printf(" > byte[%d.%d]: '%x'\n", bi, bi+m.Size-1, buffer[bi:]); bi+=m.Size
/* (4) Send message */ /* (4) Send over socket */
nbw, err := socket.Write(buffer) _, err := socket.Write(buffer)
fmt.Printf(" - buffer: '%x'\n", buffer)
fmt.Printf(" - written: %d / %d\n", nbw, bi)
if err != nil { return err } if err != nil { return err }
return nil return nil

View File

@ -126,13 +126,13 @@ func (s *T) scheduler(){
/* (1) New client */ /* (1) New client */
case client := <- s.ch.register: case client := <- s.ch.register:
fmt.Printf(" + client (sock: %p)\n", client.IO.Sock) fmt.Printf(" + client\n")
s.clients[client.IO.Sock] = client s.clients[client.IO.Sock] = client
/* (2) New client */ /* (2) New client */
case client := <- s.ch.unregister: case client := <- s.ch.unregister:
fmt.Printf(" - client (sock: %p)\n", client.IO.Sock) fmt.Printf(" - client\n")
delete(s.clients, client.IO.Sock) delete(s.clients, client.IO.Sock)
client.IO.Sock.Close() client.IO.Sock.Close()