comment non-bloquing read
This commit is contained in:
parent
ab351de382
commit
b713011e7b
|
@ -21,7 +21,7 @@ func main(){
|
|||
|
||||
// if receive message -> send it back
|
||||
sender <- &msg
|
||||
// sender <- nil
|
||||
sender <- nil
|
||||
|
||||
}
|
||||
|
||||
|
|
27
ws/client.go
27
ws/client.go
|
@ -131,21 +131,21 @@ func (c *client) reader(){
|
|||
}
|
||||
|
||||
/* (2) Wait for available data */
|
||||
c.io.sock.SetReadDeadline(time.Now().Add(time.Microsecond*10))
|
||||
_, err := c.io.reader.Peek(1)
|
||||
// c.io.sock.SetReadDeadline(time.Now().Add(10*time.Microsecond))
|
||||
// _, err := c.io.reader.Peek(1)
|
||||
|
||||
// timeout -> continune checking
|
||||
if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
|
||||
continue
|
||||
// // timeout -> continune checking
|
||||
// if neterr, ok := err.(net.Error); ok && neterr.Timeout() {
|
||||
// time.Sleep(10*time.Microsecond)
|
||||
// continue
|
||||
// }
|
||||
|
||||
}
|
||||
// // another error -> stop reading
|
||||
// if err != nil {
|
||||
// break
|
||||
// }
|
||||
|
||||
// another error -> stop reading
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
c.io.sock.SetReadDeadline(time.Time{}) // remove timeout
|
||||
// c.io.sock.SetReadDeadline(time.Time{}) // remove timeout
|
||||
|
||||
/* (3) Parse message */
|
||||
msg, err := readMessage(c.io.reader)
|
||||
|
@ -238,7 +238,7 @@ func (c *client) close(status MessageError){
|
|||
Data: make([]byte, 8),
|
||||
}
|
||||
binary.BigEndian.PutUint16(msg.Data, uint16(status))
|
||||
msg.Data = append(msg.Data, []byte("Closing")...)
|
||||
msg.Data = append(msg.Data, []byte(" close")...)
|
||||
msg.Size = uint( len(msg.Data) )
|
||||
|
||||
/* Send message */
|
||||
|
@ -247,6 +247,7 @@ func (c *client) close(status MessageError){
|
|||
}
|
||||
|
||||
/* (2) Close socket */
|
||||
c.io.sock.SetReadDeadline(time.Now())
|
||||
time.Sleep(time.Second * 3)
|
||||
c.io.sock.Close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue