MCPcopy Create free account
hub / github.com/assaultcube/AC / connect

Method connect

source/src/http.cpp:89–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89bool 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
134int httpget::get(const char *url1, uint timeout, uint totaltimeout, int range, bool head)
135{

Callers

nothing calls this directly

Calls 11

disconnectFunction · 0.85
sl_createthreadFunction · 0.85
sl_detachthreadFunction · 0.85
sl_sleepFunction · 0.85
sl_pollthreadFunction · 0.85
sl_waitthreadFunction · 0.85
elapsedMethod · 0.80
loopkFunction · 0.70
enet_socket_createFunction · 0.50
enet_socket_destroyFunction · 0.50
startMethod · 0.45

Tested by

no test coverage detected