int server(int port) { int handle;//, port=SERV_PORT; int s, len; char msg[256], *dummy; handle = dsm_server_open(SOCK_STREAM, &port, FALSE, NULL, 0); while (1) { // printf("%d\n", s); s = dsm_server_accept(handle, SOCK_STREAM, port, FALSE, NULL, &len, &dummy, 0); len = dsm_read(s, SOCK_STREAM, msg, 256, NULL); printf("%s\n", msg); dsm_close(s); } dsm_close(handle); }
void vv2monitor(char *ip) { #if __powerpc__ int d; char dsmhost[NAMELEN]; int originaldd, original; short lock1,lock2; struct sigaction action, oldAction; continueVVMlogging = 1; d = dsm_open(); if (d) { dsm_error_message(d,"dsm_open"); return; } original = whichVVM; originaldd = whichVVMdd; strcpy(dsmhost,"hal9000"); /* install control-c handler */ action.sa_flags = 0; action.sa_handler = cleanupControlCvvm; sigemptyset(&action.sa_mask); if (sigaction(SIGINT, &action, &oldAction) != 0) { STRERROR("sigaction:"); } WARN("Control-C handler installed. Hit Cntrl-C to exit the DSM logging mode.\n"); do { whichVVM = 1; whichVVMdd = vector_voltmeter.dd; lock1 = vectorQueryLock(); whichVVM = 2; whichVVMdd = vector_voltmeter2.dd; lock2 = vectorQueryLock(); d = dsm_write(dsmhost,"DSM_VVM1_LOCK_STATUS_S",&lock1); if (d) { dsm_error_message(d,"dsm_write(DSM_VVM1_LOCK_STATUS_S)"); } d=dsm_write(dsmhost,"DSM_VVM2_LOCK_STATUS_S",&lock2); if (d) { dsm_error_message(d,"dsm_write(DSM_VVM2_LOCK_STATUS_S)"); } sleep(5); } while (continueVVMlogging == 1); d = dsm_close(); WARN("restoring previous control-c handler (if any)\n"); if (sigaction(SIGINT, &oldAction, &action) != 0) { STRERROR("sigaction:"); } whichVVM = original; whichVVMdd = originaldd; #else WARN("This feature is not supported on linux\n"); #endif }
int client(char *msg, char *dsthost, int dstport) { // char msg[256]; int s; // int dstport, char *dsthost; /* compose message, determine destination host/port */ // memset(msg, 0, sizeof(msg)); // printf("%s\n", msg); s = dsm_client_open(SOCK_STREAM, dstport, FALSE, dsthost, NULL); dsm_write(s, SOCK_STREAM, msg, strlen(msg) + 1, NULL); // printf("%d\n", s); dsm_close(s); }
main(int argc, char *argv[]) { int i; int ant=ARRAY_DISPLAY; /* start up on the 'a' page */ int cycle = FALSE; int delay = 1; #ifdef LINUX int spinCount = 0; #endif char *outputFile = NULL; struct utsname unamebuf; int rms; struct sigaction action, old_action; int sigactionInt; int icount=0; int firstUpdate = TRUE; int rc; int startDay; int message = 0; int ignoreFlag; struct stat messageStat, oldMessageStat; /* The following variables are for the default Tilt flag read from the pointing model files */ FILE *fpMountModel; int itilt; char mountModelFile[100],line[BUFSIZ]; char pointingParameter[20],opticalValue[20],radioValue[20]; /* signal handler for control C */ action.sa_flags=0; sigemptyset(&action.sa_mask); action.sa_handler = handlerForSIGINT; sigactionInt = sigaction(SIGINT,&action, &old_action); uname(&unamebuf); #ifndef LINUX if(strcmp(unamebuf.nodename,"hal9000")) { printf("This program will run only on hal9000. Bye.\n"); exit(-1); } #endif #if DEBUG fprintf(stderr,"Finished opening RM\n"); #endif i = 0; #if 0 while (antlist[i] != RM_ANT_LIST_END) { antsAvailable[antlist[i]] = 1; deadAntennas[antlist[i]] = 0; i++; } #endif #if 0 defaultTiltFlag[0]=0; for(itilt=1;itilt<=8;itilt++) { defaultTiltFlag[itilt]=0; sprintf(mountModelFile,"/otherInstances/acc/%d/configFiles/pointingModel",itilt); fpMountModel=fopen(mountModelFile,"r"); if(fpMountModel!=NULL) { while(fgets(line,sizeof(line),fpMountModel) != NULL) { line[strlen(line)-1]='\0'; if(line[0]!='#') { sscanf(line,"%s %s %s", pointingParameter, opticalValue, radioValue); if(!strcmp(pointingParameter,"TiltFlag")) { defaultTiltFlag[itilt]=(int)atof(radioValue); } } } } fclose(fpMountModel); } #endif rms = dsm_open(); if(rms != DSM_SUCCESS) { dsm_error_message(rms, "dsm_open"); exit(-1); } #if DEBUG fprintf(stderr,"Finished opening DSM\n"); #endif /* * This is to get the user input as a single unbuffered char and * zero-wait */ ioctl(0, TCGETA, &tio); tin = tio; tin.c_lflag &= ~ECHO; tin.c_lflag &= ~ICANON; tin.c_cc[VMIN] = 0; tin.c_cc[VTIME] = 0; ioctl(0, TCSETA, &tin); stat(MESSAGES_LOG, &oldMessageStat); #if DEBUG fprintf(stderr,"1. Finished stat() on messages file\n"); #endif /* starting infinite loop */ /* begin while loop every 1 second */ initialize(); while (1) { time_t lastKeystrokeTime, curTime; #ifndef LINUX yield(); #endif ioctl(0, TCSETA,&tin); icount++; lastUser = user; user = getchar(); switch (user) { case 'q': move(LINES-1,0); printw("Bye.\n"); refresh(); ioctl(0, TCSETA, &tio); goto80width(); printf("\n"); rms = dsm_close(); if(rms != DSM_SUCCESS) { dsm_error_message(rms, "dsm_close"); exit(-1); } exit(0); break; } /* end of switch */ ant=1; antDisplay(ant, icount); #ifndef LINUX sleep(delay); #else usleep(delay*500000); spinCount++; if ((spinCount % 2) && ((icount % 30) > 1)) icount--; #endif } /* this is the big while loop */ ioctl(0, TCSETA, &tio); } /* end of main Loop */