MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / Write

Method Write

agentprotocol/server.go:39–75  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

37}
38
39func (c *Connection) Write(data []byte) (n int, err error) {
40 c.lock.Lock()
41 defer c.lock.Unlock()
42L:
43 for {
44 switch c.state {
45 case CONNECTION_STATE_WAITINIT:
46 c.stateCond.Wait()
47 continue
48 case CONNECTION_STATE_STARTED:
49 break L
50 case CONNECTION_STATE_WAITCLOSE:
51 fallthrough
52 case CONNECTION_STATE_CLOSED:
53 _ = c.bufferWriter.Close()
54 return 0, fmt.Errorf("connection closed")
55 default:
56 return 0, fmt.Errorf("unknown connection state %d", c.state)
57 }
58 }
59
60 packet := Packet{
61 Type: PACKET_DATA,
62 ConnectionId: c.id,
63 Payload: data,
64 }
65 err = c.ctx.writePacket(&packet)
66 if err != nil {
67 c.logger.Error(message.Wrap(
68 err,
69 message.MSSHConnected,
70 "Error writing packet",
71 ))
72 return 0, err
73 }
74 return len(data), nil
75}
76
77func (c *Connection) Close() error {
78 c.lock.Lock()

Callers

nothing calls this directly

Calls 6

WrapFunction · 0.92
writePacketMethod · 0.80
WaitMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected