X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Frsmain.c;h=67d338b502d961dc3279874cacb1344ab173e4ba;hp=437a13d35d837f552b229f100374bc5fd9699075;hb=efd685a5df610ffefc545a41be67e2e0d4b69c7c;hpb=30375dc1932be83a48fca8122e81b845c4b0ecc2 diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index 437a13d..67d338b 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -1,4 +1,29 @@ -/**/ +/* + * Route searcher - command line parsing and result printing + */ +/* + * This is part of the YARRG website, a tool for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ #include "rscommon.h" @@ -31,6 +56,8 @@ int main(int argc, const char **argv) { int i, ap; int granui; const char *database=0; + const char *concur_base=0, *concur_rhs=0; + int concur_lim=-1; #ifndef debug_flags debug_flags= ~( dbg_sql2 ); @@ -41,6 +68,10 @@ int main(int argc, const char **argv) { if (arg[0] != '-') break; if (!strcmp(arg,"-d")) { database= *++argv; + } else if (!strcmp(arg,"-C")) { + concur_base= *++argv; + concur_rhs= *++argv; + concur_lim= atoi(*++argv); } else if (!strcmp(arg,"-g")) { granus= atoi(*++argv); assert(granus>=1 && granus<=GRANUS); @@ -92,6 +123,28 @@ int main(int argc, const char **argv) { min_trade_maxprofit= atoi(*argv++); + if (concur_base) { + for (i=0; i= 0); + struct flock fl; + memset(&fl,0,sizeof(fl)); + fl.l_type= F_WRLCK; + r= fcntl(concfd, F_SETLK, &fl); + free(concfn); + if (!r) goto concur_ok; + sysassert( errno == EWOULDBLOCK ); + close(concfd); + } + fprintf(output,"@@@ concurrency limit exceeded (%d)\n", concur_lim); + exit(0); + + concur_ok: + /* deliberately leak concfd */ + fprintf(output,"concurrency slot %d\n", i); + } + setup_sql(database); setup_value(); setup_search();