| 87 | } |
| 88 | |
| 89 | bool httpget::connect(bool force) |
| 90 | { |
| 91 | if(force || tcp_age.elapsed() > TCP_TIMEOUT) disconnect(); |
| 92 | if(tcp == ENET_SOCKET_NULL) |
| 93 | { |
| 94 | connectinfo ci = { enet_socket_create(ENET_SOCKET_TYPE_STREAM), ip, 0 }; |
| 95 | tcp_age.start(); |
| 96 | if(ci.sock == ENET_SOCKET_NULL) |
| 97 | { |
| 98 | err = "could not open socket"; |
| 99 | return false; |
| 100 | } |
| 101 | void *ti = sl_createthread(hcont, &ci); |
| 102 | loopk(connecttimeout / 250 + 1) |
| 103 | { |
| 104 | sl_detachthread(NULL); // cleanup call |
| 105 | sl_sleep(250); |
| 106 | if(ci.running) // wait for the connect thread to copy its data |
| 107 | { |
| 108 | if(sl_pollthread(ti)) |
| 109 | { |
| 110 | if(sl_waitthread(ti) < 0) |
| 111 | { |
| 112 | err = "could not connect"; |
| 113 | ti = NULL; |
| 114 | break; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | tcp = ci.sock; |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 | if(execcallback(-float(tcp_age.elapsed()) / (connecttimeout| 1))) break; // esc pressed |
| 123 | } |
| 124 | } |
| 125 | sl_detachthread(ti); |
| 126 | if(!err) err = "could not connect in time"; |
| 127 | enet_socket_destroy(ci.sock); |
| 128 | ASSERT(ci.running); |
| 129 | return false; |
| 130 | } |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | int httpget::get(const char *url1, uint timeout, uint totaltimeout, int range, bool head) |
| 135 | { |
nothing calls this directly
no test coverage detected