More JDWP implementation cleanup.

tsu was confused by some logging that turns out to have been a mistake;
it basically meant "DDMS is not listening", which isn't generally interesting.
This patch relegates that to a VLOG(jdwp).

This patch also removes a bunch more of the adb/socket transport duplication.

Change-Id: I50114da96ec32c20e11ea5ea76d5beba29f30214
diff --git a/src/jdwp/jdwp.h b/src/jdwp/jdwp.h
index d3b6c1b..f2dba0b 100644
--- a/src/jdwp/jdwp.h
+++ b/src/jdwp/jdwp.h
@@ -94,7 +94,7 @@
 };
 
 struct JdwpEvent;
-struct JdwpNetState;
+struct JdwpNetStateBase;
 struct JdwpTransport;
 struct ModBasket;
 struct Request;
@@ -227,12 +227,7 @@
 
   bool HandlePacket();
 
-  /*
-   * Send an event, formatted into "pReq", to the debugger.
-   *
-   * (Messages are sent asynchronously, and do not receive a reply.)
-   */
-  bool SendRequest(ExpandBuf* pReq);
+  void SendRequest(ExpandBuf* pReq);
 
   void ResetState()
       LOCKS_EXCLUDED(event_list_lock_)
@@ -294,6 +289,7 @@
   void UnregisterEvent(JdwpEvent* pEvent)
       EXCLUSIVE_LOCKS_REQUIRED(event_list_lock_)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void SendBufferedRequest(uint32_t type, const iovec* iov, int iov_count);
 
  public: // TODO: fix privacy
   const JdwpOptions* options_;
@@ -314,7 +310,7 @@
   const JdwpTransport* transport_;
 
  public: // TODO: fix privacy
-  JdwpNetState* netState;
+  JdwpNetStateBase* netState;
 
  private:
   // For wait-for-debugger.
diff --git a/src/jdwp/jdwp_adb.cc b/src/jdwp/jdwp_adb.cc
index 788b25a..3ce2064 100644
--- a/src/jdwp/jdwp_adb.cc
+++ b/src/jdwp/jdwp_adb.cc
@@ -54,7 +54,6 @@
 
 struct JdwpNetState : public JdwpNetStateBase {
   int                 controlSock;
-  bool                awaitingHandshake;
   bool                shuttingDown;
   int                 wakeFds[2];
 
@@ -66,7 +65,6 @@
 
   JdwpNetState() {
     controlSock = -1;
-    awaitingHandshake = false;
     shuttingDown = false;
     wakeFds[0] = -1;
     wakeFds[1] = -1;
@@ -77,6 +75,10 @@
   }
 };
 
+static JdwpNetState* GetNetState(JdwpState* state) {
+  return reinterpret_cast<JdwpNetState*>(state->netState);
+}
+
 static void adbStateFree(JdwpNetState* netState) {
   if (netState == NULL) {
     return;
@@ -108,15 +110,9 @@
  * do anything that might block forever.
  */
 static bool startup(JdwpState* state, const JdwpOptions*) {
-  JdwpNetState* netState;
-
   VLOG(jdwp) << "ADB transport startup";
-
-  state->netState = netState = new JdwpNetState;
-  if (netState == NULL) {
-    return false;
-  }
-  return true;
+  state->netState = new JdwpNetState;
+  return (state->netState != NULL);
 }
 
 /*
@@ -177,7 +173,7 @@
  * should return "true" when it successfully accepts a connection.
  */
 static bool acceptConnection(JdwpState* state) {
-  JdwpNetState*  netState = state->netState;
+  JdwpNetState* netState = GetNetState(state);
   int retryCount = 0;
 
   /* first, ensure that we get a connection to the ADB daemon */
@@ -271,7 +267,7 @@
     goto retry;
   } else {
     VLOG(jdwp) << "received file descriptor " << netState->clientSock << " from ADB";
-    netState->awaitingHandshake = 1;
+    netState->SetAwaitingHandshake(true);
     netState->inputCount = 0;
     return true;
   }
@@ -285,24 +281,6 @@
 }
 
 /*
- * Close a connection from a debugger (which may have already dropped us).
- * Only called from the JDWP thread.
- */
-static void closeConnection(JdwpState* state) {
-  CHECK(state != NULL && state->netState != NULL);
-
-  JdwpNetState* netState = state->netState;
-  if (netState->clientSock < 0) {
-    return;
-  }
-
-  VLOG(jdwp) << "+++ closed JDWP <-> ADB connection";
-
-  close(netState->clientSock);
-  netState->clientSock = -1;
-}
-
-/*
  * Close all network stuff, including the socket we use to listen for
  * new connections.
  *
@@ -337,7 +315,7 @@
 }
 
 static void netShutdown(JdwpState* state) {
-  adbStateShutdown(state->netState);
+  adbStateShutdown(GetNetState(state));
 }
 
 /*
@@ -345,36 +323,7 @@
  * "netShutdown", after the JDWP thread has stopped.
  */
 static void netFree(JdwpState* state) {
-  JdwpNetState*  netState = state->netState;
-  adbStateFree(netState);
-}
-
-/*
- * Is a debugger connected to us?
- */
-static bool isConnected(JdwpState* state) {
-  return (state->netState != NULL && state->netState->clientSock >= 0);
-}
-
-/*
- * Are we still waiting for the JDWP handshake?
- */
-static bool awaitingHandshake(JdwpState* state) {
-  return state->netState->awaitingHandshake;
-}
-
-/*
- * Figure out if we have a full packet in the buffer.
- */
-static bool haveFullPacket(JdwpNetState* netState) {
-  if (netState->awaitingHandshake) {
-    return (netState->inputCount >= kMagicHandshakeLen);
-  }
-  if (netState->inputCount < 4) {
-    return false;
-  }
-  uint32_t length = Get4BE(netState->inputBuffer);
-  return (netState->inputCount >= length);
+  adbStateFree(GetNetState(state));
 }
 
 /*
@@ -393,12 +342,12 @@
  * "true" if things are still okay.
  */
 static bool processIncoming(JdwpState* state) {
-  JdwpNetState* netState = state->netState;
+  JdwpNetState* netState = GetNetState(state);
   int readCount;
 
   CHECK_GE(netState->clientSock, 0);
 
-  if (!haveFullPacket(netState)) {
+  if (!netState->HaveFullPacket()) {
     /* read some more, looping until we have data */
     errno = 0;
     while (1) {
@@ -498,7 +447,7 @@
     }
 
     netState->inputCount += readCount;
-    if (!haveFullPacket(netState)) {
+    if (!netState->HaveFullPacket()) {
       return true;        /* still not there yet */
     }
   }
@@ -511,7 +460,7 @@
    *
    * Other than this one case, the protocol [claims to be] stateless.
    */
-  if (netState->awaitingHandshake) {
+  if (netState->IsAwaitingHandshake()) {
     int cc;
 
     if (memcmp(netState->inputBuffer, kMagicHandshake, kMagicHandshakeLen) != 0) {
@@ -527,7 +476,7 @@
     }
 
     netState->ConsumeBytes(kMagicHandshakeLen);
-    netState->awaitingHandshake = false;
+    netState->SetAwaitingHandshake(false);
     VLOG(jdwp) << "+++ handshake complete";
     return true;
   }
@@ -538,85 +487,20 @@
   return state->HandlePacket();
 
  fail:
-  closeConnection(state);
+  netState->Close();
   return false;
 }
 
 /*
- * Send a request.
- *
- * The entire packet must be sent with a single write() call to avoid
- * threading issues.
- *
- * Returns "true" if it was sent successfully.
- */
-static bool sendRequest(JdwpState* state, ExpandBuf* pReq) {
-  JdwpNetState* netState = state->netState;
-
-  if (netState->clientSock < 0) {
-    /* can happen with some DDMS events */
-    VLOG(jdwp) << "NOT sending request -- no debugger is attached";
-    return false;
-  }
-
-  errno = 0;
-
-  ssize_t cc = netState->WritePacket(pReq);
-
-  if (cc != (ssize_t) expandBufGetLength(pReq)) {
-    PLOG(ERROR) << "Failed sending req to debugger (" << cc << " of " << expandBufGetLength(pReq) << ")";
-    return false;
-  }
-
-  return true;
-}
-
-/*
- * Send a request that was split into multiple buffers.
- *
- * The entire packet must be sent with a single writev() call to avoid
- * threading issues.
- *
- * Returns "true" if it was sent successfully.
- */
-static bool sendBufferedRequest(JdwpState* state, const iovec* iov, int iov_count) {
-  JdwpNetState* netState = state->netState;
-
-  if (netState->clientSock < 0) {
-    /* can happen with some DDMS events */
-    VLOG(jdwp) << "NOT sending request -- no debugger is attached";
-    return false;
-  }
-
-  size_t expected = 0;
-  for (int i = 0; i < iov_count; i++) {
-    expected += iov[i].iov_len;
-  }
-
-  ssize_t actual = netState->WriteBufferedPacket(iov, iov_count);
-  if ((size_t)actual != expected) {
-    PLOG(ERROR) << "Failed sending b-req to debugger (" << actual << " of " << expected << ")";
-    return false;
-  }
-
-  return true;
-}
-
-/*
  * Our functions.
  */
 static const JdwpTransport adbTransport = {
   startup,
   acceptConnection,
   establishConnection,
-  closeConnection,
   netShutdown,
   netFree,
-  isConnected,
-  awaitingHandshake,
   processIncoming,
-  sendRequest,
-  sendBufferedRequest
 };
 
 /*
diff --git a/src/jdwp/jdwp_event.cc b/src/jdwp/jdwp_event.cc
index 56ba131..77434e1 100644
--- a/src/jdwp/jdwp_event.cc
+++ b/src/jdwp/jdwp_event.cc
@@ -1077,22 +1077,14 @@
       }
     }
   }
-  bool success;
   if (safe_to_release_mutator_lock_over_send) {
     // Change state to waiting to allow GC, ... while we're sending.
     self->TransitionFromRunnableToSuspended(kWaitingForDebuggerSend);
-    success = (*transport_->sendBufferedRequest)(this, wrapiov, iov_count + 1);
+    SendBufferedRequest(type, wrapiov, iov_count + 1);
     self->TransitionFromSuspendedToRunnable();
   } else {
     // Send and possibly block GC...
-    success = (*transport_->sendBufferedRequest)(this, wrapiov, iov_count + 1);
-  }
-  if (!success) {
-    LOG(INFO) << StringPrintf("JDWP send of type %c%c%c%c failed.",
-                              static_cast<uint8_t>(type >> 24),
-                              static_cast<uint8_t>(type >> 16),
-                              static_cast<uint8_t>(type >> 8),
-                              static_cast<uint8_t>(type));
+    SendBufferedRequest(type, wrapiov, iov_count + 1);
   }
 }
 
diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc
index 6fca7a5..e23d80d 100644
--- a/src/jdwp/jdwp_main.cc
+++ b/src/jdwp/jdwp_main.cc
@@ -38,6 +38,7 @@
 JdwpNetStateBase::JdwpNetStateBase() : socket_lock_("JdwpNetStateBase lock") {
   clientSock = -1;
   inputCount = 0;
+  awaiting_handshake_ = false;
 }
 
 void JdwpNetStateBase::ConsumeBytes(size_t count) {
@@ -53,6 +54,43 @@
   inputCount -= count;
 }
 
+bool JdwpNetStateBase::HaveFullPacket() {
+  if (awaiting_handshake_) {
+    return (inputCount >= kMagicHandshakeLen);
+  }
+  if (inputCount < 4) {
+    return false;
+  }
+  uint32_t length = Get4BE(inputBuffer);
+  return (inputCount >= length);
+}
+
+bool JdwpNetStateBase::IsAwaitingHandshake() {
+  return awaiting_handshake_;
+}
+
+void JdwpNetStateBase::SetAwaitingHandshake(bool new_state) {
+  awaiting_handshake_ = new_state;
+}
+
+bool JdwpNetStateBase::IsConnected() {
+  return clientSock >= 0;
+}
+
+// Close a connection from a debugger (which may have already dropped us).
+// Resets the state so we're ready to receive a new connection.
+// Only called from the JDWP thread.
+void JdwpNetStateBase::Close() {
+  if (clientSock < 0) {
+    return;
+  }
+
+  VLOG(jdwp) << "+++ closing JDWP connection on fd " << clientSock;
+
+  close(clientSock);
+  clientSock = -1;
+}
+
 /*
  * Write a packet. Grabs a mutex to assure atomicity.
  */
@@ -70,11 +108,46 @@
 }
 
 bool JdwpState::IsConnected() {
-  return (*transport_->isConnected)(this);
+  return netState != NULL && netState->IsConnected();
 }
 
-bool JdwpState::SendRequest(ExpandBuf* pReq) {
-  return (*transport_->sendRequest)(this, pReq);
+void JdwpState::SendBufferedRequest(uint32_t type, const iovec* iov, int iov_count) {
+  if (netState->clientSock < 0) {
+    // Can happen with some DDMS events.
+    VLOG(jdwp) << "Not sending JDWP packet: no debugger attached!";
+    return;
+  }
+
+  size_t expected = 0;
+  for (int i = 0; i < iov_count; ++i) {
+    expected += iov[i].iov_len;
+  }
+
+  errno = 0;
+  ssize_t actual = netState->WriteBufferedPacket(iov, iov_count);
+  if (static_cast<size_t>(actual) != expected) {
+    PLOG(ERROR) << StringPrintf("Failed to send JDWP packet %c%c%c%c to debugger (%d of %d)",
+                                static_cast<uint8_t>(type >> 24),
+                                static_cast<uint8_t>(type >> 16),
+                                static_cast<uint8_t>(type >> 8),
+                                static_cast<uint8_t>(type),
+                                actual, expected);
+  }
+}
+
+void JdwpState::SendRequest(ExpandBuf* pReq) {
+  if (netState->clientSock < 0) {
+    // Can happen with some DDMS events.
+    VLOG(jdwp) << "Not sending JDWP packet: no debugger attached!";
+    return;
+  }
+
+  errno = 0;
+  ssize_t actual = netState->WritePacket(pReq);
+  if (static_cast<size_t>(actual) != expandBufGetLength(pReq)) {
+    PLOG(ERROR) << StringPrintf("Failed to send JDWP packet to debugger (%d of %d)",
+                                actual, expandBufGetLength(pReq));
+  }
 }
 
 /*
@@ -390,7 +463,7 @@
         exit(exit_status_);
       }
 
-      if (first && !(*transport_->awaitingHandshake)(this)) {
+      if (first && !netState->IsAwaitingHandshake()) {
         /* handshake worked, tell the interpreter that we're active */
         first = false;
 
@@ -406,7 +479,7 @@
       }
     }
 
-    (*transport_->close)(this);
+    netState->Close();
 
     if (ddm_is_active_) {
       ddm_is_active_ = false;
diff --git a/src/jdwp/jdwp_priv.h b/src/jdwp/jdwp_priv.h
index c03ad2a..1de4c41 100644
--- a/src/jdwp/jdwp_priv.h
+++ b/src/jdwp/jdwp_priv.h
@@ -43,10 +43,6 @@
 
 namespace JDWP {
 
-/*
- * Transport-specific network status.
- */
-struct JdwpNetState;
 struct JdwpState;
 
 /*
@@ -56,21 +52,16 @@
   bool (*startup)(JdwpState* state, const JdwpOptions* options);
   bool (*accept)(JdwpState* state);
   bool (*establish)(JdwpState* state, const JdwpOptions* options);
-  void (*close)(JdwpState* state);
   void (*shutdown)(JdwpState* state);
   void (*free)(JdwpState* state);
-  bool (*isConnected)(JdwpState* state);
-  bool (*awaitingHandshake)(JdwpState* state);
   bool (*processIncoming)(JdwpState* state);
-  bool (*sendRequest)(JdwpState* state, ExpandBuf* pReq);
-  bool (*sendBufferedRequest)(JdwpState* state, const iovec* iov, int iov_count);
 };
 
 const JdwpTransport* SocketTransport();
 const JdwpTransport* AndroidAdbTransport();
 
 /*
- * Base class for JdwpNetState
+ * Base class for the adb and socket JdwpNetState implementations.
  */
 class JdwpNetStateBase {
  public:
@@ -82,13 +73,27 @@
   size_t inputCount;
 
   JdwpNetStateBase();
+
   void ConsumeBytes(size_t byte_count);
+
+  bool IsConnected();
+
+  bool IsAwaitingHandshake();
+  void SetAwaitingHandshake(bool new_state);
+
+  bool HaveFullPacket();
+
+  void Close();
+
   ssize_t WritePacket(ExpandBuf* pReply);
   ssize_t WriteBufferedPacket(const iovec* iov, int iov_count);
 
  private:
   // Used to serialize writes to the socket.
   Mutex socket_lock_;
+
+  // Are we waiting for the JDWP handshake?
+  bool awaiting_handshake_;
 };
 
 }  // namespace JDWP
diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc
index 13e150a..755ded5 100644
--- a/src/jdwp/jdwp_socket.cc
+++ b/src/jdwp/jdwp_socket.cc
@@ -37,10 +37,6 @@
 
 namespace JDWP {
 
-// fwd
-static void netShutdown(JdwpNetState* state);
-static void netFree(JdwpNetState* state);
-
 /*
  * JDWP network state.
  *
@@ -54,18 +50,21 @@
   in_addr remoteAddr;
   uint16_t remotePort;
 
-  bool    awaitingHandshake;  /* waiting for "JDWP-Handshake" */
-
   JdwpNetState() {
     listenPort  = 0;
     listenSock  = -1;
     wakePipe[0] = -1;
     wakePipe[1] = -1;
-
-    awaitingHandshake = false;
   }
 };
 
+static void socketStateShutdown(JdwpNetState* state);
+static void socketStateFree(JdwpNetState* state);
+
+static JdwpNetState* GetNetState(JdwpState* state) {
+  return reinterpret_cast<JdwpNetState*>(state->netState);
+}
+
 static JdwpNetState* netStartup(uint16_t port, bool probe);
 
 /*
@@ -105,13 +104,6 @@
 }
 
 /*
- * Are we still waiting for the handshake string?
- */
-static bool awaitingHandshake(JdwpState* state) {
-  return state->netState->awaitingHandshake;
-}
-
-/*
  * Initialize JDWP stuff.
  *
  * Allocates a new state structure.  If "port" is non-zero, this also
@@ -167,8 +159,8 @@
   return netState;
 
  fail:
-  netShutdown(netState);
-  netFree(netState);
+  socketStateShutdown(netState);
+  socketStateFree(netState);
   return NULL;
 }
 
@@ -183,7 +175,7 @@
  * (This is currently called several times during startup as we probe
  * for an open port.)
  */
-static void netShutdown(JdwpNetState* netState) {
+static void socketStateShutdown(JdwpNetState* netState) {
   if (netState == NULL) {
     return;
   }
@@ -211,16 +203,16 @@
   }
 }
 
-static void netShutdownExtern(JdwpState* state) {
-  netShutdown(state->netState);
+static void netShutdown(JdwpState* state) {
+  socketStateShutdown(GetNetState(state));
 }
 
 /*
  * Free JDWP state.
  *
- * Call this after shutting the network down with netShutdown().
+ * Call this after shutting the network down with socketStateShutdown().
  */
-static void netFree(JdwpNetState* netState) {
+static void socketStateFree(JdwpNetState* netState) {
   if (netState == NULL) {
     return;
   }
@@ -239,15 +231,8 @@
   delete netState;
 }
 
-static void netFreeExtern(JdwpState* state) {
-  netFree(state->netState);
-}
-
-/*
- * Returns "true" if we're connected to a debugger.
- */
-static bool isConnected(JdwpState* state) {
-  return (state->netState != NULL && state->netState->clientSock >= 0);
+static void netFree(JdwpState* state) {
+  socketStateFree(GetNetState(state));
 }
 
 /*
@@ -268,7 +253,7 @@
  * is pending.
  */
 static bool acceptConnection(JdwpState* state) {
-  JdwpNetState* netState = state->netState;
+  JdwpNetState* netState = GetNetState(state);
   union {
     sockaddr_in  addrInet;
     sockaddr     addrPlain;
@@ -304,7 +289,7 @@
   VLOG(jdwp) << "+++ accepted connection from " << inet_ntoa(netState->remoteAddr) << ":" << netState->remotePort;
 
   netState->clientSock = sock;
-  netState->awaitingHandshake = true;
+  netState->SetAwaitingHandshake(true);
   netState->inputCount = 0;
 
   VLOG(jdwp) << "Setting TCP_NODELAY on accepted socket";
@@ -367,8 +352,7 @@
   /*
    * Create a socket.
    */
-  JdwpNetState* netState;
-  netState = state->netState;
+  JdwpNetState* netState = GetNetState(state);
   netState->clientSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
   if (netState->clientSock < 0) {
     PLOG(ERROR) << "Unable to create socket";
@@ -386,7 +370,7 @@
   }
 
   LOG(INFO) << "Connection established to " << options->host << " (" << inet_ntoa(addr.addrInet.sin_addr) << ":" << ntohs(addr.addrInet.sin_port) << ")";
-  netState->awaitingHandshake = true;
+  netState->SetAwaitingHandshake(true);
   netState->inputCount = 0;
 
   setNoDelay(netState->clientSock);
@@ -400,41 +384,6 @@
 }
 
 /*
- * Close the connection to the debugger.
- *
- * Reset the state so we're ready to receive a new connection.
- */
-static void closeConnection(JdwpState* state) {
-  JdwpNetState* netState;
-
-  CHECK(state != NULL && state->netState != NULL);
-
-  netState = state->netState;
-  if (netState->clientSock < 0) {
-    return;
-  }
-
-  VLOG(jdwp) << "+++ closed connection to " << inet_ntoa(netState->remoteAddr) << ":" << netState->remotePort;
-
-  close(netState->clientSock);
-  netState->clientSock = -1;
-}
-
-/*
- * Figure out if we have a full packet in the buffer.
- */
-static bool haveFullPacket(JdwpNetState* netState) {
-  if (netState->awaitingHandshake) {
-    return (netState->inputCount >= kMagicHandshakeLen);
-  }
-  if (netState->inputCount < 4) {
-    return false;
-  }
-  uint32_t length = Get4BE(netState->inputBuffer);
-  return (netState->inputCount >= length);
-}
-
-/*
  * Process incoming data.  If no data is available, this will block until
  * some arrives.
  *
@@ -450,12 +399,12 @@
  * "true" if things are still okay.
  */
 static bool processIncoming(JdwpState* state) {
-  JdwpNetState* netState = state->netState;
+  JdwpNetState* netState = GetNetState(state);
   int readCount;
 
   CHECK_GE(netState->clientSock, 0);
 
-  if (!haveFullPacket(netState)) {
+  if (!netState->HaveFullPacket()) {
     /* read some more, looping until we have data */
     errno = 0;
     while (1) {
@@ -550,7 +499,7 @@
           return true;
         } else if (readCount == 0) {
           /* EOF hit -- far end went away */
-          LOG(DEBUG) << "+++ peer disconnected";
+          VLOG(jdwp) << "+++ peer disconnected";
           goto fail;
         } else {
           break;
@@ -559,7 +508,7 @@
     }
 
     netState->inputCount += readCount;
-    if (!haveFullPacket(netState)) {
+    if (!netState->HaveFullPacket()) {
       return true;        /* still not there yet */
     }
   }
@@ -572,7 +521,7 @@
    *
    * Other than this one case, the protocol [claims to be] stateless.
    */
-  if (netState->awaitingHandshake) {
+  if (netState->IsAwaitingHandshake()) {
     int cc;
 
     if (memcmp(netState->inputBuffer, kMagicHandshake, kMagicHandshakeLen) != 0) {
@@ -588,7 +537,7 @@
     }
 
     netState->ConsumeBytes(kMagicHandshakeLen);
-    netState->awaitingHandshake = false;
+    netState->SetAwaitingHandshake(false);
     VLOG(jdwp) << "+++ handshake complete";
     return true;
   }
@@ -599,72 +548,11 @@
   return state->HandlePacket();
 
  fail:
-  closeConnection(state);
+  netState->Close();
   return false;
 }
 
 /*
- * Send a request.
- *
- * The entire packet must be sent with a single write() call to avoid
- * threading issues.
- *
- * Returns "true" if it was sent successfully.
- */
-static bool sendRequest(JdwpState* state, ExpandBuf* pReq) {
-  JdwpNetState* netState = state->netState;
-
-  /*dumpPacket(expandBufGetBuffer(pReq));*/
-  if (netState->clientSock < 0) {
-    /* can happen with some DDMS events */
-    VLOG(jdwp) << "NOT sending request -- no debugger is attached";
-    return false;
-  }
-
-  errno = 0;
-  ssize_t cc = netState->WritePacket(pReq);
-
-  if (cc != (ssize_t) expandBufGetLength(pReq)) {
-    PLOG(ERROR) << "Failed sending req to debugger (" << cc << " of " << expandBufGetLength(pReq) << ")";
-    return false;
-  }
-
-  return true;
-}
-
-/*
- * Send a request that was split into multiple buffers.
- *
- * The entire packet must be sent with a single writev() call to avoid
- * threading issues.
- *
- * Returns "true" if it was sent successfully.
- */
-static bool sendBufferedRequest(JdwpState* state, const iovec* iov, int iov_count) {
-  JdwpNetState* netState = state->netState;
-
-  if (netState->clientSock < 0) {
-    /* can happen with some DDMS events */
-    VLOG(jdwp) << "NOT sending request -- no debugger is attached";
-    return false;
-  }
-
-  size_t expected = 0;
-  for (int i = 0; i < iov_count; i++) {
-    expected += iov[i].iov_len;
-  }
-
-  ssize_t actual = netState->WriteBufferedPacket(iov, iov_count);
-
-  if ((size_t)actual != expected) {
-    PLOG(ERROR) << "Failed sending b-req to debugger (" << actual << " of " << expected << ")";
-    return false;
-  }
-
-  return true;
-}
-
-/*
  * Our functions.
  *
  * We can't generally share the implementations with other transports,
@@ -675,14 +563,9 @@
   prepareSocket,
   acceptConnection,
   establishConnection,
-  closeConnection,
-  netShutdownExtern,
-  netFreeExtern,
-  isConnected,
-  awaitingHandshake,
+  netShutdown,
+  netFree,
   processIncoming,
-  sendRequest,
-  sendBufferedRequest,
 };
 
 /*