mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
Apply coding style
This commit is contained in:
parent
273c8f6c57
commit
bfb4e0d9b0
@ -24,11 +24,24 @@ type wsconn struct {
|
||||
|
||||
func (ws *wsconn) Read(b []byte) (n int, err error) {
|
||||
ws.rlock.Lock()
|
||||
n, err = ws.read(b)
|
||||
ws.rlock.Unlock()
|
||||
return n, err
|
||||
|
||||
}
|
||||
|
||||
func (ws *wsconn) read(b []byte) (n int, err error) {
|
||||
|
||||
if ws.connClosing {
|
||||
|
||||
return 0, io.EOF
|
||||
}
|
||||
getNewBuffer := func() error {
|
||||
|
||||
n, err = ws.readNext(b)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (ws *wsconn) getNewReadBuffer() error {
|
||||
_, r, err := ws.wsc.NextReader()
|
||||
if err != nil {
|
||||
log.Warning("WS transport: ws connection NewFrameReader return " + err.Error())
|
||||
@ -38,23 +51,11 @@ func (ws *wsconn) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
ws.readBuffer = bufio.NewReader(r)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/*It seems golang's support for recursive in anonymous func is yet to complete.
|
||||
func1:=func(){
|
||||
func1()
|
||||
}
|
||||
won't work, failed to compile for it can't find func1.
|
||||
|
||||
Should following workaround panic,
|
||||
readNext could have been called before the actual defination was made,
|
||||
This is very unlikely.
|
||||
*/
|
||||
readNext := func(b []byte) (n int, err error) { panic("Runtime unstable. Please report this bug to developer.") }
|
||||
|
||||
readNext = func(b []byte) (n int, err error) {
|
||||
func (ws *wsconn) readNext(b []byte) (n int, err error) {
|
||||
if ws.readBuffer == nil {
|
||||
err = getNewBuffer()
|
||||
err = ws.getNewReadBuffer()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -69,17 +70,12 @@ func (ws *wsconn) Read(b []byte) (n int, err error) {
|
||||
if err == io.EOF {
|
||||
ws.readBuffer = nil
|
||||
if n == 0 {
|
||||
return readNext(b)
|
||||
return ws.readNext(b)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
return n, err
|
||||
|
||||
}
|
||||
n, err = readNext(b)
|
||||
ws.rlock.Unlock()
|
||||
return n, err
|
||||
|
||||
}
|
||||
|
||||
func (ws *wsconn) Write(b []byte) (n int, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user