Home | History | Annotate | Download | only in jdwpspy

Lines Matching refs:netState

47 typedef struct NetState {
57 } NetState;
220 void jdwpNetFree(NetState* netState); /* fwd */
227 NetState* jdwpNetStartup(unsigned short listenPort, const char* connectHost,
230 NetState* netState = (NetState*) malloc(sizeof(*netState));
231 memset(netState, 0, sizeof(*netState));
232 netState->listenSock = -1;
233 netState->dbg.sock = netState->vm.sock = -1;
235 strcpy(netState->dbg.label, "D");
236 strcpy(netState->vm.label, "V");
242 netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
243 if (netState->listenSock < 0) {
251 if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one,
265 if (bind(netState->listenSock, (struct sockaddr*) &addr, sizeof(addr)) != 0)
274 if (listen(netState->listenSock, 5) != 0) {
291 netState->vmAddr = *((struct in_addr*) pHost->h_addr_list[0]);
292 netState->vmPort = connectPort;
295 inet_ntoa(netState->vmAddr));
297 return netState;
300 jdwpNetFree(netState);
307 * Note that "netState" may be partially initialized if "startup" failed.
309 void jdwpNetShutdown(NetState* netState)
311 int listenSock = netState->listenSock;
312 int dbgSock = netState->dbg.sock;
313 int vmSock = netState->vm.sock;
317 netState->listenSock = netState->dbg.sock = netState->vm.sock = -1;
336 void jdwpNetFree(NetState* netState)
338 if (netState == NULL)
341 jdwpNetShutdown(netState);
342 free(netState);
362 bool jdwpAcceptConnection(NetState* netState)
368 if (netState->listenSock < 0)
371 assert(netState->dbg.sock < 0); /* must not already be talking */
375 sock = accept(netState->listenSock, (struct sockaddr*) &addr, &addrlen);
385 netState->dbg.sock = sock;
386 netState->dbg.awaitingHandshake = true;
387 netState->dbg.inputCount = 0;
399 void jdwpCloseConnection(NetState* netState)
401 if (netState->dbg.sock >= 0) {
403 close(netState->dbg.sock);
404 netState->dbg.sock = -1;
406 if (netState->vm.sock >= 0) {
408 close(netState->vm.sock);
409 netState->vm.sock = -1;
586 bool jdwpProcessIncoming(NetState* netState)
590 assert(netState->dbg.sock >= 0);
591 assert(netState
593 while (!haveFullPacket(&netState->dbg) && !haveFullPacket(&netState->vm)) {
598 highFd = (netState->dbg.sock > netState->vm.sock) ?
599 netState->dbg.sock+1 : netState->vm.sock+1;
601 FD_SET(netState->dbg.sock, &readfds);
602 FD_SET(netState->vm.sock, &readfds);
615 if (FD_ISSET(netState->dbg.sock, &readfds)) {
616 cc = read(netState->dbg.sock,
617 netState->dbg.inputBuffer + netState->dbg.inputCount,
618 sizeof(netState->dbg.inputBuffer) - netState->dbg.inputCount);
628 if (sizeof(netState->dbg.inputBuffer) ==
629 netState->dbg.inputCount)
637 netState->dbg.inputCount += cc;
640 if (FD_ISSET(netState->vm.sock, &readfds)) {
641 cc = read(netState->vm.sock,
642 netState->vm.inputBuffer + netState->vm.inputCount,
643 sizeof(netState->vm.inputBuffer) - netState->vm.inputCount);
653 if (sizeof(netState->vm.inputBuffer) ==
654 netState->vm.inputCount)
662 netState->vm.inputCount += cc;
666 if (!handleIncoming(&netState->dbg, &netState->vm))
668 if (!handleIncoming(&netState->vm, &netState->dbg))
674 jdwpCloseConnection(netState);
681 bool jdwpConnectToVm(NetState* netState)
693 addr.sin_addr = netState->vmAddr;
694 addr.sin_port = htons(netState->vmPort);
703 netState->vm.sock = sock;
704 netState->vm.awaitingHandshake = true;
705 netState->vm.inputCount = 0;
707 setNoDelay(netState->vm.sock);
725 NetState* state;