]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_tickle.c
1) try a better workaround for deadlocks when both the server and the client are...
[netatalk.git] / libatalk / dsi / dsi_tickle.c
1 /*
2  * $Id: dsi_tickle.c,v 1.8 2009-10-25 06:13:11 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. */
22 int dsi_tickle(DSI *dsi)
23 {
24   char block[DSI_BLOCKSIZ];
25   u_int16_t id;
26   int ret;
27   
28   if (dsi->asleep || dsi->in_write)
29       return 1;
30
31   id = htons(dsi_serverID(dsi));
32
33   memset(block, 0, sizeof(block));
34   block[0] = DSIFL_REQUEST;
35   block[1] = DSIFUNC_TICKLE;
36   memcpy(block + 2, &id, sizeof(id));
37   /* code = len = reserved = 0 */
38
39   ret = dsi_stream_write(dsi, block, DSI_BLOCKSIZ, DSI_NOWAIT);
40   /* we don't really care if we can't send a tickle, it will fail
41    * elsewhere
42   */
43   ret = (ret == -1 || ret == DSI_BLOCKSIZ);
44   return ret;
45 }
46