/** Read the domainID of the subExp1 from the mgrExp1 over the * vChan. * This routine will block until the domainID is retrieved from * the mgr. * return - the domainID. On any failure exit(1) is called. **/ int readSubExp1DomainID( xentoollog_logger * xc_logger, struct libxenvchan * ctrl) { char buf[DOMAIN_ID_CHAR_LEN + 1]; int size = DOMAIN_ID_CHAR_LEN; char * invalidChar; int domainID; // Read the subExp1 domain ID from mgrExp1 vchan client. // The domainID has to be right justified for the following error // checking to work. So the domainID number must be preceeded with // white space or '0's. size = libxenvchan_recv(ctrl, buf, size); // Was there a system error? if (size < 0) { // There was a significant error. Abort. fprintf(stderr, "libxenvchan_read return=%d.\n", size); perror("readSubDomain: read failed for mgrExp1."); libxenvchan_close(ctrl); exit(1); } // Did we get all of the characters of the domainID number string? if (size != DOMAIN_ID_CHAR_LEN) { fprintf(stderr, "readSubDomain: We expected to read %d characters for the" "subExp1 domain ID but got %d from mgrExp1\n", DOMAIN_ID_CHAR_LEN, size); libxenvchan_close(ctrl); exit(1); } buf[DOMAIN_ID_CHAR_LEN] = 0; // put null at end of string so we have a valid C string. // Convert the string to an integer. domainID = strtol(buf, &invalidChar, 10); if ( *invalidChar != '\0' ) { fprintf(stderr, "readSubDomain: There was an invalid character in the domainID. The invalid portion of the domainID is '%s'.\n", invalidChar); libxenvchan_close(ctrl); exit(1); } return domainID; }
//#################################################################### int readClientMessage(xentoollog_logger * xc_logger, struct libxenvchan * ctrl, char * msg, int * sz) { int result = 0; int size; //char * invalidChar; //char * buf = (char *) malloc (sizeof(char) * (*sz)); //int i = 0; /* fprintf(stdout,"size:%d\n", *sz); */ size = libxenvchan_recv(ctrl, msg, *sz); /* fprintf(stdout,"Receive strlen: %d\n",size); fprintf(stdout,"%s",msg); fprintf(stdout,"HEXDUMP\n"); for (i = 0; i < size; i++){ fprintf(stdout,"%02x ",msg[i]); } fprintf(stdout,"\n"); */ *sz = size; // Was there a system error? if (size < 0) { // There was a significant error. Abort. fprintf(stderr, "libxenvchan_recv return=%d.\n", size); perror("serverExp1: read failed for clientExp1."); exit(1); } /* // Did we get all of the characters in the message. if (size != EXP1_MSG_LEN) { fprintf(stderr, "serverExp1: We expected to read %d characters for the" "clientExp1 but got %d from clientExp1\n", EXP1_MSG_LEN, size); exit(1); } */ // msg[size] = 0; // put null at end of string so we have a valid C string. // Convert the string to an integer. return result; }
int libvchan_recv(libvchan_t *ctrl, void *data, size_t size) { return libxenvchan_recv(ctrl->xenvchan, (char*)data, size); }