void tcp_server_connected_thread(int a1, int a2, int a3) {
  SOCKET sock;
  signed int res;
  struct sockaddr locaddr;
  struct sockaddr peeraddr;
  int recvlen;
  char* buf;      
  char recvbuf[8196];  

  sock = *(_DWORD *)(a3 + 12);
  getsockname_then_getpeername(a2, (int)&locaddr,  &peeraddr, sock);

  for (int i=0; i < 2000; i++) {
    if ( call_WaitForSingleObject(0, a3) )
      break;

    /* (socket, buf, buflen, recvlen, timeout) */
    res = call_recv(sock, recvbuf, 8194, (int)&recvlen, 6);

    if ( res != 4 || !recvlen) break;

    server_handle_recv((char*)&recvbuf, recvlen - 2, (int)&peeraddr, (int)&locaddr,
                       6, sock, buf);
    if ( !buf )
      break;

    res = call_select_and_send(buf,  buf+2, sock, 8194, 5);

    if ( res != 4 ) break;
  }

  closesocket(sock);
  ExitThread(0);
}


SOURCE LISTING 11: TCP server 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.