void tcp_client_connected_thread(int a2) {
  int v2;
  int v3;
  SOCKET sock;
  int version;
  int timeout;
  int msglen;
  int local_peer;
  int counter;
  int result_out;
  int peeraddr;
  int locaddr;
  char buf[8194];
  char recvbuf[];


  sock = *(int *)(a2 + 12);
  local_peer = *(int *)(a2 + 16);
  getsockname_then_getpeername(a2, (struct sockaddr*&) locaddr, (struct
                               sockaddr *)&peeraddr, sock);
  version = get_payload_version();
  generate_new_message(buf+2, (int)&result_out, 1, local_peer, 6, 0, version, 0,
                       0, 0, 0, 0);

  for (counter=0;  counter < 2000 && result_out; counter++ ) {

    if (!WaitForSingleObject(*(HANDLE *)(a2 + 8), 0)) break;

    *(ushort *)buf = result_out;

    timeout = 5 - (local_peer != 0);

    if (call_select_and_send(buf, result_out + 2, sock, 8194, timeout)!= 4) break;

    if (call_recv(sock, recvbuf, 8194, (int)&msglen, timeout) != 4 || !msglen)
        break;

    client_handle_recvmsg(peeraddr, recvbuf, msglen - 2, locaddr, local_peer, 6,
                          (void *)sock, buf+2, (int)&result_out, 0);
  }
  closesocket(sock);
  ExitThread(0);
}

SOURCE LISTING 13: TCP client connected thread



 


 







Acknowledements

  This material is based upon work supported through the U.S. Army Research Office under the Cyber-TA Research Grant No. W911NF-06-1- 0316 and by the National Science Foundation, Grant No. CNS-07-16 612. The views expressed in this document are those of the authors and do not necessarily represent the official position of the sponsors.