int imd_send_fcoords(void *s, int32 n, const float *coords) { int rc; int32 size = HEADERSIZE+12*n; char *buf = (char *) malloc(sizeof(char) * size); fill_header((IMDheader *)buf, IMD_FCOORDS, n); memcpy(buf+HEADERSIZE, coords, 12*n); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
int imd_send_energies(void *s, const IMDEnergies *energies) { int rc; int32 size = HEADERSIZE+sizeof(IMDEnergies); char *buf = (char *) malloc(sizeof(char) * size); fill_header((IMDheader *)buf, IMD_ENERGIES, 1); memcpy(buf+HEADERSIZE, energies, sizeof(IMDEnergies)); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
int imd_send_fcoords(void *s, int32_t n, const float *coords) { int32_t size = HEADERSIZE+12*n; char *buf = (char*)Utils::malloc(sizeof(char)*size); int rc; fill_header((IMDheader *)buf, IMD_FCOORDS, n); memmove((void *)(buf+HEADERSIZE), (const void *)coords, 12*n); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
int imd_send_energies(void *s, const IMDEnergies *energies) { int32_t size = HEADERSIZE+sizeof(IMDEnergies); char *buf = (char*)Utils::malloc(sizeof(char)*size); int rc; fill_header((IMDheader *)buf, IMD_ENERGIES, 1); memmove((void *)(buf+HEADERSIZE), (const void *)energies, sizeof(IMDEnergies)); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
/* Data methods */ int imd_send_mdcomm(void *s,int32 n,const int32 *indices,const float *forces) { int rc; int32 size = HEADERSIZE+16*n; char *buf = (char *) malloc(sizeof(char) * size); fill_header((IMDheader *)buf, IMD_MDCOMM, n); memcpy(buf+HEADERSIZE, indices, 4*n); memcpy(buf+HEADERSIZE+4*n, forces, 12*n); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
int imd_send_mdcomm(void *s,int32_t n,const int32_t *indices,const float *forces) { int32_t size = HEADERSIZE+16*n; char *buf = (char*)Utils::malloc(sizeof(char)*size); int rc; fill_header((IMDheader *)buf, IMD_MDCOMM, n); memmove((void *)(buf+HEADERSIZE), (const void *)indices, 4*n); memmove((void *)(buf+HEADERSIZE+4*n), (const void *)forces, 12*n); rc = (imd_writen(s, buf, size) != size); free(buf); return rc; }
int VMDCollab::act_on_command(int, Command *cmd) { if (!clientsock) return FALSE; if (eval_in_progress) return FALSE; if (!cmd->has_text(cmdbufstr)) return TRUE; const char *txtcmd = cmdbufstr->text(); int len = strlen(txtcmd); if (len >= VMDCOLLAB_MSGSIZE) { msgWarn << "VMDCollab: command too long: " << txtcmd << sendmsg; return FALSE; } char buf[VMDCOLLAB_MSGSIZE]; strcpy(buf, txtcmd); cmdbufstr->reset(); imd_writen(clientsock, buf, VMDCOLLAB_MSGSIZE); // give the server thread a chance to propagate events before continuing vmd_msleep(1); return TRUE; }
int imd_trate(void *s, int32_t rate) { IMDheader header; fill_header(&header, IMD_TRATE, rate); return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
int imd_handshake(void *s) { IMDheader header; fill_header(&header, IMD_HANDSHAKE, 1); header.length = IMDVERSION; /* Not byteswapped! */ return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
static int imd_go(void *s) { IMDheader header; fill_header(&header, IMD_GO, 0); return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
int imd_kill(void *s) { IMDheader header; fill_header(&header, IMD_KILL, 0); return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
int imd_pause(void *s) { IMDheader header; fill_header(&header, IMD_PAUSE, 0); return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
int imd_disconnect(void *s) { IMDheader header; fill_header(&header, IMD_DISCONNECT, 0); return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE); }
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; }