Esempio n. 1
0
int tclcommand_imd_print_check_connect(Tcl_Interp *interp)
{
  /* handshaking */
  if (vmdsock_selread(initsock, 0) > 0) {
    int32_t length;

    sock = vmdsock_accept(initsock);
    if (imd_handshake(sock)) {
      Tcl_AppendResult(interp, "IMD handshake failed. Wrong VMD version ?",
		       (char *) NULL);
      vmdsock_destroy(sock);
      sock = 0;
      return (TCL_ERROR);
    }

    sleep(1);
    if ((vmdsock_selread(sock, 0) != 1) ||
	(imd_recv_header(sock, &length) != IMD_GO)) {
      Tcl_AppendResult(interp, "No go from VMD. Wrong VMD version ?",
		       (char *) NULL);
      vmdsock_destroy(sock);
      sock = 0;
      return (TCL_ERROR);
    }

    sleep(1);
  }

  return (TCL_OK);
}
Esempio n. 2
0
void IMD::connect(){
  if(comm.Get_rank()==0) {
    if(wait && clientsock==NULL)
      fprintf(stderr,"Waiting for IMD connection on %s:%d...\n", host.c_str(), port);
    do{
      if (vmdsock_selread(sock,00) > 0) {
        clientsock = vmdsock_accept(sock);
        if (imd_handshake(clientsock)) {
          clientsock = NULL;
        };
        sleep(1);
        int length;
        if(clientsock){
          if (vmdsock_selread(clientsock, 0) != 1 ||
              imd_recv_header(clientsock, &length) != IMD_GO) {
            clientsock = NULL;
          }
        }
      }
    } while(wait && clientsock==NULL);
    connected=(clientsock!=NULL);
    int c=connected;
    comm.Bcast(&c,1,0);
  } else {
    int c;
    comm.Bcast(&c,1,0);
    connected=c;
  }
}
Esempio n. 3
0
void *VMDCollab::serverproc(void *serversock) {

  ResizeArray<void *>clients;
  char buf[VMDCOLLAB_MSGSIZE];
  int i, j;
  
  while (1) {
    // if we have no clients, hang until someone connects
    // otherwise, just check for pending connections
    if (vmdsock_selread(serversock, 0) > 0) {
      msgInfo << "serversock became readable" << sendmsg;
      void *clientsock = vmdsock_accept(serversock);
      if (clientsock) {
        msgInfo << "VMDCollab accepting connection" << sendmsg;
        clients.append(clientsock);
      }
    } else if (vmdsock_selwrite(serversock, 0)) {
      msgInfo << "serversock became writable; exiting..." << sendmsg;
      break;
    }

    // Loop through one socket at a time.  If incoming data is found,
    // drain it before moving on, on the assumption that we only want
    // commands from one VMD at a time to be propagated to the other
    // clients.
    for (i=0; i<clients.num(); i++) {
      void *client = clients[i];
      while (vmdsock_selread(client, 0) > 0) {
        memset(buf, 0, VMDCOLLAB_MSGSIZE);
        if (imd_readn(client, buf, VMDCOLLAB_MSGSIZE) != VMDCOLLAB_MSGSIZE) {
          msgInfo << "client sent incomplete message, shutting it down"
                  << sendmsg;
          vmdsock_shutdown(client);
          vmdsock_destroy(client);
          clients.remove(clients.find(client));
          break;
        }
        // send to all other clients
        for (j=0; j<clients.num(); j++) {
          void *dest = clients[j];
          if (dest != client) {
            imd_writen(clients[j], buf, VMDCOLLAB_MSGSIZE);
          }
        } // loop over clients other than sender
      } // while client is readable
    } // loop over clients
    vmd_msleep(10);
  }
  // if here, then the serversock got shut down, indicating that it's
  // time to die.
  msgInfo << "VMDCollab shutting down server" << sendmsg;
  for (i=0; i<clients.num(); i++) {
    void *client = clients[i];
    strcpy(buf, "exit");
    imd_writen(client, buf, VMDCOLLAB_MSGSIZE);
    vmdsock_shutdown(client);
    vmdsock_destroy(client);
  }
  vmdsock_destroy(serversock);
  return NULL;
}