MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / tcp_client_connect

Method tcp_client_connect

net_port/net_port.cpp:151–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151bool net_port::tcp_client_connect()
152{
153 struct addrinfo *res;
154 connected = false;
155
156 for(res = result_list; res; res = res->ai_next)
157 {
158 sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
159 if(sock == INVALID_SOCKET)
160 {
161 WSACleanup();
162 return(false);
163 }
164
165 u_long arg = 1;
166 fd_set fdset;
167 timeval tv;
168
169 ioctlsocket(sock, FIONBIO, &arg);
170
171 if(result_list == NULL)
172 {
173 connected = false;
174 return(false);
175 }
176 connect(sock, res->ai_addr, res->ai_addrlen);
177
178 FD_ZERO(&fdset);
179 FD_SET(sock, &fdset);
180
181 tv.tv_sec = 4;
182 tv.tv_usec = 0;
183
184 /*-------------------------------------------------*\
185 | Set socket options - no delay |
186 \*-------------------------------------------------*/
187 setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
188
189 if(select(sock + 1, NULL, &fdset, NULL, &tv) == 1)
190 {
191 char so_error;
192 socklen_t len = sizeof(so_error);
193
194 getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
195
196 if(so_error == 0)
197 {
198 connected = true;
199 arg = 0;
200 ioctlsocket(sock, FIONBIO, &arg);
201 }
202 else
203 {
204 connected = false;
205 closesocket(sock);
206 }
207 }
208 else

Callers 9

InitializeMethod · 0.80
SetColorMethod · 0.80
TurnOffMethod · 0.80
SetMusicModeMethod · 0.80
SetPowerMethod · 0.80
SetColorMethod · 0.80
SetLEDsMethod · 0.80
SetColorMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected