MCPcopy
hub / github.com/txthinking/brook / Exchange

Method Exchange

streamclient.go:145–177  ·  view source on GitHub ↗
(local net.Conn)

Source from the content-addressed store, hash-verified

143}
144
145func (c *StreamClient) Exchange(local net.Conn) error {
146 go func() {
147 for {
148 if c.Timeout != 0 {
149 if err := c.Server.SetDeadline(time.Now().Add(time.Duration(c.Timeout) * time.Second)); err != nil {
150 return
151 }
152 }
153 l, err := c.Read()
154 if err != nil {
155 return
156 }
157 if _, err := local.Write(c.RB[2+16 : 2+16+l]); err != nil {
158 return
159 }
160 }
161 }()
162 for {
163 if c.Timeout != 0 {
164 if err := local.SetDeadline(time.Now().Add(time.Duration(c.Timeout) * time.Second)); err != nil {
165 return nil
166 }
167 }
168 l, err := local.Read(c.WB[2+16 : len(c.WB)-16])
169 if err != nil {
170 return nil
171 }
172 if err := c.Write(l); err != nil {
173 return nil
174 }
175 }
176 return nil
177}
178
179func (c *StreamClient) Write(l int) error {
180 binary.BigEndian.PutUint16(c.WB[:2], uint16(l))

Callers 1

TCPHandleMethod · 0.95

Calls 3

ReadMethod · 0.95
WriteMethod · 0.95
SetDeadlineMethod · 0.45

Tested by

no test coverage detected