2 * Copyright (c) 2005 Andrey Simonenko
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
32 #include <sys/socket.h>
39 #include "t_%%TTYPE%%.h"
40 #include "t_generic.h"
41 #include "uc_common.h"
42 #include "uc_check_time.h"
44 #if defined(%%SCM_TTYPE%%)
46 check_scm_%%TTYPE%%(struct cmsghdr *cmsghdr)
48 const struct %%DTYPE%% *bt;
50 if (uc_check_cmsghdr(cmsghdr, %%SCM_TTYPE%%, sizeof(struct %%DTYPE%%)) < 0)
53 bt = (struct %%DTYPE%% *)CMSG_DATA(cmsghdr);
55 if (uc_check_%%TTYPE%%(bt) < 0)
58 uc_dbgmsg("%%DTYPE%%.%%MAJ_MEMB%% %"PRIdMAX", %%DTYPE%%.%%MIN_MEMB%% %"PRIuMAX,
59 (intmax_t)bt->%%MAJ_MEMB%%, (uintmax_t)bt->%%MIN_MEMB%%);
65 t_%%TTYPE%%_client(int fd)
73 if (uc_sync_recv() < 0)
78 cmsg_size = CMSG_SPACE(sizeof(struct %%DTYPE%%));
79 cmsg_data = malloc(cmsg_size);
80 if (cmsg_data == NULL) {
84 uc_msghdr_init_client(&msghdr, iov, cmsg_data, cmsg_size,
85 %%SCM_TTYPE%%, sizeof(struct %%DTYPE%%));
87 if (uc_socket_connect(fd) < 0)
90 if (uc_message_sendn(fd, &msghdr) < 0)
100 t_%%TTYPE%%_server(int fd1)
102 struct msghdr msghdr;
104 struct cmsghdr *cmsghdr;
110 if (uc_sync_send() < 0)
116 cmsg_size = CMSG_SPACE(sizeof(struct %%DTYPE%%));
117 cmsg_data = malloc(cmsg_size);
118 if (cmsg_data == NULL) {
123 if (uc_cfg.sock_type == SOCK_STREAM) {
124 fd2 = uc_socket_accept(fd1);
131 for (i = 1; i <= uc_cfg.ipc_msg.msg_num; ++i) {
132 uc_dbgmsg("message #%u", i);
134 uc_msghdr_init_server(&msghdr, iov, cmsg_data, cmsg_size);
135 if (uc_message_recv(fd2, &msghdr) < 0) {
140 if (uc_check_msghdr(&msghdr, sizeof(*cmsghdr)) < 0)
143 cmsghdr = CMSG_FIRSTHDR(&msghdr);
144 if (check_scm_%%TTYPE%%(cmsghdr) < 0)
147 if (i > uc_cfg.ipc_msg.msg_num)
151 if (uc_cfg.sock_type == SOCK_STREAM && fd2 >= 0)
152 if (uc_socket_close(fd2) < 0)
160 return (t_generic(t_%%TTYPE%%_client, t_%%TTYPE%%_server));
162 #endif /* %%SCM_TTYPE%% */