1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
|
/* $Id: skills.c,v 1.84 2004/11/23 19:45:13 graziano Exp $ */
#include "config_nws.h"
#include <stdlib.h>
#include "diagnostic.h"
#include "experiments.h"
#include "host_protocol.h"
#include "skills.h"
#include "osutil.h"
#include "strutil.h"
#include "connect_exp.h"
#include "disk.h"
#include "hybridCpu.h"
#include "memory.h"
#include "tcp_bw_exp.h"
#include "fstests.h"
#include "availtest.h"
#include "starttest.h"
#include "memorySpeed.h"
static int wouldYouFork = 1;
static void *lock = NULL; /* local lock */
/* these are all the options we understand */
static const char* OPTION_FORMATS = "buffer:0_to_1_int\tmessage:0_to_1_int\tnice:0_to_10_int\tpath:1_to_10_string\ttype:0_to_1_string\tsize:0_to_1_int\ttarget:1_to_100_sensors\tfstype:0_to_1_string\tfsblock:0_to_1_int\tfssize:0_to_1_int\tfsbufmode:0_to_1_int\tfstmpdir:0_to_1_string\tfsphysmem:0_to_1_int\tmode:0_to_1_string\tloops:0_to_1_int";
/*
* this is a single resource: a resource needs to have a label (what we
* are measuring) a name and a enum type we use internally (defined in
* the header file) from NWS to refer to this resource
*/
typedef struct {
const char *label;
const char *name;
const MeasuredResources skillResource;
} NwsResource;
static const NwsResource myResources[RESOURCE_COUNT] = {
{"CPU Fraction", "availableCpu", availableCpu},
{"CPU Fraction", "currentCpu", currentCpu},
{"Megabytes", "freeDisk", freeDisk,},
{"Megabytes", "freeMemory", freeMemory,},
{"Milliseconds", "connectTimeTcp", connectTimeTcp,},
{"Megabits/second", "bandwidthTcp", bandwidthTcp,},
{"Milliseconds", "latencyTcp", latencyTcp},
{"Megabytes/second", "fsreadSpeed", fsreadSpeed},
{"Megabytes/second", "fswriteSpeed", fswriteSpeed},
{"Seconds", "upTime", upTime},
{"Seconds", "startTime", startTime},
{"Megabytes/second", "memorySpeed", memorySpeed}
};
/* this is needed because the different controls have default options
* that need to be added to the skill options */
typedef struct {
int control;
const char *options;
} Controls;
/*
* the target option is the target for the network measurement, and the
* childToParent is the socket to use (usually a pipe) to communicate
* to the parent the data for the automatic timeout discovery. It's used
* internally. */
static const Controls controlOptions[ALL_CONTROLS] = {
{PERIODIC_CONTROL, ""},
{CLIQUE_CONTROL, "target,childToParent"}
};
/* typedef for the function that monitors the skill availability */
typedef int (*MonitorIsAvailable)(const char *options);
typedef void (*MonitorUseSkill)(const char *options, int *length, SkillResult **results);
/*
* this is a single skill: a skill has a name, is valid only for a
* specific control (so far we have only periodic and clique), has a
* list of options it supports and possibly some default values for them,
* and a list of the resources it measures.
*
* MonitorIsAvailable is the function to call to check if the particular
* skill can be exercise with the options: the function should returns 1
* on success, 0 otherwhise. NULL assumes an always true case.
*
* MonitorUseSkill is the workhorse for the experiment: it does all the
* work and will call AppendResults to add the results. If you are
* writing a clique-enable skill, you can access the list of targets of
* the clique automatically: it's been added for you. A stub for
* MonitorUseSkill is here:
*
* const char c*;
* char option[63+1], opts[255+1];
* double res;
* char *targets;
*
* get the default option (pippo) with a default value (ciao)
* myCommonOpts = GetOptionValue(options, "pippo", "ciao");
*
* loop through options that can be specified multpile times
* targets = GetOptionValue(options, "target", "");
* for (c = targets; GETTOK(option, c, ",", &c);) {
* snprintf(opts, sizeof(opts), "pippo:%s,target:%s",
* myCommonOpts, option);
* if (myExperiment(...,&res)) {
* AppendResult(skill, opts, 1, res, lenght,results);
* } else {
* AppendResult(skill, opts, 0, 0, lenght,results);
* }
* }
* free(myCommonOpts);
* free(targets);
*
*
*
*/
#define MAX_RESOURCES_PER_SKILL 2
typedef struct {
const char *name;
const int control;
const char *options;
const char *optionsDefault;
const MeasuredResources resources[MAX_RESOURCES_PER_SKILL];
const int resourcesCount;
MonitorIsAvailable skillIsAvailable;
MonitorUseSkill useSkill;
} NwsSkill;
static const NwsSkill mySkills[SKILL_COUNT] = {
{"cpuMonitor", PERIODIC_CONTROL, "nice", "0", {availableCpu, currentCpu}, 2, &HybridCpuMonitorAvailable, &HybridCpuUseSkill},
{"diskMonitor", PERIODIC_CONTROL, "path", NULL, {freeDisk}, 1, &DiskFreeAvailable, &DiskFreeUseSkill},
{"memoryMonitor", PERIODIC_CONTROL, "type", "passive", {freeMemory}, 1, &MemoryMonitorAvailable, &MemoryUseSkill},
{"tcpConnectMonitor", CLIQUE_CONTROL, "", NULL, {connectTimeTcp}, 1, &TcpConnectAvailable, &TcpConnectUseSkill},
{"tcpMessageMonitor", CLIQUE_CONTROL, "buffer,message,size", "32,16,256", {bandwidthTcp, latencyTcp}, 2, &TcpLtBwAvailable, &TcpLtBwUseSkill},
{"filesystemMonitor", PERIODIC_CONTROL, "fstype,fsblock,fssize,path,fsbufmode,fstmpdir,fsphysmem", NULL, {fsreadSpeed, fswriteSpeed}, 2, &FileSystemMonitorAvailable, &FileSystemUseSkill},
{"availabilityMonitor", PERIODIC_CONTROL, "", NULL, {upTime}, 1, &AvailabilityMonitorAvailable, &AvailabilityUseSkill},
{"startMonitor", PERIODIC_CONTROL, "", NULL, {startTime}, 1, &StartAvailable, &StartUseSkill},
{"memorySpeedMonitor", PERIODIC_CONTROL, "size,mode,loops", "8192,random,1", {memorySpeed}, 1, &MemorySpeedAvailable, &MemorySpeedUseSkill}
};
/* Adds a new result with the given fields to lastResults. */
void
AppendResult( MeasuredResources resource,
const char *options,
int succeeded,
double measurement,
int *howMany,
SkillResult **results) {
SkillResult *tmp;
/* sanity check */
if (results == NULL|| (void *)howMany == NULL) {
ERROR("AppendResult: NULL parameters\n");
return;
}
if (resource < 0 || resource > RESOURCE_COUNT) {
ERROR1("AppendResult: unknown resource %d\n", resource);
return;
}
/* jsut be sure we start right */
if (*howMany == 0) {
tmp = NULL;
} else {
tmp = *results;
}
/* make room for the pointer */
tmp = REALLOC(tmp, (*howMany + 1) * sizeof(SkillResult));
if (results == NULL) {
ABORT("AppendResult: out of memory\n");
}
tmp[*howMany].resource = resource;
tmp[*howMany].options = strdup(options);
if (tmp[*howMany].options == NULL) {
ABORT("AppendResult: out of memory\n");
}
tmp[*howMany].succeeded = succeeded;
if (succeeded) {
tmp[*howMany].measurement = measurement;
} else {
tmp[*howMany].measurement = 0.0;
}
/* one more result */
*howMany = *howMany + 1;
*results = tmp;
}
void
FreeSkillResults( int howMany,
SkillResult **results) {
int i;
SkillResult *tmp;
tmp = *results;
for(i = 0; i < howMany; i++) {
free(tmp[i].options);
}
FREE(tmp);
*results = NULL;
}
/* A message listener (see messages.h) for the skills module. */
static void
HandleSkillMessage(Socket *sd,
MessageHeader header) {
int ret, i, howMany, Ichild;
KnownSkills skill;
char *tmp = NULL, *name;
const char *resName;
DataDescriptor descriptor = SIMPLE_DATA(CHAR_TYPE, 0);
DataDescriptor doubleDescriptor = SIMPLE_DATA(DOUBLE_TYPE, 1);
SkillResult *results = NULL;
ret = Ichild = 0;
switch (header.message) {
case SKILL_EXPERIMENT:
if (wouldYouFork) {
pid_t pid;
if(!CreateLocalChild(&pid, NULL, NULL)) {
ERROR("HandleSkillMessage: fork failed.\n");
return;
}
if(pid > 0) {
/* Parent process. */
PassSocket(sd, pid);
return;
}
/* child process */
Ichild = 1;
}
/* get the options */
descriptor.repetitions = header.dataSize;
tmp = (char *)MALLOC(descriptor.repetitions + 1);
if (tmp == NULL) {
ERROR("HandleSkillMessage: out of memory\n");
break;
}
if (!RecvData(*sd, tmp, &descriptor, 1, -1)) {
ERROR("HandleSkillMessage: receive failed\n");
break;
}
tmp[header.dataSize] = '\0';
/* search for the skill */
name = NwsAttributeValue_r(FindNwsAttribute(tmp, "skillName"));
if (name == NULL) {
ERROR("HandleSkillMessage: no skillName attribute\n");
break;
}
for (i = 0; i < SKILL_COUNT; i++) {
skill = (KnownSkills) i;
if (strcmp(name, SkillName(skill)) == 0) {
break;
}
}
FREE(name);
if (i >= SKILL_COUNT) {
ERROR("HandleSkillMessage: no known skill\n");
break;
}
UseSkill(skill, tmp, -1, &results, &howMany);
for (i = 0; i < howMany; i++) {
if (!results[i].succeeded) {
WARN1("HandleSkillMessage: skill %s failed\n", SkillName(skill));
continue;
}
/* we got at least one result */
ret = 1;
/* let's send the result back */
resName = ResourceName(results[i].resource);
descriptor.repetitions = strlen(resName);
if (!SendMessageAndDatas(*sd,
SKILL_RESULT,
resName,
&descriptor,
1,
&results[i].measurement,
&doubleDescriptor,
1,
-1)) {
ERROR1("HandleSkillMessage: failed to send SKILL_RESULT on %d\n", *sd);
break;
}
}
/* free the memory */
FreeSkillResults(howMany, &results);
if (ret != 0) {
SendMessage(*sd, SKILL_FAILED, -1);
}
break;
}
FREE(tmp);
DROP_SOCKET(sd);
if (Ichild) {
exit(!ret);
}
}
char *
GetOptionValue(const char *options,
const char *name,
const char *defaultValue) {
const char *c;
size_t nameLen = strlen(name);
char *returnValue;
const char *value;
const char *valueEnd;
size_t valuesLen = 0;
/* sanity check */
if (options == NULL || name == NULL) {
valuesLen = 0;
} else for (c = strstr(options, name); c; c = strstr(c + 1, name)) {
/* Find the total length of all #name# option values in
* #options#. */
if ((*(c + nameLen) != ':') || ((c != options) && (*(c - 1) != '\t')))
continue; /* Bogus match. */
value = c + nameLen + 1;
valueEnd = strchr(value, '\t');
valuesLen += (valueEnd == NULL) ? strlen(value) : (valueEnd - value);
valuesLen++;
}
if (valuesLen == 0) {
if (defaultValue != NULL) {
returnValue = strdup(defaultValue);
if (returnValue == NULL) {
ABORT("GetOptionValue: out of memory\n");
}
} else {
returnValue = NULL;
}
return returnValue;
}
/* Merge all #name# option values into a single, comma-delimited
* list. */
returnValue = (char *)MALLOC(valuesLen);
memset(returnValue, 0, valuesLen);
for(c = strstr(options, name); c != NULL; c = strstr(c + 1, name)) {
if ((*(c + nameLen) != ':') || ((c != options) && (*(c - 1) != '\t')))
continue; /* Bogus match. */
value = c + nameLen + 1;
valueEnd = strchr(value, '\t');
if (*returnValue != '\0') {
strcat(returnValue, ",");
}
strncat(returnValue, value, (valueEnd == NULL) ? strlen(value) : (valueEnd - value));
}
return returnValue;
}
const char *
ResourceLabel(MeasuredResources resource) {
if (resource < 0 || resource >= RESOURCE_COUNT) {
return NULL;
}
return myResources[resource].label;
}
const char *
ResourceName(MeasuredResources resource) {
if (resource < 0 || resource >= RESOURCE_COUNT) {
return NULL;
}
return myResources[resource].name;
}
int
SkillAvailableForControl( KnownSkills skill,
const char *options,
int control) {
int ret;
/* sanity check */
if (skill < 0 || skill >= SKILL_COUNT || control < 0 || control >= SKILL_COUNT) {
WARN("SkillAvailableForControl: wrong parameters\n");
return 0;
}
/* we check right away if the skill is right for the control */
if (control != ALL_CONTROLS && control != mySkills[skill].control) {
return 0;
}
ret = 1;
if (mySkills[skill].skillIsAvailable != NULL) {
ret = mySkills[skill].skillIsAvailable(options);
}
return ret;
}
const char *
SkillName(KnownSkills skill) {
if (skill < 0 || skill >= SKILL_COUNT) {
return NULL;
}
return mySkills[skill].name;
}
const char *
SkillSupportedOptions( const KnownSkills skill) {
/* sanity check */
if (skill < 0 || skill > SKILL_COUNT) {
return NULL;
}
return (mySkills[skill].options);
}
char *
SkillOptionDefault( const KnownSkills skill,
const char *option) {
const char *c, *v;
char name[63+1], value[63+1], *ret;
/* sanity check */
if (option == NULL || skill < 0 || skill > SKILL_COUNT) {
return NULL;
}
/* let's find if we know the option for the skill, and wich
* position it has */
ret = NULL;
v = mySkills[skill].optionsDefault;
c = mySkills[skill].options;
while (GETTOK(name, c, ",", &c) && GETTOK(value, v, ",", &v)) {
if (strcmp(option, name) == 0) {
ret = strdup(value);
if (ret == NULL) {
ERROR("SkillOptionDefault: out of memory\n");
}
break;
}
}
return ret;
}
void
SkillOptions(KnownSkills skill,
const char *options,
char *toWhere,
int len) {
const char *c;
char option[63 + 1];
char *value;
int i;
*toWhere = '\0';
GetNWSLock(&lock);
i = 0;
value = NULL;
for(c = mySkills[skill].options; GETTOK(option, c, ",", &c); ) {
value = GetOptionValue(options, option, NULL);
if (value != NULL) {
if (len < i + strlen(option) + strlen(value) + 2) {
ERROR("SkillOptions: option too long\n");
FREE(value);
break;
}
if(*toWhere != '\0') {
strcat(toWhere, "\t");
}
strcat(toWhere, option);
strcat(toWhere, ":");
strcat(toWhere, value);
}
FREE(value);
}
ReleaseNWSLock(&lock);
FREE(value);
}
char *
SkillOptionFormat( const char *option) {
char *c, *value;
value = NULL;
c = FindNwsAttribute((Object)OPTION_FORMATS, option);
if (c != NULL) {
value = NwsAttributeValue_r(c);
}
return value;
}
int
SkillResources(KnownSkills skill,
const MeasuredResources **resources,
int *length) {
/* sanity check */
if (skill < 0 || skill > SKILL_COUNT) {
INFO("SkillResources: wrong skill\n");
return 0;
}
if (length == NULL) {
INFO("SkillResources: NULL parameter\n");
return 0;
}
if ((void *)(resources) != NULL) {
*resources = mySkills[skill].resources;
}
*length = mySkills[skill].resourcesCount;
return 1;
}
int
SkillsInit( const char *opts) {
int i;
KnownSkills skill;
Object reg;
char options[255], *tmp;
static int initialized = 0;
/* initialize only once */
GetNWSLock(&lock);
if (initialized) {
ReleaseNWSLock(&lock);
ERROR("SkillsInit: you can initialize only once!\n");
return 0;
}
initialized = 1;
ReleaseNWSLock(&lock);
options[0] = '\0';
for (i = 0; i < SKILL_COUNT; i++) {
skill = (KnownSkills) i;
if (SkillAvailable(skill, opts)) {
/* let's write a skill object to be registerd */
reg = NewObject();
/* name is host.skill format */
snprintf(options, sizeof(options), "%s.%s", EstablishedRegistration(), mySkills[i].name);
AddNwsAttribute(®, "name", options);
AddNwsAttribute(®, "objectclass", "nwsSkill");
AddNwsAttribute(®, "host", EstablishedRegistration());
AddNwsAttribute(®, "option", mySkills[i].options);
AddNwsAttribute(®, "skillName", mySkills[i].name);
SkillOptions(skill, OPTION_FORMATS, options, 255);
AddOptionToObject(®, options);
RegisterObject(reg);
FreeObject(®);
}
}
RegisterListener(SKILL_EXPERIMENT, "SKILL_EXPERIMENT", &HandleSkillMessage);
/* remember if we need to fork */
tmp = GetOptionValue(opts, "fork", NULL);
if (tmp == NULL || strncmp(tmp, "yes", (strlen(tmp) > 3 ? 3 : strlen(tmp)))) {
wouldYouFork = 1;
} else {
wouldYouFork = 0;
}
FREE(tmp);
return 1;
}
void
UseSkill( KnownSkills skill,
const char *options,
double timeOut,
SkillResult **results,
int *length) {
const char *c;
char *opts,
option[255+1],
*n;
int i;
*length = 0; /* not yet data */
/* let's check if the skill is valid */
if (skill < 0 || skill > SKILL_COUNT) {
ERROR("UseSkill: unknown skill\n");
return;
}
opts = NewObject();
if (opts == NULL) {
ERROR("UseSkill: out of memory\n");
return;
}
/* add timeout and defaults options for the skill */
snprintf(option, sizeof(option), "%.2f", timeOut);
AddNwsAttribute(&opts, "timeout", option);
/* add the options of the particular skill */
for (c = mySkills[skill].options; GETTOK(option, c, ",", &c);) {
/* the passed in parameters gets precedence */
n = GetOptionValue(options, option, NULL);
if (n != NULL) {
AddNwsAttribute(&opts, option, n);
FREE(n);
continue;
}
/* use the default if exists */
n = SkillOptionDefault(skill, option);
if (n != NULL) {
AddNwsAttribute(&opts, option, n);
FREE(n);
}
}
/* add the option coming from the control */
for (c = NULL, i = 0; i < ALL_CONTROLS; i++) {
if (mySkills[skill].control == controlOptions[i].control) {
c = controlOptions[i].options;
break;
}
}
while (GETTOK(option, c, ",", &c)) {
/* the passed in parameters gets precedence */
n = GetOptionValue(options, option, NULL);
if (n != NULL) {
AddNwsAttribute(&opts, option, n);
FREE(n);
continue;
}
/* use the default if exists */
n = SkillOptionDefault(skill, option);
if (n != NULL) {
AddNwsAttribute(&opts, option, n);
FREE(n);
}
}
/* let's check if we can run the skill and run it in case */
if (mySkills[skill].skillIsAvailable && mySkills[skill].useSkill) {
if (mySkills[skill].skillIsAvailable(opts)) {
mySkills[skill].useSkill(opts, length, results);
} else {
INFO2("UseSkill: skill %s not available (options %s)\n", mySkills[skill].name, opts);
}
}
FreeObject(&opts);
}
int
RemoteUseSkill( struct host_cookie *cookie,
char *opts,
double tout,
char ***resources,
double *d,
int *howMany) {
size_t dataSize;
DataDescriptor objDes = SIMPLE_DATA(CHAR_TYPE, 0);
DataDescriptor meas = SIMPLE_DATA(DOUBLE_TYPE, 1);
char *name;
int len, i;
/* sanity check */
if (cookie == NULL || opts == NULL || resources == NULL) {
ERROR("RemoteUseSkill: NULL parameter(s)\n");
return 0;
}
/* let's see how many resources are monitored by this skill */
name = NwsAttributeValue_r(FindNwsAttribute(opts, "skillName"));
if (name == NULL) {
ERROR("RemoteUseSkill: missing skillName!\n");
return 0;
}
for (dataSize = 0; dataSize < SKILL_COUNT; dataSize++) {
if (strcmp(name, SkillName((KnownSkills)dataSize)) == 0) {
break;
}
}
free(name);
if (dataSize >= SKILL_COUNT) {
ERROR("RemoteUseSkill: unknown skillName\n");
return 0;
}
/* let's see how many resources we handle */
SkillResources((KnownSkills)dataSize, NULL, &len);
/* let's send the skill/options blob */
objDes.repetitions = strlen(opts);
/* let's try to talk with the host */
if (!ConnectToHost(cookie, NULL) || !SendMessageAndData(cookie->sd, SKILL_EXPERIMENT, opts, &objDes, 1, tout)) {
ERROR2("RemoteUseSkill: failed to send SKILL_EXPERIMENT to %s:%d\n", cookie->name, cookie->port);
return 0;
}
/* makes room for the resources name */
*resources = (char **)MALLOC(sizeof(char*) * len);
if (*resources == NULL) {
ERROR("RemoteUseSkill: out of memory\n");
return 0;
}
for (i = 0; i < len; i++) {
if (!RecvMessage(cookie->sd, SKILL_RESULT, &dataSize, tout)) {
ERROR("RemoteUseSkill: failed to receive data\n");
return 0;
}
/* we receive the descriptions first: the length is
* dataSize - the size of a double ... */
objDes.repetitions = dataSize - HomogenousDataSize(DOUBLE_TYPE, 1, NETWORK_FORMAT);
(*resources)[i] = (char *)MALLOC(objDes.repetitions + 1);
if ((*resources)[i] == NULL) {
ERROR("RemoteUseSkill: out of memory\n");
return 0;
}
if (!RecvData(cookie->sd, (*resources)[i], &objDes, 1, tout)) {
ERROR("RemoteUseSkill: failed to receive data\n");
return 0;
}
(*resources)[i][objDes.repetitions] = '\0';
/* now receive the measurement */
if (!RecvData(cookie->sd, &d[i], &meas, 1, tout)) {
ERROR("RemoteUseSkill: failed to receive data\n");
return 0;
}
}
*howMany = i;
return 1;
}
|