| 147 | } |
| 148 | } |
| 149 | static 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 | } |
| 206 | static void lua_client_send(int server_id,int client_id,std::string data) |
nothing calls this directly
no test coverage detected