1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2011 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/select.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
33 #include <yaz/options.h>
35 #include <yaz/xmalloc.h>
44 static int run(FILE *inf, struct addrinfo *res)
46 long long tv_sec0 = 0;
47 long long tv_usec0 = 0;
63 for (i = 0; c != '\n' && i < (sizeof(req)-2); i++)
69 r = sscanf(req, "%lld %lld %lld %d", &tv_sec1, &tv_usec1, &id, &sz);
72 fprintf(stderr, "bad line %s\n", req);
79 spec.tv_sec = tv_sec1 - tv_sec0;
80 if (tv_usec0 > tv_usec1)
82 spec.tv_usec = 1000000 + tv_usec1 - tv_usec0;
86 spec.tv_usec = tv_usec1 - tv_usec0;
88 select(0, 0, 0, 0, &spec);
92 for (conp = &cons; *conp; conp = &(*conp)->next)
93 if ((*conp)->id == id)
99 for (rp = res; rp; rp = rp->ai_next)
101 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
107 fprintf(stderr, "socket: cannot create\n");
110 r = connect(fd, rp->ai_addr, rp->ai_addrlen);
113 fprintf(stderr, "socket: cannot connect\n");
117 *conp = xmalloc(sizeof(**conp));
124 struct con *c = *conp;
137 size_t toread = sz - cnt;
139 if (toread > sizeof(buf))
140 toread = sizeof(buf);
141 r = fread(buf, 1, toread, inf);
144 fprintf(stderr, "fread truncated. toread=%lld r=%lld\n",
145 (long long) toread, (long long) r);
148 w = write((*conp)->fd, buf, toread);
151 fprintf(stderr, "write truncated\n");
161 static void usage(void)
163 fprintf(stderr, "Usage: pazpar2_play infile host\n"
164 " -v level Set log level\n");
168 int main(int argc, char **argv)
173 const char *file = 0;
174 while ((ret = options("v:", argv, argc, &arg)) != -2)
179 yaz_log_init_level(yaz_log_mask_str(arg));
202 struct addrinfo hints, *res;
204 hints.ai_family = AF_UNSPEC;
205 hints.ai_socktype = SOCK_STREAM;
206 hints.ai_protocol = 0;
207 hints.ai_addrlen = 0;
208 hints.ai_addr = NULL;
209 hints.ai_canonname = NULL;
210 hints.ai_next = NULL;
212 cp = strchr(host, ':');
222 if (getaddrinfo(host, port, &hints, &res))
224 fprintf(stderr, "cannot resolve %s:%s\n", host, port);
228 inf = fopen(file, "rb");
231 fprintf(stderr, "cannot open %s\n", file);
246 * c-file-style: "Stroustrup"
247 * indent-tabs-mode: nil
249 * vim: shiftwidth=4 tabstop=8 expandtab