MCPcopy Create free account
hub / github.com/DFHack/dfhack / lua_client_receive

Function lua_client_receive

plugins/luasocket.cpp:149–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147 }
148}
149static std::string lua_client_receive(int server_id,int client_id,int bytes,std::string pattern,bool fail_on_timeout)
150{
151 auto info=get_client(server_id,client_id);
152 CActiveSocket *sock=info.first;
153 if(bytes>0)
154 {
155 if(sock->Receive(bytes)<=0)
156 {
157 throw std::runtime_error(sock->DescribeError());
158 }
159 return std::string((char*)sock->GetData(),bytes);
160 }
161 else
162 {
163 std::string ret;
164 if(pattern=="*a") //??
165 {
166 while(true)
167 {
168 int received=sock->Receive(1);
169 if(received<0)
170 {
171 handle_error(sock->GetSocketError(),!fail_on_timeout);
172 return "";//maybe return partial string?
173 }
174 else if(received==0)
175 {
176 break;
177 }
178 ret+=(char)*sock->GetData();
179
180 }
181 return ret;
182 }
183 else if (pattern=="" || pattern=="*l")
184 {
185 while(true)
186 {
187
188 if(sock->Receive(1)<=0)
189 {
190 handle_error(sock->GetSocketError(),!fail_on_timeout);
191 return "";//maybe return partial string?
192 }
193 char rec=(char)*sock->GetData();
194 if(rec=='\n')
195 break;
196 ret+=rec;
197 }
198 return ret;
199 }
200 else
201 {
202 throw std::runtime_error("Unsupported receive pattern");
203 }
204 }
205}
206static void lua_client_send(int server_id,int client_id,std::string data)

Callers

nothing calls this directly

Calls 2

get_clientFunction · 0.85
handle_errorFunction · 0.85

Tested by

no test coverage detected