MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxConnect

Function fxConnect

xs/platforms/win_xs.c:154–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152
153#ifdef mxDebug
154void fxConnect(txMachine* the)
155{
156 WSADATA wsaData;
157 struct hostent *host;
158 struct sockaddr_in address;
159 char name[C_PATH_MAX];
160 unsigned long flag;
161 char *hostname = "localhost";
162 if (getenv("XSBUG_HOST"))
163 hostname = getenv("XSBUG_HOST");
164
165 if (WSAStartup(0x202, &wsaData) == SOCKET_ERROR)
166 goto bail;
167 host = gethostbyname(hostname);
168 if (!host)
169 goto bail;
170 memset(&address, 0, sizeof(address));
171 address.sin_family = AF_INET;
172 memcpy(&(address.sin_addr), host->h_addr, host->h_length);
173 if (GetModuleFileName(NULL, name, sizeof(name)) && strstr(name, "xsbug"))
174 address.sin_port = htons(5003);
175 else {
176 int port = 5002;
177 char *portStr = getenv("XSBUG_PORT");
178 if (portStr)
179 port = atoi(portStr);
180 address.sin_port = htons(port);
181 }
182 the->connection = socket(AF_INET, SOCK_STREAM, 0);
183 if (the->connection == INVALID_SOCKET)
184 goto bail;
185 flag = 1;
186 ioctlsocket(the->connection, FIONBIO, &flag);
187 if (connect(the->connection, (struct sockaddr*)&address, sizeof(address)) == SOCKET_ERROR) {
188 if (WSAEWOULDBLOCK == WSAGetLastError()) {
189 fd_set fds;
190 struct timeval timeout = { 2, 0 }; // 2 seconds, 0 micro-seconds
191 FD_ZERO(&fds);
192 FD_SET(the->connection, &fds);
193 if (select(0, NULL, &fds, NULL, &timeout) == 0)
194 goto bail;
195 if (!FD_ISSET(the->connection, &fds))
196 goto bail;
197 }
198 else
199 goto bail;
200 }
201 // flag = 0;
202 // ioctlsocket(the->connection, FIONBIO, &flag);
203 if (WSAAsyncSelect(the->connection, the->window, WM_XSBUG, FD_READ))
204 goto bail;
205 return;
206bail:
207 fxDisconnect(the);
208}
209
210void fxDisconnect(txMachine* the)
211{

Callers

nothing calls this directly

Calls 3

selectFunction · 0.85
fxDisconnectFunction · 0.70
connectFunction · 0.50

Tested by

no test coverage detected