/* Record the host after connection is established*/ static void host_added(int ihost, int sock){ htime[ihost]=myclockd(); proc_remove_all(ihost);/*remove all entries. */ LOCK(mhost); nhostup++; hsock[ihost]=sock; FD_SET(sock, &active_fd_set); UNLOCK(mhost); add_host_wrap(-1);//wakes up listen_host(). info("connected to %s\n", hosts[ihost]); gdk_threads_add_idle(host_up, GINT_TO_POINTER(ihost)); }
/*remove the host upon disconnection*/ static void host_removed(int sock){ int ihost=host_from_sock(sock); if(ihost==-1) return; close(sock); LOCK(mhost); nhostup--; hsock[ihost]=-1; FD_CLR(sock, &active_fd_set); UNLOCK(mhost); add_host_wrap(-1); gdk_threads_add_idle(host_down, GINT_TO_POINTER(ihost)); info("disconnected from %s\n", hosts[ihost]); }
/** called by monitor to talk to scheduler. */ int scheduler_cmd(int host,int pid, int command){ if(command==CMD_DISPLAY){ return scheduler_display(host, pid); }else{ int sock=hsock[host]; if(sock==-1){ add_host_wrap(host); sleep(1); } if(sock==-1) return 1; int cmd[2]; cmd[0]=command; cmd[1]=pid;/*pid */ int ans=stwriteintarr(sock,cmd,2); if(ans){/*communicated failed.*/ close(sock); } return ans; } }