MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / Read

Method Read

internal/socks/conn.go:28–68  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

26func NewVirtualConn(s *session.Session) *VirtualConn { return &VirtualConn{s: s} }
27
28func (v *VirtualConn) Read(b []byte) (int, error) {
29 for {
30 v.mu.Lock()
31 if len(v.readBuf) > 0 {
32 n := copy(b, v.readBuf)
33 v.readBuf = v.readBuf[n:]
34 v.mu.Unlock()
35 return n, nil
36 }
37 deadline := v.readDeadline
38 v.mu.Unlock()
39
40 var timerCh <-chan time.Time
41 if !deadline.IsZero() {
42 dur := time.Until(deadline)
43 if dur <= 0 {
44 return 0, context.DeadlineExceeded
45 }
46 timerCh = time.After(dur)
47 }
48
49 select {
50 case data, ok := <-v.s.RxChan:
51 if !ok {
52 return 0, io.EOF
53 }
54 if len(data) == 0 {
55 continue
56 }
57 v.mu.Lock()
58 n := copy(b, data)
59 if n < len(data) {
60 v.readBuf = data[n:]
61 }
62 v.mu.Unlock()
63 return n, nil
64 case <-timerCh:
65 return 0, context.DeadlineExceeded
66 }
67 }
68}
69
70func (v *VirtualConn) Write(b []byte) (int, error) {
71 if len(b) > 0 {

Callers 1

SealMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected