source: trunk/tools/neercs/old/mini-client.c @ 2183

Last change on this file since 2183 was 2183, checked in by sam, 7 years ago

build: fix the WTFPL site URL in all code comments.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/*
2 *  neercs        console-based window manager
3 *  Copyright (c) 2006-2011 Sam Hocevar <sam@hocevar.net>
4 *                2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                2008-2010 Pascal Terjan <pterjan@linuxfr.org>
6 *                All Rights Reserved
7 *
8 *  This program is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://www.wtfpl.net/ for more details.
13 */
14
15#if defined HAVE_CONFIG_H
16#   include "config.h"
17#endif
18
19#include <stdio.h> /* BUFSIZ */
20#include <string.h> /* strncmp() */
21
22#include <caca.h>
23
24#include "mini-neercs.h"
25#include "mini-socket.h"
26
27static caca_display_t *dp;
28static caca_canvas_t *cv;
29static nrx_socket_t *insock, *outsock;
30
31void client_init(void)
32{
33    int i, usec = 10000;
34
35    cv = caca_create_canvas(0, 0);
36    dp = caca_create_display(cv);
37    caca_set_display_title(dp, "Press Esc to quit");
38
39    insock = socket_open("/tmp/neercs.sock.client", 1);
40
41    for (i = 0; i < 10; i++)
42    {
43        outsock = socket_open("/tmp/neercs.sock", 0);
44        if (outsock)
45            break;
46        usleep(usec);
47        usec += usec;
48    }
49
50    socket_puts(outsock, "CONNECT /tmp/neercs.sock.client");
51}
52
53int client_step(void)
54{
55    caca_event_t ev;
56    int ret;
57
58    /* Handle client sockets */
59    ret = socket_select(insock, 1000);
60    if (ret > 0)
61    {
62        char buf[BUFSIZ];
63        ssize_t bytes = socket_read(insock, buf, BUFSIZ);
64        if (bytes <= 0)
65            return 1;
66
67        /* Parse message */
68        if (!strncmp(buf, "OK", strlen("OK")))
69        {
70            fprintf(stderr, "neercs: connection established\n");
71socket_puts(insock, "TEST insock");
72        }
73    }
74
75    /* Handle libcaca events */
76    if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 1000)
77        && caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE)
78        return 0;
79
80    return 1;
81}
82
83void client_fini(void)
84{
85    socket_puts(outsock, "QUIT /tmp/neercs.sock.client");
86
87    caca_free_display(dp);
88    caca_free_canvas(cv);
89    if (insock)
90        socket_close(insock);
91    if (outsock)
92        socket_close(outsock);
93}
94
Note: See TracBrowser for help on using the repository browser.