int CClp_sread_warmstart(CC_SFILE *file, CClp_warmstart **warm) { /* READS warmstart information from the file. */ int i, j, ccount, rcount; char name[5]; CClp_free_warmstart(warm); for (i = 0; i < 4; i++) if (CCutil_sread_char(file, &name[i])) goto fail; name[4] = '\0'; if (strncmp(name, SOLVER, 4)) { print("CClp_sread_warmstart: warmstart for another solver (%s)" " ignored", name); return 0; } if (CCutil_sread_int(file, &ccount)) goto fail; if (CCutil_sread_int(file, &rcount)) goto fail; (*warm) = umalloc(sizeof(CClp_warmstart)); (*warm)->ncols = 0; (*warm)->nrows = 0; (*warm)->cstat = NULL; (*warm)->rstat = NULL; (*warm)->cstat = ucalloc(ccount, sizeof(int)); (*warm)->rstat = ucalloc(rcount, sizeof(int)); for (j = 0; j < ccount; j++) if (CCutil_sread_bits(file, &(((*warm)->cstat)[j]), 2)) goto fail; for (i = 0; i < rcount; i++) if (CCutil_sread_bits(file, &(((*warm)->rstat)[i]), 1)) goto fail; (*warm)->ncols = ccount; (*warm)->nrows = rcount; return 0; fail: CClp_free_warmstart(warm); return 1; }
static int serve_file (CC_SFILE *f, char *probfname, int silent) { char request; char probbuf[1024]; int id; int rval; rval = CCutil_sread_char (f, &request); if (rval) { fprintf (stderr, "CCutil_sread_char failed\n"); return rval; } rval = CCutil_sread_string (f, probbuf, sizeof (probbuf)); if (rval) { fprintf (stderr, "CCutil_sread_string failed\n"); return rval; } rval = CCutil_sread_int (f, &id); if (rval) { fprintf (stderr, "CCutil_sread_int failed\n"); return rval; } if (strcmp (probfname, probbuf)) { fprintf (stderr, "ERROR - serving %s, request %s\n", probfname, probbuf); return rval; } switch (request) { case CCtsp_Pread: rval = serve_read (f, probfname, id, silent); if (rval) { fprintf (stderr, "serve_read failed\n"); return rval; } break; case CCtsp_Pwrite: rval = serve_write (f, probfname, id, silent); if (rval) { fprintf (stderr, "serve_write failed\n"); return rval; } break; case CCtsp_Pdelete: rval = serve_delete (probname, id); if (rval) { fprintf (stderr, "serve_delete failed\n"); return rval; } break; default: fprintf (stderr, "Invalid request %c\n", request); return 1; } return 0; }
static int serve_write (CC_SFILE *f, char *probfname, int id, int silent) { CCtsp_PROB_FILE *local = (CCtsp_PROB_FILE *) NULL; CCtsp_PROB_FILE *remote = (CCtsp_PROB_FILE *) NULL; char request; int rval; if (debug) { printf ("serving write %s %d\n", probfname, id); fflush (stdout); } local = CCtsp_prob_write (probfname, id); if (local == (CCtsp_PROB_FILE *) NULL) { fprintf (stderr, "CCtsp_prob_write failed\n"); rval = 1; goto CLEANUP; } remote = CCtsp_prob_server (f); if (remote == (CCtsp_PROB_FILE *) NULL) { fprintf (stderr, "CCtsp_prob_server failed\n"); rval = 1; goto CLEANUP; } for (;;) { rval = CCutil_sread_char (f, &request); if (rval) { fprintf (stderr, "CCutil_sread_char failed\n"); goto CLEANUP; } if (debug) { printf ("Request %c...", request); fflush (stdout); } if (request == CCtsp_Pexit) goto CLEANUP; rval = CCtsp_prob_copy_section (remote, local, request, silent); if (rval) { fprintf (stderr, "CCtsp_prob_copy_section failed\n"); goto CLEANUP; } if (debug) { printf ("done\n"); fflush (stdout); } } CLEANUP: if (debug) { printf ("exit\n"); fflush (stdout); } rval |= CCtsp_prob_wclose (local); if (rval) { fprintf (stderr, "CCtsp_prob_wclose failed\n"); } rval |= CCtsp_prob_rclose (remote); if (rval) { fprintf (stderr, "CCtsp_prob_rclose failed\n"); } return rval; }