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
25 #include <sys/types.h>
26 #include <sys/socket.h>
31 #include <yaz/options.h>
33 #include <yaz/xmalloc.h>
42 static int run(FILE *inf, struct addrinfo *res)
60 for (i = 0; c != '\n' && i < (sizeof(req)-2); i++)
66 r = sscanf(req, "%lld %lld %lld %d", &tv_sec1, &tv_usec1, &id, &sz);
69 fprintf(stderr, "bad line %s\n", req);
72 for (conp = &cons; *conp; conp = &(*conp)->next)
73 if ((*conp)->id == id)
79 for (rp = res; rp; rp = rp->ai_next)
81 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
87 fprintf(stderr, "socket: cannot create\n");
90 r = connect(fd, rp->ai_addr, rp->ai_addrlen);
93 fprintf(stderr, "socket: cannot connect\n");
97 *conp = xmalloc(sizeof(**conp));
104 struct con *c = *conp;
117 size_t toread = sz - cnt;
119 if (toread > sizeof(buf))
120 toread = sizeof(buf);
121 r = fread(buf, 1, toread, inf);
124 fprintf(stderr, "fread truncated. toread=%lld r=%lld\n",
125 (long long) toread, (long long) r);
128 w = write((*conp)->fd, buf, toread);
131 fprintf(stderr, "write truncated\n");
141 static void usage(void)
143 fprintf(stderr, "Usage: pazpar2_play infile host\n"
144 " -v level Set log level\n");
148 int main(int argc, char **argv)
153 const char *file = 0;
154 while ((ret = options("v:", argv, argc, &arg)) != -2)
159 yaz_log_init_level(yaz_log_mask_str(arg));
182 struct addrinfo hints, *res;
184 hints.ai_family = AF_UNSPEC;
185 hints.ai_socktype = SOCK_STREAM;
186 hints.ai_protocol = 0;
187 hints.ai_addrlen = 0;
188 hints.ai_addr = NULL;
189 hints.ai_canonname = NULL;
190 hints.ai_next = NULL;
192 cp = strchr(host, ':');
202 if (getaddrinfo(host, port, &hints, &res))
204 fprintf(stderr, "cannot resolve %s:%s\n", host, port);
208 inf = fopen(file, "rb");
211 fprintf(stderr, "cannot open %s\n", file);
226 * c-file-style: "Stroustrup"
227 * indent-tabs-mode: nil
229 * vim: shiftwidth=4 tabstop=8 expandtab