Home | History | Annotate | Download | only in jdwp

Lines Matching refs:netState

93             state->netState = netStartup(port);
97 state->netState = netStartup(port);
98 if (state->netState != NULL)
102 if (state->netState == NULL) {
108 state->netState = netStartup(-1);
126 return state->netState->awaitingHandshake;
144 JdwpNetState* netState = new JdwpNetState;
147 return netState;
151 netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
152 if (netState->listenSock < 0) {
158 if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one,
173 if (bind(netState->listenSock, &addr.addrPlain, sizeof(addr)) != 0) {
178 netState->listenPort = port;
179 LOGVV("+++ bound to port %d", netState->listenPort);
181 if (listen(netState->listenSock, 5) != 0) {
186 return netState;
189 netShutdown(netState);
190 netFree(netState);
197 * Note that "netState" may be partially initialized if "startup" failed.
205 static void netShutdown(JdwpNetState* netState)
207 if (netState == NULL)
210 int listenSock = netState->listenSock;
211 int clientSock = netState->clientSock;
214 netState->listenSock = netState->clientSock = -1;
227 if (netState->wakePipe[1] >= 0) {
229 (void) write(netState->wakePipe[1], "", 1);
234 netShutdown(state->netState);
242 static void netFree(JdwpNetState* netState)
244 if (netState == NULL)
246 assert(netState->listenSock == -1);
247 assert(netState->clientSock == -1);
249 if (netState->wakePipe[0] >= 0) {
250 close(netState->wakePipe[0]);
251 netState->wakePipe[0] = -1;
253 if (netState->wakePipe[1] >= 0) {
254 close(netState->wakePipe[1]);
255 netState->wakePipe[1] = -1;
258 delete netState;
262 netFree(state->netState);
270 return (state->netState != NULL &&
271 state->netState->clientSock >= 0);
309 JdwpNetState* netState = state->netState;
311 assert(netState->listenSock >= 0);
313 assert(netState->clientSock < 0);
315 if (!isFdReadable(netState->listenSock))
342 JdwpNetState* netState = state->netState;
350 if (netState->listenSock < 0)
353 assert(netState->clientSock < 0); /* must not already be talking */
357 sock = accept(netState->listenSock, &addr.addrPlain, &addrlen);
369 netState->remoteAddr = addr.addrInet.sin_addr;
370 netState->remotePort = ntohs(addr.addrInet.sin_port);
372 inet_ntoa(netState->remoteAddr), netState->remotePort);
374 netState->clientSock = sock;
375 netState->awaitingHandshake = true;
376 netState->inputCount = 0;
379 setNoDelay(netState->clientSock);
381 if (pipe(netState->wakePipe) < 0) {
401 assert(state != NULL && state->netState != NULL);
444 JdwpNetState* netState;
445 netState = state->netState;
446 netState->clientSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
447 if (netState->clientSock < 0) {
455 if (connect(netState->clientSock, &addr.addrPlain, sizeof(addr)) != 0) {
459 close(netState->clientSock);
460 netState->clientSock = -1;
467 netState->awaitingHandshake = true;
468 netState->inputCount = 0;
470 setNoDelay(netState->clientSock);
472 if (pipe(netState->wakePipe) < 0) {
487 JdwpNetState* netState;
489 assert(state != NULL && state->netState != NULL);
491 netState = state->netState;
492 if (netState->clientSock < 0)
496 inet_ntoa(netState->remoteAddr), netState->remotePort);
498 close(netState->clientSock);
499 netState->clientSock = -1;
507 static bool haveFullPacket(JdwpNetState* netState)
511 if (netState->awaitingHandshake)
512 return (netState->inputCount >= (int) kMagicHandshakeLen);
514 if (netState->inputCount < 4)
517 length = get4BE(netState->inputBuffer);
518 return (netState->inputCount >= length);
527 static void consumeBytes(JdwpNetState* netState, int count)
530 assert(count <= netState->inputCount);
532 if (count == netState->inputCount) {
533 netState->inputCount = 0;
537 memmove(netState->inputBuffer, netState->inputBuffer + count,
538 netState->inputCount - count);
539 netState->inputCount -= count;
584 JdwpNetState* netState = state->netState;
585 const unsigned char* buf = netState->inputBuffer;
595 /*dumpPacket(netState->inputBuffer);*/
609 assert((int) length <= netState->inputCount);
610 dataLen = length - (buf - netState->inputBuffer);
621 ssize_t cc = netState->writePacket(pReply);
639 consumeBytes(netState, length);
660 JdwpNetState* netState = state->netState;
663 assert(netState->clientSock >= 0);
665 if (!haveFullPacket(netState)) {
674 maxfd = netState->listenSock;
675 if (netState->clientSock > maxfd)
676 maxfd = netState->clientSock;
677 if (netState->wakePipe[0] > maxfd)
678 maxfd = netState->wakePipe[0];
688 fd = netState->listenSock;
691 fd = netState->clientSock;
694 fd = netState->wakePipe[0];
721 if (netState->wakePipe[0] >= 0 &&
722 FD_ISSET(netState->wakePipe[0], &readfds))
724 if (netState->listenSock >= 0)
730 if (netState->listenSock >= 0 &&
731 FD_ISSET(netState->listenSock, &readfds))
740 tmpSock = accept(netState->listenSock, &addr.addrPlain,
747 if (netState->clientSock >= 0 &&
748 FD_ISSET(netState->clientSock, &readfds))
750 readCount = read(netState->clientSock,
751 netState->inputBuffer + netState->inputCount,
752 sizeof(netState->inputBuffer) - netState->inputCount);
768 netState->inputCount += readCount;
769 if (!haveFullPacket(netState))
781 if (netState->awaitingHandshake) {
784 if (memcmp(netState->inputBuffer,
787 ALOGE("ERROR: bad handshake '%.14s'", netState->inputBuffer);
792 cc = write(netState->clientSock, netState->inputBuffer,
800 consumeBytes(netState, kMagicHandshakeLen);
801 netState->awaitingHandshake = false;
826 JdwpNetState* netState = state->netState;
829 if (netState->clientSock < 0) {
836 ssize_t cc = netState->writePacket(pReq);
858 JdwpNetState* netState = state->netState;
860 if (netState->clientSock < 0) {
871 ssize_t actual = netState->writeBufferedPacket(iov, iovcnt);