MCPcopy Index your code
hub / github.com/devspace-sh/devspace / ReceiveData

Function ReceiveData

helper/tunnel/server.go:90–141  ·  view source on GitHub ↗
(stream remote.Tunnel_InitTunnelServer, closeChan chan struct{})

Source from the content-addressed store, hash-verified

88}
89
90func ReceiveData(stream remote.Tunnel_InitTunnelServer, closeChan chan struct{}) {
91 for {
92 select {
93 case <-closeChan:
94 return
95 case <-stream.Context().Done():
96 return
97 default:
98 message, err := stream.Recv()
99 if err != nil {
100 stderrlog.Errorf("failed receiving message from stream, exiting: %v", err)
101 close(closeChan)
102 continue
103 }
104
105 reqID, err := uuid.Parse(message.GetRequestId())
106 if err != nil {
107 stderrlog.Errorf(" %s; failed to parse requestId, %v", message.GetRequestId(), err)
108 continue
109 }
110
111 session, ok := GetSession(reqID)
112 if !ok && !message.ShouldClose {
113 stderrlog.Errorf("%s; session not found in openRequests", reqID)
114 continue
115 }
116
117 data := message.GetData()
118 br := len(data)
119
120 stderrlog.Debugf("received %d bytes from client", len(data))
121
122 // send data if we received any
123 if br > 0 && session.Open {
124 stderrlog.Debugf("writing %d bytes to conn", br)
125 _, err := session.Conn.Write(data)
126 if err != nil {
127 stderrlog.Errorf("%s; failed writing data to socket", reqID)
128 message.ShouldClose = true
129 } else {
130 stderrlog.Debugf("wrote %d bytes to conn", br)
131 }
132 }
133
134 if message.ShouldClose {
135 stderrlog.Debugf("closing session")
136 session.Close()
137 stderrlog.Debugf("closed session")
138 }
139 }
140 }
141}
142
143func readConn(ctx context.Context, session *Session, sessions chan<- *Session) {
144 for {

Callers 1

InitTunnelMethod · 0.70

Calls 12

ErrorfFunction · 0.92
DebugfFunction · 0.92
closeFunction · 0.85
GetSessionFunction · 0.85
DoneMethod · 0.65
ContextMethod · 0.65
RecvMethod · 0.65
ParseMethod · 0.65
GetDataMethod · 0.65
CloseMethod · 0.65
GetRequestIdMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected