]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_tickle.c
5b5c7e7b7409c0f097fdba688b6d70f7d68f65ce
[netatalk.git] / libatalk / dsi / dsi_tickle.c
1 /*
2  * $Id: dsi_tickle.c,v 1.7 2009-10-22 04:59:50 didg Exp $
3  *
4  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5  * All rights reserved. See COPYRIGHT.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <stdio.h>
13 #include <sys/types.h>
14 #include <string.h>
15 #include <signal.h>
16
17 #include <atalk/dsi.h>
18 #include <netatalk/endian.h>
19
20 /* server generated tickles. as this is only called by the tickle handler,
21  * we don't need to block signals. well, actually, we might get it during
22  * a SIGHUP. */
23 int dsi_tickle(DSI *dsi)
24 {
25   char block[DSI_BLOCKSIZ];
26   sigset_t oldset;
27   u_int16_t id;
28   int ret;
29   
30   if (dsi->asleep || dsi->in_write)
31       return 1;
32
33   id = htons(dsi_serverID(dsi));
34
35   memset(block, 0, sizeof(block));
36   block[0] = DSIFL_REQUEST;
37   block[1] = DSIFUNC_TICKLE;
38   memcpy(block + 2, &id, sizeof(id));
39   /* code = len = reserved = 0 */
40
41   sigprocmask(SIG_BLOCK, &dsi->sigblockset, &oldset);
42   ret = dsi_stream_write(dsi, block, DSI_BLOCKSIZ, 0) == DSI_BLOCKSIZ;
43   sigprocmask(SIG_SETMASK, &oldset, NULL);
44   return ret;
45 }
46