| 229 | } |
| 230 | } |
| 231 | static int lua_socket_connect(std::string ip,int port) |
| 232 | { |
| 233 | static int last_client_id=0; |
| 234 | CActiveSocket* sock=new CActiveSocket; |
| 235 | if(!sock->Initialize()) |
| 236 | { |
| 237 | CSimpleSocket::CSocketError err=sock->GetSocketError(); |
| 238 | delete sock; |
| 239 | throw std::runtime_error(CSimpleSocket::DescribeError(err)); |
| 240 | } |
| 241 | if(!sock->Open(ip.c_str(),port)) |
| 242 | { |
| 243 | CSimpleSocket::CSocketError err=sock->GetSocketError(); |
| 244 | delete sock; |
| 245 | throw std::runtime_error(CSimpleSocket::DescribeError(err)); |
| 246 | } |
| 247 | sock->SetNonblocking(); |
| 248 | last_client_id++; |
| 249 | clients[last_client_id]=sock; |
| 250 | return last_client_id; |
| 251 | } |
| 252 | CSimpleSocket* get_socket(int server_id, int client_id) |
| 253 | { |
| 254 | std::map<int, CActiveSocket*>* target = &clients; |