7 /* wakeup INET-domain server
9 /* #include <trigger.h>
11 /* int inet_trigger(service, buf, len, timeout)
17 /* inet_trigger() wakes up the named INET-domain server by making
18 /* a brief connection to it and by writing the contents of the
21 /* The connection is closed by a background thread. Some kernels
22 /* cannot handle client-side disconnect before the server has
23 /* received the message.
27 /* Name of the communication endpoint.
29 /* Address of data to be written.
31 /* Amount of data to be written.
33 /* Deadline in seconds. Specify a value <= 0 to disable
36 /* The result is zero in case of success, -1 in case of problems.
39 /* inet_connect(3), INET-domain client
43 /* The Secure Mailer license must be distributed with this software.
46 /* IBM T.J. Watson Research
48 /* Yorktown Heights, NY 10598, USA
54 #include <sys/socket.h>
58 /* Utility library. */
72 /* inet_trigger_event - disconnect from peer */
74 static void inet_trigger_event(int event
, char *context
)
76 struct inet_trigger
*ip
= (struct inet_trigger
*) context
;
77 static const char *myname
= "inet_trigger_event";
82 if (event
== EVENT_TIME
)
83 msg_warn("%s: read timeout for service %s", myname
, ip
->service
);
84 event_disable_readwrite(ip
->fd
);
85 event_cancel_timer(inet_trigger_event
, context
);
86 if (close(ip
->fd
) < 0)
87 msg_warn("%s: close %s: %m", myname
, ip
->service
);
93 /* inet_trigger - wakeup INET-domain server */
95 int inet_trigger(const char *service
, const char *buf
, ssize_t len
, int timeout
)
97 const char *myname
= "inet_trigger";
98 struct inet_trigger
*ip
;
102 msg_info("%s: service %s", myname
, service
);
107 if ((fd
= inet_connect(service
, BLOCKING
, timeout
)) < 0) {
109 msg_warn("%s: connect to %s: %m", myname
, service
);
112 close_on_exec(fd
, CLOSE_ON_EXEC
);
113 ip
= (struct inet_trigger
*) mymalloc(sizeof(*ip
));
115 ip
->service
= mystrdup(service
);
118 * Write the request...
120 if (write_buf(fd
, buf
, len
, timeout
) < 0
121 || write_buf(fd
, "", 1, timeout
) < 0)
123 msg_warn("%s: write to %s: %m", myname
, service
);
126 * Wakeup when the peer disconnects, or when we lose patience.
129 event_request_timer(inet_trigger_event
, (char *) ip
, timeout
+ 100);
130 event_enable_read(fd
, inet_trigger_event
, (char *) ip
);