MCPcopy Create free account
hub / github.com/cuberite/cuberite / ReceiveResponse

Method ReceiveResponse

Tools/RCONClient/RCONClient.cpp:103–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102
103bool cRCONPacketizer::ReceiveResponse(void)
104{
105 // Receive the response:
106 cByteBuffer Buffer(64 KiB);
107 while (true)
108 {
109 char buf[1024];
110 int NumReceived = m_Socket.Receive(buf, sizeof(buf), 0);
111 if (NumReceived == 0)
112 {
113 fprintf(stderr, "The remote end closed the connection. Aborting.");
114 return false;
115 }
116 if (NumReceived < 0)
117 {
118 fprintf(stderr, "Network error while receiving response: %d, %d (%s). Aborting.",
119 NumReceived, cSocket::GetLastError(), cSocket::GetLastErrorString().c_str()
120 );
121 return false;
122 }
123 Buffer.Write(buf, NumReceived);
124 Buffer.ResetRead();
125
126 // Check if the buffer contains the full packet:
127 if (!Buffer.CanReadBytes(14))
128 {
129 // 14 is the minimum packet size for RCON
130 continue;
131 }
132 int PacketSize;
133 VERIFY(Buffer.ReadLEInt(PacketSize));
134 if (!Buffer.CanReadBytes(PacketSize))
135 {
136 // The packet is not complete yet
137 continue;
138 }
139
140 // Parse the packet
141 return ParsePacket(Buffer, PacketSize);
142 }
143}
144
145
146

Callers

nothing calls this directly

Calls 6

ReceiveMethod · 0.80
c_strMethod · 0.80
ResetReadMethod · 0.80
CanReadBytesMethod · 0.80
ReadLEIntMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected